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 sctp_paramhdr_t
*param_hdr
;
1059 struct sctp_chunk
*chunk
= arg
;
1060 struct sctp_chunk
*reply
;
1063 if (!sctp_vtag_verify(chunk
, asoc
))
1064 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1066 /* Make sure that the HEARTBEAT chunk has a valid length. */
1067 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_heartbeat_chunk_t
)))
1068 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1071 /* 8.3 The receiver of the HEARTBEAT should immediately
1072 * respond with a HEARTBEAT ACK that contains the Heartbeat
1073 * Information field copied from the received HEARTBEAT chunk.
1075 chunk
->subh
.hb_hdr
= (sctp_heartbeathdr_t
*) chunk
->skb
->data
;
1076 param_hdr
= (sctp_paramhdr_t
*) chunk
->subh
.hb_hdr
;
1077 paylen
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(sctp_chunkhdr_t
);
1079 if (ntohs(param_hdr
->length
) > paylen
)
1080 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
1081 param_hdr
, commands
);
1083 if (!pskb_pull(chunk
->skb
, paylen
))
1086 reply
= sctp_make_heartbeat_ack(asoc
, chunk
, param_hdr
, paylen
);
1090 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
1091 return SCTP_DISPOSITION_CONSUME
;
1094 return SCTP_DISPOSITION_NOMEM
;
1098 * Process the returning HEARTBEAT ACK.
1100 * Section: 8.3 Path Heartbeat
1101 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
1102 * should clear the error counter of the destination transport
1103 * address to which the HEARTBEAT was sent, and mark the destination
1104 * transport address as active if it is not so marked. The endpoint may
1105 * optionally report to the upper layer when an inactive destination
1106 * address is marked as active due to the reception of the latest
1107 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
1108 * clear the association overall error count as well (as defined
1111 * The receiver of the HEARTBEAT ACK should also perform an RTT
1112 * measurement for that destination transport address using the time
1113 * value carried in the HEARTBEAT ACK chunk.
1115 * Verification Tag: 8.5 Verification Tag [Normal verification]
1118 * (endpoint, asoc, chunk)
1121 * (asoc, reply_msg, msg_up, timers, counters)
1123 * The return value is the disposition of the chunk.
1125 sctp_disposition_t
sctp_sf_backbeat_8_3(struct net
*net
,
1126 const struct sctp_endpoint
*ep
,
1127 const struct sctp_association
*asoc
,
1128 const sctp_subtype_t type
,
1130 sctp_cmd_seq_t
*commands
)
1132 struct sctp_chunk
*chunk
= arg
;
1133 union sctp_addr from_addr
;
1134 struct sctp_transport
*link
;
1135 sctp_sender_hb_info_t
*hbinfo
;
1136 unsigned long max_interval
;
1138 if (!sctp_vtag_verify(chunk
, asoc
))
1139 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1141 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1142 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
) +
1143 sizeof(sctp_sender_hb_info_t
)))
1144 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1147 hbinfo
= (sctp_sender_hb_info_t
*) chunk
->skb
->data
;
1148 /* Make sure that the length of the parameter is what we expect */
1149 if (ntohs(hbinfo
->param_hdr
.length
) !=
1150 sizeof(sctp_sender_hb_info_t
)) {
1151 return SCTP_DISPOSITION_DISCARD
;
1154 from_addr
= hbinfo
->daddr
;
1155 link
= sctp_assoc_lookup_paddr(asoc
, &from_addr
);
1157 /* This should never happen, but lets log it if so. */
1158 if (unlikely(!link
)) {
1159 if (from_addr
.sa
.sa_family
== AF_INET6
) {
1160 net_warn_ratelimited("%s association %p could not find address %pI6\n",
1163 &from_addr
.v6
.sin6_addr
);
1165 net_warn_ratelimited("%s association %p could not find address %pI4\n",
1168 &from_addr
.v4
.sin_addr
.s_addr
);
1170 return SCTP_DISPOSITION_DISCARD
;
1173 /* Validate the 64-bit random nonce. */
1174 if (hbinfo
->hb_nonce
!= link
->hb_nonce
)
1175 return SCTP_DISPOSITION_DISCARD
;
1177 max_interval
= link
->hbinterval
+ link
->rto
;
1179 /* Check if the timestamp looks valid. */
1180 if (time_after(hbinfo
->sent_at
, jiffies
) ||
1181 time_after(jiffies
, hbinfo
->sent_at
+ max_interval
)) {
1182 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp "
1183 "received for transport: %p\n",
1185 return SCTP_DISPOSITION_DISCARD
;
1188 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1189 * the HEARTBEAT should clear the error counter of the
1190 * destination transport address to which the HEARTBEAT was
1191 * sent and mark the destination transport address as active if
1192 * it is not so marked.
1194 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_ON
, SCTP_TRANSPORT(link
));
1196 return SCTP_DISPOSITION_CONSUME
;
1199 /* Helper function to send out an abort for the restart
1202 static int sctp_sf_send_restart_abort(struct net
*net
, union sctp_addr
*ssa
,
1203 struct sctp_chunk
*init
,
1204 sctp_cmd_seq_t
*commands
)
1207 struct sctp_packet
*pkt
;
1208 union sctp_addr_param
*addrparm
;
1209 struct sctp_errhdr
*errhdr
;
1210 struct sctp_endpoint
*ep
;
1211 char buffer
[sizeof(struct sctp_errhdr
)+sizeof(union sctp_addr_param
)];
1212 struct sctp_af
*af
= sctp_get_af_specific(ssa
->v4
.sin_family
);
1214 /* Build the error on the stack. We are way to malloc crazy
1215 * throughout the code today.
1217 errhdr
= (struct sctp_errhdr
*)buffer
;
1218 addrparm
= (union sctp_addr_param
*)errhdr
->variable
;
1220 /* Copy into a parm format. */
1221 len
= af
->to_addr_param(ssa
, addrparm
);
1222 len
+= sizeof(sctp_errhdr_t
);
1224 errhdr
->cause
= SCTP_ERROR_RESTART
;
1225 errhdr
->length
= htons(len
);
1227 /* Assign to the control socket. */
1228 ep
= sctp_sk(net
->sctp
.ctl_sock
)->ep
;
1230 /* Association is NULL since this may be a restart attack and we
1231 * want to send back the attacker's vtag.
1233 pkt
= sctp_abort_pkt_new(net
, ep
, NULL
, init
, errhdr
, len
);
1237 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
, SCTP_PACKET(pkt
));
1239 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
1241 /* Discard the rest of the inbound packet. */
1242 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
1245 /* Even if there is no memory, treat as a failure so
1246 * the packet will get dropped.
1251 static bool list_has_sctp_addr(const struct list_head
*list
,
1252 union sctp_addr
*ipaddr
)
1254 struct sctp_transport
*addr
;
1256 list_for_each_entry(addr
, list
, transports
) {
1257 if (sctp_cmp_addr_exact(ipaddr
, &addr
->ipaddr
))
1263 /* A restart is occurring, check to make sure no new addresses
1264 * are being added as we may be under a takeover attack.
1266 static int sctp_sf_check_restart_addrs(const struct sctp_association
*new_asoc
,
1267 const struct sctp_association
*asoc
,
1268 struct sctp_chunk
*init
,
1269 sctp_cmd_seq_t
*commands
)
1271 struct net
*net
= sock_net(new_asoc
->base
.sk
);
1272 struct sctp_transport
*new_addr
;
1275 /* Implementor's Guide - Section 5.2.2
1277 * Before responding the endpoint MUST check to see if the
1278 * unexpected INIT adds new addresses to the association. If new
1279 * addresses are added to the association, the endpoint MUST respond
1283 /* Search through all current addresses and make sure
1284 * we aren't adding any new ones.
1286 list_for_each_entry(new_addr
, &new_asoc
->peer
.transport_addr_list
,
1288 if (!list_has_sctp_addr(&asoc
->peer
.transport_addr_list
,
1289 &new_addr
->ipaddr
)) {
1290 sctp_sf_send_restart_abort(net
, &new_addr
->ipaddr
, init
,
1297 /* Return success if all addresses were found. */
1301 /* Populate the verification/tie tags based on overlapping INIT
1304 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1306 static void sctp_tietags_populate(struct sctp_association
*new_asoc
,
1307 const struct sctp_association
*asoc
)
1309 switch (asoc
->state
) {
1311 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1313 case SCTP_STATE_COOKIE_WAIT
:
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
= 0;
1319 case SCTP_STATE_COOKIE_ECHOED
:
1320 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1321 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1322 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1325 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1326 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1329 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1330 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1334 /* Other parameters for the endpoint SHOULD be copied from the
1335 * existing parameters of the association (e.g. number of
1336 * outbound streams) into the INIT ACK and cookie.
1338 new_asoc
->rwnd
= asoc
->rwnd
;
1339 new_asoc
->c
.sinit_num_ostreams
= asoc
->c
.sinit_num_ostreams
;
1340 new_asoc
->c
.sinit_max_instreams
= asoc
->c
.sinit_max_instreams
;
1341 new_asoc
->c
.initial_tsn
= asoc
->c
.initial_tsn
;
1345 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1348 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1350 * Returns value representing action to be taken. These action values
1351 * correspond to Action/Description values in RFC 2960, Table 2.
1353 static char sctp_tietags_compare(struct sctp_association
*new_asoc
,
1354 const struct sctp_association
*asoc
)
1356 /* In this case, the peer may have restarted. */
1357 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1358 (asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) &&
1359 (asoc
->c
.my_vtag
== new_asoc
->c
.my_ttag
) &&
1360 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_ttag
))
1363 /* Collision case B. */
1364 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1365 ((asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) ||
1366 (0 == asoc
->c
.peer_vtag
))) {
1370 /* Collision case D. */
1371 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1372 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
))
1375 /* Collision case C. */
1376 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1377 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
) &&
1378 (0 == new_asoc
->c
.my_ttag
) &&
1379 (0 == new_asoc
->c
.peer_ttag
))
1382 /* No match to any of the special cases; discard this packet. */
1386 /* Common helper routine for both duplicate and simulataneous INIT
1389 static sctp_disposition_t
sctp_sf_do_unexpected_init(
1391 const struct sctp_endpoint
*ep
,
1392 const struct sctp_association
*asoc
,
1393 const sctp_subtype_t type
,
1394 void *arg
, sctp_cmd_seq_t
*commands
)
1396 sctp_disposition_t retval
;
1397 struct sctp_chunk
*chunk
= arg
;
1398 struct sctp_chunk
*repl
;
1399 struct sctp_association
*new_asoc
;
1400 struct sctp_chunk
*err_chunk
;
1401 struct sctp_packet
*packet
;
1402 sctp_unrecognized_param_t
*unk_param
;
1406 * An endpoint MUST NOT bundle INIT, INIT ACK or
1407 * SHUTDOWN COMPLETE with any other chunks.
1410 * Furthermore, we require that the receiver of an INIT chunk MUST
1411 * enforce these rules by silently discarding an arriving packet
1412 * with an INIT chunk that is bundled with other chunks.
1414 if (!chunk
->singleton
)
1415 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1417 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1420 if (chunk
->sctp_hdr
->vtag
!= 0)
1421 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
1423 /* Make sure that the INIT chunk has a valid length.
1424 * In this case, we generate a protocol violation since we have
1425 * an association established.
1427 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_init_chunk_t
)))
1428 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1430 /* Grab the INIT header. */
1431 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
1433 /* Tag the variable length parameters. */
1434 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
1436 /* Verify the INIT chunk before processing it. */
1438 if (!sctp_verify_init(net
, asoc
, chunk
->chunk_hdr
->type
,
1439 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
1441 /* This chunk contains fatal error. It is to be discarded.
1442 * Send an ABORT, with causes if there is any.
1445 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
1446 (__u8
*)(err_chunk
->chunk_hdr
) +
1447 sizeof(sctp_chunkhdr_t
),
1448 ntohs(err_chunk
->chunk_hdr
->length
) -
1449 sizeof(sctp_chunkhdr_t
));
1452 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
1453 SCTP_PACKET(packet
));
1454 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
1455 retval
= SCTP_DISPOSITION_CONSUME
;
1457 retval
= SCTP_DISPOSITION_NOMEM
;
1461 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
,
1467 * Other parameters for the endpoint SHOULD be copied from the
1468 * existing parameters of the association (e.g. number of
1469 * outbound streams) into the INIT ACK and cookie.
1470 * FIXME: We are copying parameters from the endpoint not the
1473 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
1477 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
,
1478 sctp_scope(sctp_source(chunk
)), GFP_ATOMIC
) < 0)
1481 /* In the outbound INIT ACK the endpoint MUST copy its current
1482 * Verification Tag and Peers Verification tag into a reserved
1483 * place (local tie-tag and per tie-tag) within the state cookie.
1485 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
),
1486 (sctp_init_chunk_t
*)chunk
->chunk_hdr
,
1490 /* Make sure no new addresses are being added during the
1491 * restart. Do not do this check for COOKIE-WAIT state,
1492 * since there are no peer addresses to check against.
1493 * Upon return an ABORT will have been sent if needed.
1495 if (!sctp_state(asoc
, COOKIE_WAIT
)) {
1496 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
,
1498 retval
= SCTP_DISPOSITION_CONSUME
;
1503 sctp_tietags_populate(new_asoc
, asoc
);
1505 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1507 /* If there are errors need to be reported for unknown parameters,
1508 * make sure to reserve enough room in the INIT ACK for them.
1512 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
1513 sizeof(sctp_chunkhdr_t
);
1516 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
1520 /* If there are errors need to be reported for unknown parameters,
1521 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1525 /* Get the "Unrecognized parameter" parameter(s) out of the
1526 * ERROR chunk generated by sctp_verify_init(). Since the
1527 * error cause code for "unknown parameter" and the
1528 * "Unrecognized parameter" type is the same, we can
1529 * construct the parameters in INIT ACK by copying the
1530 * ERROR causes over.
1532 unk_param
= (sctp_unrecognized_param_t
*)
1533 ((__u8
*)(err_chunk
->chunk_hdr
) +
1534 sizeof(sctp_chunkhdr_t
));
1535 /* Replace the cause code with the "Unrecognized parameter"
1538 sctp_addto_chunk(repl
, len
, unk_param
);
1541 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
1542 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1545 * Note: After sending out INIT ACK with the State Cookie parameter,
1546 * "Z" MUST NOT allocate any resources for this new association.
1547 * Otherwise, "Z" will be vulnerable to resource attacks.
1549 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
1550 retval
= SCTP_DISPOSITION_CONSUME
;
1555 retval
= SCTP_DISPOSITION_NOMEM
;
1558 sctp_association_free(new_asoc
);
1561 sctp_chunk_free(err_chunk
);
1566 * Handle simultaneous INIT.
1567 * This means we started an INIT and then we got an INIT request from
1570 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1571 * This usually indicates an initialization collision, i.e., each
1572 * endpoint is attempting, at about the same time, to establish an
1573 * association with the other endpoint.
1575 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1576 * endpoint MUST respond with an INIT ACK using the same parameters it
1577 * sent in its original INIT chunk (including its Verification Tag,
1578 * unchanged). These original parameters are combined with those from the
1579 * newly received INIT chunk. The endpoint shall also generate a State
1580 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1581 * INIT to calculate the State Cookie.
1583 * After that, the endpoint MUST NOT change its state, the T1-init
1584 * timer shall be left running and the corresponding TCB MUST NOT be
1585 * destroyed. The normal procedures for handling State Cookies when
1586 * a TCB exists will resolve the duplicate INITs to a single association.
1588 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1589 * its Tie-Tags with the Tag information of itself and its peer (see
1590 * section 5.2.2 for a description of the Tie-Tags).
1592 * Verification Tag: Not explicit, but an INIT can not have a valid
1593 * verification tag, so we skip the check.
1596 * (endpoint, asoc, chunk)
1599 * (asoc, reply_msg, msg_up, timers, counters)
1601 * The return value is the disposition of the chunk.
1603 sctp_disposition_t
sctp_sf_do_5_2_1_siminit(struct net
*net
,
1604 const struct sctp_endpoint
*ep
,
1605 const struct sctp_association
*asoc
,
1606 const sctp_subtype_t type
,
1608 sctp_cmd_seq_t
*commands
)
1610 /* Call helper to do the real work for both simulataneous and
1611 * duplicate INIT chunk handling.
1613 return sctp_sf_do_unexpected_init(net
, ep
, asoc
, type
, arg
, commands
);
1617 * Handle duplicated INIT messages. These are usually delayed
1620 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1621 * COOKIE-ECHOED and COOKIE-WAIT
1623 * Unless otherwise stated, upon reception of an unexpected INIT for
1624 * this association, the endpoint shall generate an INIT ACK with a
1625 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1626 * current Verification Tag and peer's Verification Tag into a reserved
1627 * place within the state cookie. We shall refer to these locations as
1628 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1629 * containing this INIT ACK MUST carry a Verification Tag value equal to
1630 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1631 * MUST contain a new Initiation Tag (randomly generated see Section
1632 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1633 * existing parameters of the association (e.g. number of outbound
1634 * streams) into the INIT ACK and cookie.
1636 * After sending out the INIT ACK, the endpoint shall take no further
1637 * actions, i.e., the existing association, including its current state,
1638 * and the corresponding TCB MUST NOT be changed.
1640 * Note: Only when a TCB exists and the association is not in a COOKIE-
1641 * WAIT state are the Tie-Tags populated. For a normal association INIT
1642 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1643 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1644 * State Cookie are populated as specified in section 5.2.1.
1646 * Verification Tag: Not specified, but an INIT has no way of knowing
1647 * what the verification tag could be, so we ignore it.
1650 * (endpoint, asoc, chunk)
1653 * (asoc, reply_msg, msg_up, timers, counters)
1655 * The return value is the disposition of the chunk.
1657 sctp_disposition_t
sctp_sf_do_5_2_2_dupinit(struct net
*net
,
1658 const struct sctp_endpoint
*ep
,
1659 const struct sctp_association
*asoc
,
1660 const sctp_subtype_t type
,
1662 sctp_cmd_seq_t
*commands
)
1664 /* Call helper to do the real work for both simulataneous and
1665 * duplicate INIT chunk handling.
1667 return sctp_sf_do_unexpected_init(net
, ep
, asoc
, type
, arg
, commands
);
1672 * Unexpected INIT-ACK handler.
1675 * If an INIT ACK received by an endpoint in any state other than the
1676 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1677 * An unexpected INIT ACK usually indicates the processing of an old or
1678 * duplicated INIT chunk.
1680 sctp_disposition_t
sctp_sf_do_5_2_3_initack(struct net
*net
,
1681 const struct sctp_endpoint
*ep
,
1682 const struct sctp_association
*asoc
,
1683 const sctp_subtype_t type
,
1684 void *arg
, sctp_cmd_seq_t
*commands
)
1686 /* Per the above section, we'll discard the chunk if we have an
1687 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1689 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
)
1690 return sctp_sf_ootb(net
, ep
, asoc
, type
, arg
, commands
);
1692 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
1695 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1698 * A) In this case, the peer may have restarted.
1700 static sctp_disposition_t
sctp_sf_do_dupcook_a(struct net
*net
,
1701 const struct sctp_endpoint
*ep
,
1702 const struct sctp_association
*asoc
,
1703 struct sctp_chunk
*chunk
,
1704 sctp_cmd_seq_t
*commands
,
1705 struct sctp_association
*new_asoc
)
1707 sctp_init_chunk_t
*peer_init
;
1708 struct sctp_ulpevent
*ev
;
1709 struct sctp_chunk
*repl
;
1710 struct sctp_chunk
*err
;
1711 sctp_disposition_t disposition
;
1713 /* new_asoc is a brand-new association, so these are not yet
1714 * side effects--it is safe to run them here.
1716 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1718 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
), peer_init
,
1722 /* Make sure no new addresses are being added during the
1723 * restart. Though this is a pretty complicated attack
1724 * since you'd have to get inside the cookie.
1726 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
, commands
)) {
1727 return SCTP_DISPOSITION_CONSUME
;
1730 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1731 * the peer has restarted (Action A), it MUST NOT setup a new
1732 * association but instead resend the SHUTDOWN ACK and send an ERROR
1733 * chunk with a "Cookie Received while Shutting Down" error cause to
1736 if (sctp_state(asoc
, SHUTDOWN_ACK_SENT
)) {
1737 disposition
= sctp_sf_do_9_2_reshutack(net
, ep
, asoc
,
1738 SCTP_ST_CHUNK(chunk
->chunk_hdr
->type
),
1740 if (SCTP_DISPOSITION_NOMEM
== disposition
)
1743 err
= sctp_make_op_error(asoc
, chunk
,
1744 SCTP_ERROR_COOKIE_IN_SHUTDOWN
,
1747 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1750 return SCTP_DISPOSITION_CONSUME
;
1753 /* For now, stop pending T3-rtx and SACK timers, fail any unsent/unacked
1754 * data. Consider the optional choice of resending of this data.
1756 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
1757 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1758 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK
));
1759 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_OUTQUEUE
, SCTP_NULL());
1761 /* Stop pending T4-rto timer, teardown ASCONF queue, ASCONF-ACK queue
1762 * and ASCONF-ACK cache.
1764 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1765 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
1766 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_ASCONF_QUEUE
, SCTP_NULL());
1768 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1772 /* Report association restart to upper layer. */
1773 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_RESTART
, 0,
1774 new_asoc
->c
.sinit_num_ostreams
,
1775 new_asoc
->c
.sinit_max_instreams
,
1780 /* Update the content of current association. */
1781 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1782 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1783 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
1784 return SCTP_DISPOSITION_CONSUME
;
1787 sctp_chunk_free(repl
);
1789 return SCTP_DISPOSITION_NOMEM
;
1792 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1795 * B) In this case, both sides may be attempting to start an association
1796 * at about the same time but the peer endpoint started its INIT
1797 * after responding to the local endpoint's INIT
1799 /* This case represents an initialization collision. */
1800 static sctp_disposition_t
sctp_sf_do_dupcook_b(struct net
*net
,
1801 const struct sctp_endpoint
*ep
,
1802 const struct sctp_association
*asoc
,
1803 struct sctp_chunk
*chunk
,
1804 sctp_cmd_seq_t
*commands
,
1805 struct sctp_association
*new_asoc
)
1807 sctp_init_chunk_t
*peer_init
;
1808 struct sctp_chunk
*repl
;
1810 /* new_asoc is a brand-new association, so these are not yet
1811 * side effects--it is safe to run them here.
1813 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1814 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
), peer_init
,
1818 /* Update the content of current association. */
1819 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1820 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1821 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1822 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
1823 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
1825 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1829 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1831 /* RFC 2960 5.1 Normal Establishment of an Association
1833 * D) IMPLEMENTATION NOTE: An implementation may choose to
1834 * send the Communication Up notification to the SCTP user
1835 * upon reception of a valid COOKIE ECHO chunk.
1837 * Sadly, this needs to be implemented as a side-effect, because
1838 * we are not guaranteed to have set the association id of the real
1839 * association and so these notifications need to be delayed until
1840 * the association id is allocated.
1843 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_CHANGE
, SCTP_U8(SCTP_COMM_UP
));
1845 /* Sockets API Draft Section 5.3.1.6
1846 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1847 * delivers this notification to inform the application that of the
1848 * peers requested adaptation layer.
1850 * This also needs to be done as a side effect for the same reason as
1853 if (asoc
->peer
.adaptation_ind
)
1854 sctp_add_cmd_sf(commands
, SCTP_CMD_ADAPTATION_IND
, SCTP_NULL());
1856 return SCTP_DISPOSITION_CONSUME
;
1859 return SCTP_DISPOSITION_NOMEM
;
1862 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1865 * C) In this case, the local endpoint's cookie has arrived late.
1866 * Before it arrived, the local endpoint sent an INIT and received an
1867 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1868 * but a new tag of its own.
1870 /* This case represents an initialization collision. */
1871 static sctp_disposition_t
sctp_sf_do_dupcook_c(struct net
*net
,
1872 const struct sctp_endpoint
*ep
,
1873 const struct sctp_association
*asoc
,
1874 struct sctp_chunk
*chunk
,
1875 sctp_cmd_seq_t
*commands
,
1876 struct sctp_association
*new_asoc
)
1878 /* The cookie should be silently discarded.
1879 * The endpoint SHOULD NOT change states and should leave
1880 * any timers running.
1882 return SCTP_DISPOSITION_DISCARD
;
1885 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1889 * D) When both local and remote tags match the endpoint should always
1890 * enter the ESTABLISHED state, if it has not already done so.
1892 /* This case represents an initialization collision. */
1893 static sctp_disposition_t
sctp_sf_do_dupcook_d(struct net
*net
,
1894 const struct sctp_endpoint
*ep
,
1895 const struct sctp_association
*asoc
,
1896 struct sctp_chunk
*chunk
,
1897 sctp_cmd_seq_t
*commands
,
1898 struct sctp_association
*new_asoc
)
1900 struct sctp_ulpevent
*ev
= NULL
, *ai_ev
= NULL
;
1901 struct sctp_chunk
*repl
;
1903 /* Clarification from Implementor's Guide:
1904 * D) When both local and remote tags match the endpoint should
1905 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1906 * It should stop any cookie timer that may be running and send
1910 /* Don't accidentally move back into established state. */
1911 if (asoc
->state
< SCTP_STATE_ESTABLISHED
) {
1912 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1913 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
1914 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1915 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1916 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
1917 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
,
1920 /* RFC 2960 5.1 Normal Establishment of an Association
1922 * D) IMPLEMENTATION NOTE: An implementation may choose
1923 * to send the Communication Up notification to the
1924 * SCTP user upon reception of a valid COOKIE
1927 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0,
1929 asoc
->c
.sinit_num_ostreams
,
1930 asoc
->c
.sinit_max_instreams
,
1935 /* Sockets API Draft Section 5.3.1.6
1936 * When a peer sends a Adaptation Layer Indication parameter,
1937 * SCTP delivers this notification to inform the application
1938 * that of the peers requested adaptation layer.
1940 if (asoc
->peer
.adaptation_ind
) {
1941 ai_ev
= sctp_ulpevent_make_adaptation_indication(asoc
,
1949 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1953 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1956 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1959 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1960 SCTP_ULPEVENT(ai_ev
));
1962 return SCTP_DISPOSITION_CONSUME
;
1966 sctp_ulpevent_free(ai_ev
);
1968 sctp_ulpevent_free(ev
);
1969 return SCTP_DISPOSITION_NOMEM
;
1973 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1974 * chunk was retransmitted and then delayed in the network.
1976 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1978 * Verification Tag: None. Do cookie validation.
1981 * (endpoint, asoc, chunk)
1984 * (asoc, reply_msg, msg_up, timers, counters)
1986 * The return value is the disposition of the chunk.
1988 sctp_disposition_t
sctp_sf_do_5_2_4_dupcook(struct net
*net
,
1989 const struct sctp_endpoint
*ep
,
1990 const struct sctp_association
*asoc
,
1991 const sctp_subtype_t type
,
1993 sctp_cmd_seq_t
*commands
)
1995 sctp_disposition_t retval
;
1996 struct sctp_chunk
*chunk
= arg
;
1997 struct sctp_association
*new_asoc
;
2000 struct sctp_chunk
*err_chk_p
;
2002 /* Make sure that the chunk has a valid length from the protocol
2003 * perspective. In this case check to make sure we have at least
2004 * enough for the chunk header. Cookie length verification is
2007 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
2008 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2011 /* "Decode" the chunk. We have no optional parameters so we
2012 * are in good shape.
2014 chunk
->subh
.cookie_hdr
= (struct sctp_signed_cookie
*)chunk
->skb
->data
;
2015 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
2016 sizeof(sctp_chunkhdr_t
)))
2019 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
2020 * of a duplicate COOKIE ECHO match the Verification Tags of the
2021 * current association, consider the State Cookie valid even if
2022 * the lifespan is exceeded.
2024 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
2028 * If the re-build failed, what is the proper error path
2031 * [We should abort the association. --piggy]
2034 /* FIXME: Several errors are possible. A bad cookie should
2035 * be silently discarded, but think about logging it too.
2038 case -SCTP_IERROR_NOMEM
:
2041 case -SCTP_IERROR_STALE_COOKIE
:
2042 sctp_send_stale_cookie_err(net
, ep
, asoc
, chunk
, commands
,
2044 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2045 case -SCTP_IERROR_BAD_SIG
:
2047 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2051 /* Compare the tie_tag in cookie with the verification tag of
2052 * current association.
2054 action
= sctp_tietags_compare(new_asoc
, asoc
);
2057 case 'A': /* Association restart. */
2058 retval
= sctp_sf_do_dupcook_a(net
, ep
, asoc
, chunk
, commands
,
2062 case 'B': /* Collision case B. */
2063 retval
= sctp_sf_do_dupcook_b(net
, ep
, asoc
, chunk
, commands
,
2067 case 'C': /* Collision case C. */
2068 retval
= sctp_sf_do_dupcook_c(net
, ep
, asoc
, chunk
, commands
,
2072 case 'D': /* Collision case D. */
2073 retval
= sctp_sf_do_dupcook_d(net
, ep
, asoc
, chunk
, commands
,
2077 default: /* Discard packet for all others. */
2078 retval
= sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2082 /* Delete the tempory new association. */
2083 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
2084 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
2086 /* Restore association pointer to provide SCTP command interpeter
2087 * with a valid context in case it needs to manipulate
2089 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_ASOC
,
2090 SCTP_ASOC((struct sctp_association
*)asoc
));
2095 return SCTP_DISPOSITION_NOMEM
;
2099 * Process an ABORT. (SHUTDOWN-PENDING state)
2101 * See sctp_sf_do_9_1_abort().
2103 sctp_disposition_t
sctp_sf_shutdown_pending_abort(
2105 const struct sctp_endpoint
*ep
,
2106 const struct sctp_association
*asoc
,
2107 const sctp_subtype_t type
,
2109 sctp_cmd_seq_t
*commands
)
2111 struct sctp_chunk
*chunk
= arg
;
2113 if (!sctp_vtag_verify_either(chunk
, asoc
))
2114 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2116 /* Make sure that the ABORT chunk has a valid length.
2117 * Since this is an ABORT chunk, we have to discard it
2118 * because of the following text:
2119 * RFC 2960, Section 3.3.7
2120 * If an endpoint receives an ABORT with a format error or for an
2121 * association that doesn't exist, it MUST silently discard it.
2122 * Because the length is "invalid", we can't really discard just
2123 * as we do not know its true length. So, to be safe, discard the
2126 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2127 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2129 /* ADD-IP: Special case for ABORT chunks
2130 * F4) One special consideration is that ABORT Chunks arriving
2131 * destined to the IP address being deleted MUST be
2132 * ignored (see Section 5.3.1 for further details).
2134 if (SCTP_ADDR_DEL
==
2135 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2136 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2138 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2142 * Process an ABORT. (SHUTDOWN-SENT state)
2144 * See sctp_sf_do_9_1_abort().
2146 sctp_disposition_t
sctp_sf_shutdown_sent_abort(struct net
*net
,
2147 const struct sctp_endpoint
*ep
,
2148 const struct sctp_association
*asoc
,
2149 const sctp_subtype_t type
,
2151 sctp_cmd_seq_t
*commands
)
2153 struct sctp_chunk
*chunk
= arg
;
2155 if (!sctp_vtag_verify_either(chunk
, asoc
))
2156 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2158 /* Make sure that the ABORT chunk has a valid length.
2159 * Since this is an ABORT chunk, we have to discard it
2160 * because of the following text:
2161 * RFC 2960, Section 3.3.7
2162 * If an endpoint receives an ABORT with a format error or for an
2163 * association that doesn't exist, it MUST silently discard it.
2164 * Because the length is "invalid", we can't really discard just
2165 * as we do not know its true length. So, to be safe, discard the
2168 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2169 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2171 /* ADD-IP: Special case for ABORT chunks
2172 * F4) One special consideration is that ABORT Chunks arriving
2173 * destined to the IP address being deleted MUST be
2174 * ignored (see Section 5.3.1 for further details).
2176 if (SCTP_ADDR_DEL
==
2177 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2178 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2180 /* Stop the T2-shutdown timer. */
2181 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2182 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2184 /* Stop the T5-shutdown guard timer. */
2185 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2186 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
2188 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2192 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2194 * See sctp_sf_do_9_1_abort().
2196 sctp_disposition_t
sctp_sf_shutdown_ack_sent_abort(
2198 const struct sctp_endpoint
*ep
,
2199 const struct sctp_association
*asoc
,
2200 const sctp_subtype_t type
,
2202 sctp_cmd_seq_t
*commands
)
2204 /* The same T2 timer, so we should be able to use
2205 * common function with the SHUTDOWN-SENT state.
2207 return sctp_sf_shutdown_sent_abort(net
, ep
, asoc
, type
, arg
, commands
);
2211 * Handle an Error received in COOKIE_ECHOED state.
2213 * Only handle the error type of stale COOKIE Error, the other errors will
2217 * (endpoint, asoc, chunk)
2220 * (asoc, reply_msg, msg_up, timers, counters)
2222 * The return value is the disposition of the chunk.
2224 sctp_disposition_t
sctp_sf_cookie_echoed_err(struct net
*net
,
2225 const struct sctp_endpoint
*ep
,
2226 const struct sctp_association
*asoc
,
2227 const sctp_subtype_t type
,
2229 sctp_cmd_seq_t
*commands
)
2231 struct sctp_chunk
*chunk
= arg
;
2234 if (!sctp_vtag_verify(chunk
, asoc
))
2235 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2237 /* Make sure that the ERROR chunk has a valid length.
2238 * The parameter walking depends on this as well.
2240 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
2241 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2244 /* Process the error here */
2245 /* FUTURE FIXME: When PR-SCTP related and other optional
2246 * parms are emitted, this will have to change to handle multiple
2249 sctp_walk_errors(err
, chunk
->chunk_hdr
) {
2250 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
)
2251 return sctp_sf_do_5_2_6_stale(net
, ep
, asoc
, type
,
2255 /* It is possible to have malformed error causes, and that
2256 * will cause us to end the walk early. However, since
2257 * we are discarding the packet, there should be no adverse
2260 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2264 * Handle a Stale COOKIE Error
2266 * Section: 5.2.6 Handle Stale COOKIE Error
2267 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2268 * one of the following three alternatives.
2270 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2271 * Preservative parameter requesting an extension to the lifetime of
2272 * the State Cookie. When calculating the time extension, an
2273 * implementation SHOULD use the RTT information measured based on the
2274 * previous COOKIE ECHO / ERROR exchange, and should add no more
2275 * than 1 second beyond the measured RTT, due to long State Cookie
2276 * lifetimes making the endpoint more subject to a replay attack.
2278 * Verification Tag: Not explicit, but safe to ignore.
2281 * (endpoint, asoc, chunk)
2284 * (asoc, reply_msg, msg_up, timers, counters)
2286 * The return value is the disposition of the chunk.
2288 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(struct net
*net
,
2289 const struct sctp_endpoint
*ep
,
2290 const struct sctp_association
*asoc
,
2291 const sctp_subtype_t type
,
2293 sctp_cmd_seq_t
*commands
)
2295 struct sctp_chunk
*chunk
= arg
;
2297 sctp_cookie_preserve_param_t bht
;
2299 struct sctp_chunk
*reply
;
2300 struct sctp_bind_addr
*bp
;
2301 int attempts
= asoc
->init_err_counter
+ 1;
2303 if (attempts
> asoc
->max_init_attempts
) {
2304 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
2305 SCTP_ERROR(ETIMEDOUT
));
2306 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2307 SCTP_PERR(SCTP_ERROR_STALE_COOKIE
));
2308 return SCTP_DISPOSITION_DELETE_TCB
;
2311 err
= (sctp_errhdr_t
*)(chunk
->skb
->data
);
2313 /* When calculating the time extension, an implementation
2314 * SHOULD use the RTT information measured based on the
2315 * previous COOKIE ECHO / ERROR exchange, and should add no
2316 * more than 1 second beyond the measured RTT, due to long
2317 * State Cookie lifetimes making the endpoint more subject to
2319 * Measure of Staleness's unit is usec. (1/1000000 sec)
2320 * Suggested Cookie Life-span Increment's unit is msec.
2322 * In general, if you use the suggested cookie life, the value
2323 * found in the field of measure of staleness should be doubled
2324 * to give ample time to retransmit the new cookie and thus
2325 * yield a higher probability of success on the reattempt.
2327 stale
= ntohl(*(__be32
*)((u8
*)err
+ sizeof(sctp_errhdr_t
)));
2328 stale
= (stale
* 2) / 1000;
2330 bht
.param_hdr
.type
= SCTP_PARAM_COOKIE_PRESERVATIVE
;
2331 bht
.param_hdr
.length
= htons(sizeof(bht
));
2332 bht
.lifespan_increment
= htonl(stale
);
2334 /* Build that new INIT chunk. */
2335 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
2336 reply
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, sizeof(bht
));
2340 sctp_addto_chunk(reply
, sizeof(bht
), &bht
);
2342 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2343 sctp_add_cmd_sf(commands
, SCTP_CMD_CLEAR_INIT_TAG
, SCTP_NULL());
2345 /* Stop pending T3-rtx and heartbeat timers */
2346 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
2347 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
2349 /* Delete non-primary peer ip addresses since we are transitioning
2350 * back to the COOKIE-WAIT state
2352 sctp_add_cmd_sf(commands
, SCTP_CMD_DEL_NON_PRIMARY
, SCTP_NULL());
2354 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2357 sctp_add_cmd_sf(commands
, SCTP_CMD_T1_RETRAN
,
2358 SCTP_TRANSPORT(asoc
->peer
.primary_path
));
2360 /* Cast away the const modifier, as we want to just
2361 * rerun it through as a sideffect.
2363 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_INC
, SCTP_NULL());
2365 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2366 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
2367 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2368 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
2369 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
2370 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2372 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2374 return SCTP_DISPOSITION_CONSUME
;
2377 return SCTP_DISPOSITION_NOMEM
;
2384 * After checking the Verification Tag, the receiving endpoint shall
2385 * remove the association from its record, and shall report the
2386 * termination to its upper layer.
2388 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2389 * B) Rules for packet carrying ABORT:
2391 * - The endpoint shall always fill in the Verification Tag field of the
2392 * outbound packet with the destination endpoint's tag value if it
2395 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2396 * MUST follow the procedure described in Section 8.4.
2398 * - The receiver MUST accept the packet if the Verification Tag
2399 * matches either its own tag, OR the tag of its peer. Otherwise, the
2400 * receiver MUST silently discard the packet and take no further
2404 * (endpoint, asoc, chunk)
2407 * (asoc, reply_msg, msg_up, timers, counters)
2409 * The return value is the disposition of the chunk.
2411 sctp_disposition_t
sctp_sf_do_9_1_abort(struct net
*net
,
2412 const struct sctp_endpoint
*ep
,
2413 const struct sctp_association
*asoc
,
2414 const sctp_subtype_t type
,
2416 sctp_cmd_seq_t
*commands
)
2418 struct sctp_chunk
*chunk
= arg
;
2420 if (!sctp_vtag_verify_either(chunk
, asoc
))
2421 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2423 /* Make sure that the ABORT chunk has a valid length.
2424 * Since this is an ABORT chunk, we have to discard it
2425 * because of the following text:
2426 * RFC 2960, Section 3.3.7
2427 * If an endpoint receives an ABORT with a format error or for an
2428 * association that doesn't exist, it MUST silently discard it.
2429 * Because the length is "invalid", we can't really discard just
2430 * as we do not know its true length. So, to be safe, discard the
2433 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2434 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2436 /* ADD-IP: Special case for ABORT chunks
2437 * F4) One special consideration is that ABORT Chunks arriving
2438 * destined to the IP address being deleted MUST be
2439 * ignored (see Section 5.3.1 for further details).
2441 if (SCTP_ADDR_DEL
==
2442 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2443 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2445 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2448 static sctp_disposition_t
__sctp_sf_do_9_1_abort(struct net
*net
,
2449 const struct sctp_endpoint
*ep
,
2450 const struct sctp_association
*asoc
,
2451 const sctp_subtype_t type
,
2453 sctp_cmd_seq_t
*commands
)
2455 struct sctp_chunk
*chunk
= arg
;
2457 __be16 error
= SCTP_ERROR_NO_ERROR
;
2459 /* See if we have an error cause code in the chunk. */
2460 len
= ntohs(chunk
->chunk_hdr
->length
);
2461 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
)) {
2464 sctp_walk_errors(err
, chunk
->chunk_hdr
);
2465 if ((void *)err
!= (void *)chunk
->chunk_end
)
2466 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2468 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2471 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(ECONNRESET
));
2472 /* ASSOC_FAILED will DELETE_TCB. */
2473 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
, SCTP_PERR(error
));
2474 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
2475 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
2477 return SCTP_DISPOSITION_ABORT
;
2481 * Process an ABORT. (COOKIE-WAIT state)
2483 * See sctp_sf_do_9_1_abort() above.
2485 sctp_disposition_t
sctp_sf_cookie_wait_abort(struct net
*net
,
2486 const struct sctp_endpoint
*ep
,
2487 const struct sctp_association
*asoc
,
2488 const sctp_subtype_t type
,
2490 sctp_cmd_seq_t
*commands
)
2492 struct sctp_chunk
*chunk
= arg
;
2494 __be16 error
= SCTP_ERROR_NO_ERROR
;
2496 if (!sctp_vtag_verify_either(chunk
, asoc
))
2497 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2499 /* Make sure that the ABORT chunk has a valid length.
2500 * Since this is an ABORT chunk, we have to discard it
2501 * because of the following text:
2502 * RFC 2960, Section 3.3.7
2503 * If an endpoint receives an ABORT with a format error or for an
2504 * association that doesn't exist, it MUST silently discard it.
2505 * Because the length is "invalid", we can't really discard just
2506 * as we do not know its true length. So, to be safe, discard the
2509 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2510 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2512 /* See if we have an error cause code in the chunk. */
2513 len
= ntohs(chunk
->chunk_hdr
->length
);
2514 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2515 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2517 return sctp_stop_t1_and_abort(net
, commands
, error
, ECONNREFUSED
, asoc
,
2522 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2524 sctp_disposition_t
sctp_sf_cookie_wait_icmp_abort(struct net
*net
,
2525 const struct sctp_endpoint
*ep
,
2526 const struct sctp_association
*asoc
,
2527 const sctp_subtype_t type
,
2529 sctp_cmd_seq_t
*commands
)
2531 return sctp_stop_t1_and_abort(net
, commands
, SCTP_ERROR_NO_ERROR
,
2533 (struct sctp_transport
*)arg
);
2537 * Process an ABORT. (COOKIE-ECHOED state)
2539 sctp_disposition_t
sctp_sf_cookie_echoed_abort(struct net
*net
,
2540 const struct sctp_endpoint
*ep
,
2541 const struct sctp_association
*asoc
,
2542 const sctp_subtype_t type
,
2544 sctp_cmd_seq_t
*commands
)
2546 /* There is a single T1 timer, so we should be able to use
2547 * common function with the COOKIE-WAIT state.
2549 return sctp_sf_cookie_wait_abort(net
, ep
, asoc
, type
, arg
, commands
);
2553 * Stop T1 timer and abort association with "INIT failed".
2555 * This is common code called by several sctp_sf_*_abort() functions above.
2557 static sctp_disposition_t
sctp_stop_t1_and_abort(struct net
*net
,
2558 sctp_cmd_seq_t
*commands
,
2559 __be16 error
, int sk_err
,
2560 const struct sctp_association
*asoc
,
2561 struct sctp_transport
*transport
)
2563 SCTP_DEBUG_PRINTK("ABORT received (INIT).\n");
2564 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2565 SCTP_STATE(SCTP_STATE_CLOSED
));
2566 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
2567 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2568 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2569 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(sk_err
));
2570 /* CMD_INIT_FAILED will DELETE_TCB. */
2571 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2573 return SCTP_DISPOSITION_ABORT
;
2577 * sctp_sf_do_9_2_shut
2580 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2581 * - enter the SHUTDOWN-RECEIVED state,
2583 * - stop accepting new data from its SCTP user
2585 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2586 * that all its outstanding DATA chunks have been received by the
2589 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2590 * send a SHUTDOWN in response to a ULP request. And should discard
2591 * subsequent SHUTDOWN chunks.
2593 * If there are still outstanding DATA chunks left, the SHUTDOWN
2594 * receiver shall continue to follow normal data transmission
2595 * procedures defined in Section 6 until all outstanding DATA chunks
2596 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2597 * new data from its SCTP user.
2599 * Verification Tag: 8.5 Verification Tag [Normal verification]
2602 * (endpoint, asoc, chunk)
2605 * (asoc, reply_msg, msg_up, timers, counters)
2607 * The return value is the disposition of the chunk.
2609 sctp_disposition_t
sctp_sf_do_9_2_shutdown(struct net
*net
,
2610 const struct sctp_endpoint
*ep
,
2611 const struct sctp_association
*asoc
,
2612 const sctp_subtype_t type
,
2614 sctp_cmd_seq_t
*commands
)
2616 struct sctp_chunk
*chunk
= arg
;
2617 sctp_shutdownhdr_t
*sdh
;
2618 sctp_disposition_t disposition
;
2619 struct sctp_ulpevent
*ev
;
2622 if (!sctp_vtag_verify(chunk
, asoc
))
2623 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2625 /* Make sure that the SHUTDOWN chunk has a valid length. */
2626 if (!sctp_chunk_length_valid(chunk
,
2627 sizeof(struct sctp_shutdown_chunk_t
)))
2628 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2631 /* Convert the elaborate header. */
2632 sdh
= (sctp_shutdownhdr_t
*)chunk
->skb
->data
;
2633 skb_pull(chunk
->skb
, sizeof(sctp_shutdownhdr_t
));
2634 chunk
->subh
.shutdown_hdr
= sdh
;
2635 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2637 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2638 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn
);
2639 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc
->ctsn_ack_point
);
2640 return SCTP_DISPOSITION_DISCARD
;
2643 /* If Cumulative TSN Ack beyond the max tsn currently
2644 * send, terminating the association and respond to the
2645 * sender with an ABORT.
2647 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2648 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
2650 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2651 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2652 * inform the application that it should cease sending data.
2654 ev
= sctp_ulpevent_make_shutdown_event(asoc
, 0, GFP_ATOMIC
);
2656 disposition
= SCTP_DISPOSITION_NOMEM
;
2659 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
2661 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2662 * - enter the SHUTDOWN-RECEIVED state,
2663 * - stop accepting new data from its SCTP user
2665 * [This is implicit in the new state.]
2667 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2668 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED
));
2669 disposition
= SCTP_DISPOSITION_CONSUME
;
2671 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
2672 disposition
= sctp_sf_do_9_2_shutdown_ack(net
, ep
, asoc
, type
,
2676 if (SCTP_DISPOSITION_NOMEM
== disposition
)
2679 /* - verify, by checking the Cumulative TSN Ack field of the
2680 * chunk, that all its outstanding DATA chunks have been
2681 * received by the SHUTDOWN sender.
2683 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2684 SCTP_BE32(chunk
->subh
.shutdown_hdr
->cum_tsn_ack
));
2691 * sctp_sf_do_9_2_shut_ctsn
2693 * Once an endpoint has reached the SHUTDOWN-RECEIVED state,
2694 * it MUST NOT send a SHUTDOWN in response to a ULP request.
2695 * The Cumulative TSN Ack of the received SHUTDOWN chunk
2696 * MUST be processed.
2698 sctp_disposition_t
sctp_sf_do_9_2_shut_ctsn(struct net
*net
,
2699 const struct sctp_endpoint
*ep
,
2700 const struct sctp_association
*asoc
,
2701 const sctp_subtype_t type
,
2703 sctp_cmd_seq_t
*commands
)
2705 struct sctp_chunk
*chunk
= arg
;
2706 sctp_shutdownhdr_t
*sdh
;
2709 if (!sctp_vtag_verify(chunk
, asoc
))
2710 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2712 /* Make sure that the SHUTDOWN chunk has a valid length. */
2713 if (!sctp_chunk_length_valid(chunk
,
2714 sizeof(struct sctp_shutdown_chunk_t
)))
2715 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2718 sdh
= (sctp_shutdownhdr_t
*)chunk
->skb
->data
;
2719 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2721 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2722 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn
);
2723 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc
->ctsn_ack_point
);
2724 return SCTP_DISPOSITION_DISCARD
;
2727 /* If Cumulative TSN Ack beyond the max tsn currently
2728 * send, terminating the association and respond to the
2729 * sender with an ABORT.
2731 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2732 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
2734 /* verify, by checking the Cumulative TSN Ack field of the
2735 * chunk, that all its outstanding DATA chunks have been
2736 * received by the SHUTDOWN sender.
2738 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2739 SCTP_BE32(sdh
->cum_tsn_ack
));
2741 return SCTP_DISPOSITION_CONSUME
;
2745 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2746 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2747 * transport addresses (either in the IP addresses or in the INIT chunk)
2748 * that belong to this association, it should discard the INIT chunk and
2749 * retransmit the SHUTDOWN ACK chunk.
2751 sctp_disposition_t
sctp_sf_do_9_2_reshutack(struct net
*net
,
2752 const struct sctp_endpoint
*ep
,
2753 const struct sctp_association
*asoc
,
2754 const sctp_subtype_t type
,
2756 sctp_cmd_seq_t
*commands
)
2758 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
2759 struct sctp_chunk
*reply
;
2761 /* Make sure that the chunk has a valid length */
2762 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
2763 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2766 /* Since we are not going to really process this INIT, there
2767 * is no point in verifying chunk boundries. Just generate
2770 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
2774 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2775 * the T2-SHUTDOWN timer.
2777 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
2779 /* and restart the T2-shutdown timer. */
2780 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2781 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2783 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2785 return SCTP_DISPOSITION_CONSUME
;
2787 return SCTP_DISPOSITION_NOMEM
;
2791 * sctp_sf_do_ecn_cwr
2793 * Section: Appendix A: Explicit Congestion Notification
2797 * RFC 2481 details a specific bit for a sender to send in the header of
2798 * its next outbound TCP segment to indicate to its peer that it has
2799 * reduced its congestion window. This is termed the CWR bit. For
2800 * SCTP the same indication is made by including the CWR chunk.
2801 * This chunk contains one data element, i.e. the TSN number that
2802 * was sent in the ECNE chunk. This element represents the lowest
2803 * TSN number in the datagram that was originally marked with the
2806 * Verification Tag: 8.5 Verification Tag [Normal verification]
2808 * (endpoint, asoc, chunk)
2811 * (asoc, reply_msg, msg_up, timers, counters)
2813 * The return value is the disposition of the chunk.
2815 sctp_disposition_t
sctp_sf_do_ecn_cwr(struct net
*net
,
2816 const struct sctp_endpoint
*ep
,
2817 const struct sctp_association
*asoc
,
2818 const sctp_subtype_t type
,
2820 sctp_cmd_seq_t
*commands
)
2823 struct sctp_chunk
*chunk
= arg
;
2826 if (!sctp_vtag_verify(chunk
, asoc
))
2827 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2829 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2830 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2833 cwr
= (sctp_cwrhdr_t
*) chunk
->skb
->data
;
2834 skb_pull(chunk
->skb
, sizeof(sctp_cwrhdr_t
));
2836 lowest_tsn
= ntohl(cwr
->lowest_tsn
);
2838 /* Does this CWR ack the last sent congestion notification? */
2839 if (TSN_lte(asoc
->last_ecne_tsn
, lowest_tsn
)) {
2840 /* Stop sending ECNE. */
2841 sctp_add_cmd_sf(commands
,
2843 SCTP_U32(lowest_tsn
));
2845 return SCTP_DISPOSITION_CONSUME
;
2851 * Section: Appendix A: Explicit Congestion Notification
2855 * RFC 2481 details a specific bit for a receiver to send back in its
2856 * TCP acknowledgements to notify the sender of the Congestion
2857 * Experienced (CE) bit having arrived from the network. For SCTP this
2858 * same indication is made by including the ECNE chunk. This chunk
2859 * contains one data element, i.e. the lowest TSN associated with the IP
2860 * datagram marked with the CE bit.....
2862 * Verification Tag: 8.5 Verification Tag [Normal verification]
2864 * (endpoint, asoc, chunk)
2867 * (asoc, reply_msg, msg_up, timers, counters)
2869 * The return value is the disposition of the chunk.
2871 sctp_disposition_t
sctp_sf_do_ecne(struct net
*net
,
2872 const struct sctp_endpoint
*ep
,
2873 const struct sctp_association
*asoc
,
2874 const sctp_subtype_t type
,
2876 sctp_cmd_seq_t
*commands
)
2878 sctp_ecnehdr_t
*ecne
;
2879 struct sctp_chunk
*chunk
= arg
;
2881 if (!sctp_vtag_verify(chunk
, asoc
))
2882 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2884 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2885 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2888 ecne
= (sctp_ecnehdr_t
*) chunk
->skb
->data
;
2889 skb_pull(chunk
->skb
, sizeof(sctp_ecnehdr_t
));
2891 /* If this is a newer ECNE than the last CWR packet we sent out */
2892 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_ECNE
,
2893 SCTP_U32(ntohl(ecne
->lowest_tsn
)));
2895 return SCTP_DISPOSITION_CONSUME
;
2899 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2901 * The SCTP endpoint MUST always acknowledge the reception of each valid
2904 * The guidelines on delayed acknowledgement algorithm specified in
2905 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2906 * acknowledgement SHOULD be generated for at least every second packet
2907 * (not every second DATA chunk) received, and SHOULD be generated within
2908 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2909 * situations it may be beneficial for an SCTP transmitter to be more
2910 * conservative than the algorithms detailed in this document allow.
2911 * However, an SCTP transmitter MUST NOT be more aggressive than the
2912 * following algorithms allow.
2914 * A SCTP receiver MUST NOT generate more than one SACK for every
2915 * incoming packet, other than to update the offered window as the
2916 * receiving application consumes new data.
2918 * Verification Tag: 8.5 Verification Tag [Normal verification]
2921 * (endpoint, asoc, chunk)
2924 * (asoc, reply_msg, msg_up, timers, counters)
2926 * The return value is the disposition of the chunk.
2928 sctp_disposition_t
sctp_sf_eat_data_6_2(struct net
*net
,
2929 const struct sctp_endpoint
*ep
,
2930 const struct sctp_association
*asoc
,
2931 const sctp_subtype_t type
,
2933 sctp_cmd_seq_t
*commands
)
2935 struct sctp_chunk
*chunk
= arg
;
2936 sctp_arg_t force
= SCTP_NOFORCE();
2939 if (!sctp_vtag_verify(chunk
, asoc
)) {
2940 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
2942 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2945 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
2946 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2949 error
= sctp_eat_data(asoc
, chunk
, commands
);
2951 case SCTP_IERROR_NO_ERROR
:
2953 case SCTP_IERROR_HIGH_TSN
:
2954 case SCTP_IERROR_BAD_STREAM
:
2955 SCTP_INC_STATS(net
, SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
2956 goto discard_noforce
;
2957 case SCTP_IERROR_DUP_TSN
:
2958 case SCTP_IERROR_IGNORE_TSN
:
2959 SCTP_INC_STATS(net
, SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
2961 case SCTP_IERROR_NO_DATA
:
2963 case SCTP_IERROR_PROTO_VIOLATION
:
2964 return sctp_sf_abort_violation(net
, ep
, asoc
, chunk
, commands
,
2965 (u8
*)chunk
->subh
.data_hdr
, sizeof(sctp_datahdr_t
));
2970 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_SACK_IMM
)
2971 force
= SCTP_FORCE();
2973 if (asoc
->autoclose
) {
2974 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2975 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
2978 /* If this is the last chunk in a packet, we need to count it
2979 * toward sack generation. Note that we need to SACK every
2980 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2981 * THEM. We elect to NOT generate SACK's if the chunk fails
2982 * the verification tag test.
2984 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2986 * The SCTP endpoint MUST always acknowledge the reception of
2987 * each valid DATA chunk.
2989 * The guidelines on delayed acknowledgement algorithm
2990 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2991 * Specifically, an acknowledgement SHOULD be generated for at
2992 * least every second packet (not every second DATA chunk)
2993 * received, and SHOULD be generated within 200 ms of the
2994 * arrival of any unacknowledged DATA chunk. In some
2995 * situations it may be beneficial for an SCTP transmitter to
2996 * be more conservative than the algorithms detailed in this
2997 * document allow. However, an SCTP transmitter MUST NOT be
2998 * more aggressive than the following algorithms allow.
3000 if (chunk
->end_of_packet
)
3001 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, force
);
3003 return SCTP_DISPOSITION_CONSUME
;
3006 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
3008 * When a packet arrives with duplicate DATA chunk(s) and with
3009 * no new DATA chunk(s), the endpoint MUST immediately send a
3010 * SACK with no delay. If a packet arrives with duplicate
3011 * DATA chunk(s) bundled with new DATA chunks, the endpoint
3012 * MAY immediately send a SACK. Normally receipt of duplicate
3013 * DATA chunks will occur when the original SACK chunk was lost
3014 * and the peer's RTO has expired. The duplicate TSN number(s)
3015 * SHOULD be reported in the SACK as duplicate.
3017 /* In our case, we split the MAY SACK advice up whether or not
3018 * the last chunk is a duplicate.'
3020 if (chunk
->end_of_packet
)
3021 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3022 return SCTP_DISPOSITION_DISCARD
;
3025 if (chunk
->end_of_packet
)
3026 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, force
);
3028 return SCTP_DISPOSITION_DISCARD
;
3030 return SCTP_DISPOSITION_CONSUME
;
3035 * sctp_sf_eat_data_fast_4_4
3038 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
3039 * DATA chunks without delay.
3041 * Verification Tag: 8.5 Verification Tag [Normal verification]
3043 * (endpoint, asoc, chunk)
3046 * (asoc, reply_msg, msg_up, timers, counters)
3048 * The return value is the disposition of the chunk.
3050 sctp_disposition_t
sctp_sf_eat_data_fast_4_4(struct net
*net
,
3051 const struct sctp_endpoint
*ep
,
3052 const struct sctp_association
*asoc
,
3053 const sctp_subtype_t type
,
3055 sctp_cmd_seq_t
*commands
)
3057 struct sctp_chunk
*chunk
= arg
;
3060 if (!sctp_vtag_verify(chunk
, asoc
)) {
3061 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3063 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3066 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
3067 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3070 error
= sctp_eat_data(asoc
, chunk
, commands
);
3072 case SCTP_IERROR_NO_ERROR
:
3073 case SCTP_IERROR_HIGH_TSN
:
3074 case SCTP_IERROR_DUP_TSN
:
3075 case SCTP_IERROR_IGNORE_TSN
:
3076 case SCTP_IERROR_BAD_STREAM
:
3078 case SCTP_IERROR_NO_DATA
:
3080 case SCTP_IERROR_PROTO_VIOLATION
:
3081 return sctp_sf_abort_violation(net
, ep
, asoc
, chunk
, commands
,
3082 (u8
*)chunk
->subh
.data_hdr
, sizeof(sctp_datahdr_t
));
3087 /* Go a head and force a SACK, since we are shutting down. */
3089 /* Implementor's Guide.
3091 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3092 * respond to each received packet containing one or more DATA chunk(s)
3093 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3095 if (chunk
->end_of_packet
) {
3096 /* We must delay the chunk creation since the cumulative
3097 * TSN has not been updated yet.
3099 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3100 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3101 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3102 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3106 return SCTP_DISPOSITION_CONSUME
;
3110 * Section: 6.2 Processing a Received SACK
3111 * D) Any time a SACK arrives, the endpoint performs the following:
3113 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
3114 * then drop the SACK. Since Cumulative TSN Ack is monotonically
3115 * increasing, a SACK whose Cumulative TSN Ack is less than the
3116 * Cumulative TSN Ack Point indicates an out-of-order SACK.
3118 * ii) Set rwnd equal to the newly received a_rwnd minus the number
3119 * of bytes still outstanding after processing the Cumulative TSN Ack
3120 * and the Gap Ack Blocks.
3122 * iii) If the SACK is missing a TSN that was previously
3123 * acknowledged via a Gap Ack Block (e.g., the data receiver
3124 * reneged on the data), then mark the corresponding DATA chunk
3125 * as available for retransmit: Mark it as missing for fast
3126 * retransmit as described in Section 7.2.4 and if no retransmit
3127 * timer is running for the destination address to which the DATA
3128 * chunk was originally transmitted, then T3-rtx is started for
3129 * that destination address.
3131 * Verification Tag: 8.5 Verification Tag [Normal verification]
3134 * (endpoint, asoc, chunk)
3137 * (asoc, reply_msg, msg_up, timers, counters)
3139 * The return value is the disposition of the chunk.
3141 sctp_disposition_t
sctp_sf_eat_sack_6_2(struct net
*net
,
3142 const struct sctp_endpoint
*ep
,
3143 const struct sctp_association
*asoc
,
3144 const sctp_subtype_t type
,
3146 sctp_cmd_seq_t
*commands
)
3148 struct sctp_chunk
*chunk
= arg
;
3149 sctp_sackhdr_t
*sackh
;
3152 if (!sctp_vtag_verify(chunk
, asoc
))
3153 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3155 /* Make sure that the SACK chunk has a valid length. */
3156 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_sack_chunk_t
)))
3157 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3160 /* Pull the SACK chunk from the data buffer */
3161 sackh
= sctp_sm_pull_sack(chunk
);
3162 /* Was this a bogus SACK? */
3164 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3165 chunk
->subh
.sack_hdr
= sackh
;
3166 ctsn
= ntohl(sackh
->cum_tsn_ack
);
3168 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
3169 * Ack Point, then drop the SACK. Since Cumulative TSN
3170 * Ack is monotonically increasing, a SACK whose
3171 * Cumulative TSN Ack is less than the Cumulative TSN Ack
3172 * Point indicates an out-of-order SACK.
3174 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
3175 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn
);
3176 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc
->ctsn_ack_point
);
3177 return SCTP_DISPOSITION_DISCARD
;
3180 /* If Cumulative TSN Ack beyond the max tsn currently
3181 * send, terminating the association and respond to the
3182 * sender with an ABORT.
3184 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
3185 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
3187 /* Return this SACK for further processing. */
3188 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_SACK
, SCTP_CHUNK(chunk
));
3190 /* Note: We do the rest of the work on the PROCESS_SACK
3193 return SCTP_DISPOSITION_CONSUME
;
3197 * Generate an ABORT in response to a packet.
3199 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
3201 * 8) The receiver should respond to the sender of the OOTB packet with
3202 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3203 * MUST fill in the Verification Tag field of the outbound packet
3204 * with the value found in the Verification Tag field of the OOTB
3205 * packet and set the T-bit in the Chunk Flags to indicate that the
3206 * Verification Tag is reflected. After sending this ABORT, the
3207 * receiver of the OOTB packet shall discard the OOTB packet and take
3208 * no further action.
3212 * The return value is the disposition of the chunk.
3214 static sctp_disposition_t
sctp_sf_tabort_8_4_8(struct net
*net
,
3215 const struct sctp_endpoint
*ep
,
3216 const struct sctp_association
*asoc
,
3217 const sctp_subtype_t type
,
3219 sctp_cmd_seq_t
*commands
)
3221 struct sctp_packet
*packet
= NULL
;
3222 struct sctp_chunk
*chunk
= arg
;
3223 struct sctp_chunk
*abort
;
3225 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
3228 /* Make an ABORT. The T bit will be set if the asoc
3231 abort
= sctp_make_abort(asoc
, chunk
, 0);
3233 sctp_ootb_pkt_free(packet
);
3234 return SCTP_DISPOSITION_NOMEM
;
3237 /* Reflect vtag if T-Bit is set */
3238 if (sctp_test_T_bit(abort
))
3239 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3241 /* Set the skb to the belonging sock for accounting. */
3242 abort
->skb
->sk
= ep
->base
.sk
;
3244 sctp_packet_append_chunk(packet
, abort
);
3246 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3247 SCTP_PACKET(packet
));
3249 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
3251 sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3252 return SCTP_DISPOSITION_CONSUME
;
3255 return SCTP_DISPOSITION_NOMEM
;
3259 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
3260 * event as ULP notification for each cause included in the chunk.
3262 * API 5.3.1.3 - SCTP_REMOTE_ERROR
3264 * The return value is the disposition of the chunk.
3266 sctp_disposition_t
sctp_sf_operr_notify(struct net
*net
,
3267 const struct sctp_endpoint
*ep
,
3268 const struct sctp_association
*asoc
,
3269 const sctp_subtype_t type
,
3271 sctp_cmd_seq_t
*commands
)
3273 struct sctp_chunk
*chunk
= arg
;
3276 if (!sctp_vtag_verify(chunk
, asoc
))
3277 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3279 /* Make sure that the ERROR chunk has a valid length. */
3280 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
3281 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3283 sctp_walk_errors(err
, chunk
->chunk_hdr
);
3284 if ((void *)err
!= (void *)chunk
->chunk_end
)
3285 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3286 (void *)err
, commands
);
3288 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_OPERR
,
3291 return SCTP_DISPOSITION_CONSUME
;
3295 * Process an inbound SHUTDOWN ACK.
3298 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3299 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3300 * peer, and remove all record of the association.
3302 * The return value is the disposition.
3304 sctp_disposition_t
sctp_sf_do_9_2_final(struct net
*net
,
3305 const struct sctp_endpoint
*ep
,
3306 const struct sctp_association
*asoc
,
3307 const sctp_subtype_t type
,
3309 sctp_cmd_seq_t
*commands
)
3311 struct sctp_chunk
*chunk
= arg
;
3312 struct sctp_chunk
*reply
;
3313 struct sctp_ulpevent
*ev
;
3315 if (!sctp_vtag_verify(chunk
, asoc
))
3316 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3318 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3319 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3320 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3322 /* 10.2 H) SHUTDOWN COMPLETE notification
3324 * When SCTP completes the shutdown procedures (section 9.2) this
3325 * notification is passed to the upper layer.
3327 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
3328 0, 0, 0, NULL
, GFP_ATOMIC
);
3332 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3333 reply
= sctp_make_shutdown_complete(asoc
, chunk
);
3337 /* Do all the commands now (after allocation), so that we
3338 * have consistent state if memory allocation failes
3340 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
3342 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3343 * stop the T2-shutdown timer,
3345 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3346 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3348 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3349 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
3351 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
3352 SCTP_STATE(SCTP_STATE_CLOSED
));
3353 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
3354 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3355 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
3357 /* ...and remove all record of the association. */
3358 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
3359 return SCTP_DISPOSITION_DELETE_TCB
;
3362 sctp_ulpevent_free(ev
);
3364 return SCTP_DISPOSITION_NOMEM
;
3368 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3370 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3371 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3372 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3373 * packet must fill in the Verification Tag field of the outbound
3374 * packet with the Verification Tag received in the SHUTDOWN ACK and
3375 * set the T-bit in the Chunk Flags to indicate that the Verification
3378 * 8) The receiver should respond to the sender of the OOTB packet with
3379 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3380 * MUST fill in the Verification Tag field of the outbound packet
3381 * with the value found in the Verification Tag field of the OOTB
3382 * packet and set the T-bit in the Chunk Flags to indicate that the
3383 * Verification Tag is reflected. After sending this ABORT, the
3384 * receiver of the OOTB packet shall discard the OOTB packet and take
3385 * no further action.
3387 sctp_disposition_t
sctp_sf_ootb(struct net
*net
,
3388 const struct sctp_endpoint
*ep
,
3389 const struct sctp_association
*asoc
,
3390 const sctp_subtype_t type
,
3392 sctp_cmd_seq_t
*commands
)
3394 struct sctp_chunk
*chunk
= arg
;
3395 struct sk_buff
*skb
= chunk
->skb
;
3396 sctp_chunkhdr_t
*ch
;
3399 int ootb_shut_ack
= 0;
3400 int ootb_cookie_ack
= 0;
3402 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
3404 ch
= (sctp_chunkhdr_t
*) chunk
->chunk_hdr
;
3406 /* Report violation if the chunk is less then minimal */
3407 if (ntohs(ch
->length
) < sizeof(sctp_chunkhdr_t
))
3408 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3411 /* Now that we know we at least have a chunk header,
3412 * do things that are type appropriate.
3414 if (SCTP_CID_SHUTDOWN_ACK
== ch
->type
)
3417 /* RFC 2960, Section 3.3.7
3418 * Moreover, under any circumstances, an endpoint that
3419 * receives an ABORT MUST NOT respond to that ABORT by
3420 * sending an ABORT of its own.
3422 if (SCTP_CID_ABORT
== ch
->type
)
3423 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3425 /* RFC 8.4, 7) If the packet contains a "Stale cookie" ERROR
3426 * or a COOKIE ACK the SCTP Packet should be silently
3430 if (SCTP_CID_COOKIE_ACK
== ch
->type
)
3431 ootb_cookie_ack
= 1;
3433 if (SCTP_CID_ERROR
== ch
->type
) {
3434 sctp_walk_errors(err
, ch
) {
3435 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
) {
3436 ootb_cookie_ack
= 1;
3442 /* Report violation if chunk len overflows */
3443 ch_end
= ((__u8
*)ch
) + WORD_ROUND(ntohs(ch
->length
));
3444 if (ch_end
> skb_tail_pointer(skb
))
3445 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3448 ch
= (sctp_chunkhdr_t
*) ch_end
;
3449 } while (ch_end
< skb_tail_pointer(skb
));
3452 return sctp_sf_shut_8_4_5(net
, ep
, asoc
, type
, arg
, commands
);
3453 else if (ootb_cookie_ack
)
3454 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3456 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
3460 * Handle an "Out of the blue" SHUTDOWN ACK.
3462 * Section: 8.4 5, sctpimpguide 2.41.
3464 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3465 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3466 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3467 * packet must fill in the Verification Tag field of the outbound
3468 * packet with the Verification Tag received in the SHUTDOWN ACK and
3469 * set the T-bit in the Chunk Flags to indicate that the Verification
3473 * (endpoint, asoc, type, arg, commands)
3476 * (sctp_disposition_t)
3478 * The return value is the disposition of the chunk.
3480 static sctp_disposition_t
sctp_sf_shut_8_4_5(struct net
*net
,
3481 const struct sctp_endpoint
*ep
,
3482 const struct sctp_association
*asoc
,
3483 const sctp_subtype_t type
,
3485 sctp_cmd_seq_t
*commands
)
3487 struct sctp_packet
*packet
= NULL
;
3488 struct sctp_chunk
*chunk
= arg
;
3489 struct sctp_chunk
*shut
;
3491 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
3494 /* Make an SHUTDOWN_COMPLETE.
3495 * The T bit will be set if the asoc is NULL.
3497 shut
= sctp_make_shutdown_complete(asoc
, chunk
);
3499 sctp_ootb_pkt_free(packet
);
3500 return SCTP_DISPOSITION_NOMEM
;
3503 /* Reflect vtag if T-Bit is set */
3504 if (sctp_test_T_bit(shut
))
3505 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3507 /* Set the skb to the belonging sock for accounting. */
3508 shut
->skb
->sk
= ep
->base
.sk
;
3510 sctp_packet_append_chunk(packet
, shut
);
3512 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3513 SCTP_PACKET(packet
));
3515 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
3517 /* If the chunk length is invalid, we don't want to process
3518 * the reset of the packet.
3520 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3521 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3523 /* We need to discard the rest of the packet to prevent
3524 * potential bomming attacks from additional bundled chunks.
3525 * This is documented in SCTP Threats ID.
3527 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3530 return SCTP_DISPOSITION_NOMEM
;
3534 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3536 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3537 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3538 * procedures in section 8.4 SHOULD be followed, in other words it
3539 * should be treated as an Out Of The Blue packet.
3540 * [This means that we do NOT check the Verification Tag on these
3544 sctp_disposition_t
sctp_sf_do_8_5_1_E_sa(struct net
*net
,
3545 const struct sctp_endpoint
*ep
,
3546 const struct sctp_association
*asoc
,
3547 const sctp_subtype_t type
,
3549 sctp_cmd_seq_t
*commands
)
3551 struct sctp_chunk
*chunk
= arg
;
3553 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3554 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3555 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3558 /* Although we do have an association in this case, it corresponds
3559 * to a restarted association. So the packet is treated as an OOTB
3560 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3561 * called with a NULL association.
3563 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
3565 return sctp_sf_shut_8_4_5(net
, ep
, NULL
, type
, arg
, commands
);
3568 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3569 sctp_disposition_t
sctp_sf_do_asconf(struct net
*net
,
3570 const struct sctp_endpoint
*ep
,
3571 const struct sctp_association
*asoc
,
3572 const sctp_subtype_t type
, void *arg
,
3573 sctp_cmd_seq_t
*commands
)
3575 struct sctp_chunk
*chunk
= arg
;
3576 struct sctp_chunk
*asconf_ack
= NULL
;
3577 struct sctp_paramhdr
*err_param
= NULL
;
3578 sctp_addiphdr_t
*hdr
;
3579 union sctp_addr_param
*addr_param
;
3583 if (!sctp_vtag_verify(chunk
, asoc
)) {
3584 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3586 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3589 /* ADD-IP: Section 4.1.1
3590 * This chunk MUST be sent in an authenticated way by using
3591 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3592 * is received unauthenticated it MUST be silently discarded as
3593 * described in [I-D.ietf-tsvwg-sctp-auth].
3595 if (!net
->sctp
.addip_noauth
&& !chunk
->auth
)
3596 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
3598 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3599 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_addip_chunk_t
)))
3600 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3603 hdr
= (sctp_addiphdr_t
*)chunk
->skb
->data
;
3604 serial
= ntohl(hdr
->serial
);
3606 addr_param
= (union sctp_addr_param
*)hdr
->params
;
3607 length
= ntohs(addr_param
->p
.length
);
3608 if (length
< sizeof(sctp_paramhdr_t
))
3609 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3610 (void *)addr_param
, commands
);
3612 /* Verify the ASCONF chunk before processing it. */
3613 if (!sctp_verify_asconf(asoc
,
3614 (sctp_paramhdr_t
*)((void *)addr_param
+ length
),
3615 (void *)chunk
->chunk_end
,
3617 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3618 (void *)err_param
, commands
);
3620 /* ADDIP 5.2 E1) Compare the value of the serial number to the value
3621 * the endpoint stored in a new association variable
3622 * 'Peer-Serial-Number'.
3624 if (serial
== asoc
->peer
.addip_serial
+ 1) {
3625 /* If this is the first instance of ASCONF in the packet,
3626 * we can clean our old ASCONF-ACKs.
3628 if (!chunk
->has_asconf
)
3629 sctp_assoc_clean_asconf_ack_cache(asoc
);
3631 /* ADDIP 5.2 E4) When the Sequence Number matches the next one
3632 * expected, process the ASCONF as described below and after
3633 * processing the ASCONF Chunk, append an ASCONF-ACK Chunk to
3634 * the response packet and cache a copy of it (in the event it
3635 * later needs to be retransmitted).
3637 * Essentially, do V1-V5.
3639 asconf_ack
= sctp_process_asconf((struct sctp_association
*)
3642 return SCTP_DISPOSITION_NOMEM
;
3643 } else if (serial
< asoc
->peer
.addip_serial
+ 1) {
3645 * If the value found in the Sequence Number is less than the
3646 * ('Peer- Sequence-Number' + 1), simply skip to the next
3647 * ASCONF, and include in the outbound response packet
3648 * any previously cached ASCONF-ACK response that was
3649 * sent and saved that matches the Sequence Number of the
3650 * ASCONF. Note: It is possible that no cached ASCONF-ACK
3651 * Chunk exists. This will occur when an older ASCONF
3652 * arrives out of order. In such a case, the receiver
3653 * should skip the ASCONF Chunk and not include ASCONF-ACK
3654 * Chunk for that chunk.
3656 asconf_ack
= sctp_assoc_lookup_asconf_ack(asoc
, hdr
->serial
);
3658 return SCTP_DISPOSITION_DISCARD
;
3660 /* Reset the transport so that we select the correct one
3661 * this time around. This is to make sure that we don't
3662 * accidentally use a stale transport that's been removed.
3664 asconf_ack
->transport
= NULL
;
3666 /* ADDIP 5.2 E5) Otherwise, the ASCONF Chunk is discarded since
3667 * it must be either a stale packet or from an attacker.
3669 return SCTP_DISPOSITION_DISCARD
;
3672 /* ADDIP 5.2 E6) The destination address of the SCTP packet
3673 * containing the ASCONF-ACK Chunks MUST be the source address of
3674 * the SCTP packet that held the ASCONF Chunks.
3676 * To do this properly, we'll set the destination address of the chunk
3677 * and at the transmit time, will try look up the transport to use.
3678 * Since ASCONFs may be bundled, the correct transport may not be
3679 * created until we process the entire packet, thus this workaround.
3681 asconf_ack
->dest
= chunk
->source
;
3682 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(asconf_ack
));
3683 if (asoc
->new_transport
) {
3684 sctp_sf_heartbeat(ep
, asoc
, type
, asoc
->new_transport
,
3686 ((struct sctp_association
*)asoc
)->new_transport
= NULL
;
3689 return SCTP_DISPOSITION_CONSUME
;
3693 * ADDIP Section 4.3 General rules for address manipulation
3694 * When building TLV parameters for the ASCONF Chunk that will add or
3695 * delete IP addresses the D0 to D13 rules should be applied:
3697 sctp_disposition_t
sctp_sf_do_asconf_ack(struct net
*net
,
3698 const struct sctp_endpoint
*ep
,
3699 const struct sctp_association
*asoc
,
3700 const sctp_subtype_t type
, void *arg
,
3701 sctp_cmd_seq_t
*commands
)
3703 struct sctp_chunk
*asconf_ack
= arg
;
3704 struct sctp_chunk
*last_asconf
= asoc
->addip_last_asconf
;
3705 struct sctp_chunk
*abort
;
3706 struct sctp_paramhdr
*err_param
= NULL
;
3707 sctp_addiphdr_t
*addip_hdr
;
3708 __u32 sent_serial
, rcvd_serial
;
3710 if (!sctp_vtag_verify(asconf_ack
, asoc
)) {
3711 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3713 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3716 /* ADD-IP, Section 4.1.2:
3717 * This chunk MUST be sent in an authenticated way by using
3718 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3719 * is received unauthenticated it MUST be silently discarded as
3720 * described in [I-D.ietf-tsvwg-sctp-auth].
3722 if (!net
->sctp
.addip_noauth
&& !asconf_ack
->auth
)
3723 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
3725 /* Make sure that the ADDIP chunk has a valid length. */
3726 if (!sctp_chunk_length_valid(asconf_ack
, sizeof(sctp_addip_chunk_t
)))
3727 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3730 addip_hdr
= (sctp_addiphdr_t
*)asconf_ack
->skb
->data
;
3731 rcvd_serial
= ntohl(addip_hdr
->serial
);
3733 /* Verify the ASCONF-ACK chunk before processing it. */
3734 if (!sctp_verify_asconf(asoc
,
3735 (sctp_paramhdr_t
*)addip_hdr
->params
,
3736 (void *)asconf_ack
->chunk_end
,
3738 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3739 (void *)err_param
, commands
);
3742 addip_hdr
= (sctp_addiphdr_t
*)last_asconf
->subh
.addip_hdr
;
3743 sent_serial
= ntohl(addip_hdr
->serial
);
3745 sent_serial
= asoc
->addip_serial
- 1;
3748 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3749 * equal to the next serial number to be used but no ASCONF chunk is
3750 * outstanding the endpoint MUST ABORT the association. Note that a
3751 * sequence number is greater than if it is no more than 2^^31-1
3752 * larger than the current sequence number (using serial arithmetic).
3754 if (ADDIP_SERIAL_gte(rcvd_serial
, sent_serial
+ 1) &&
3755 !(asoc
->addip_last_asconf
)) {
3756 abort
= sctp_make_abort(asoc
, asconf_ack
,
3757 sizeof(sctp_errhdr_t
));
3759 sctp_init_cause(abort
, SCTP_ERROR_ASCONF_ACK
, 0);
3760 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3763 /* We are going to ABORT, so we might as well stop
3764 * processing the rest of the chunks in the packet.
3766 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3767 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3768 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
3769 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3770 SCTP_ERROR(ECONNABORTED
));
3771 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3772 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3773 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
3774 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3775 return SCTP_DISPOSITION_ABORT
;
3778 if ((rcvd_serial
== sent_serial
) && asoc
->addip_last_asconf
) {
3779 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3780 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3782 if (!sctp_process_asconf_ack((struct sctp_association
*)asoc
,
3784 /* Successfully processed ASCONF_ACK. We can
3785 * release the next asconf if we have one.
3787 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_NEXT_ASCONF
,
3789 return SCTP_DISPOSITION_CONSUME
;
3792 abort
= sctp_make_abort(asoc
, asconf_ack
,
3793 sizeof(sctp_errhdr_t
));
3795 sctp_init_cause(abort
, SCTP_ERROR_RSRC_LOW
, 0);
3796 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3799 /* We are going to ABORT, so we might as well stop
3800 * processing the rest of the chunks in the packet.
3802 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
3803 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3804 SCTP_ERROR(ECONNABORTED
));
3805 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3806 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3807 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
3808 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3809 return SCTP_DISPOSITION_ABORT
;
3812 return SCTP_DISPOSITION_DISCARD
;
3816 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3818 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3819 * its cumulative TSN point to the value carried in the FORWARD TSN
3820 * chunk, and then MUST further advance its cumulative TSN point locally
3822 * After the above processing, the data receiver MUST stop reporting any
3823 * missing TSNs earlier than or equal to the new cumulative TSN point.
3825 * Verification Tag: 8.5 Verification Tag [Normal verification]
3827 * The return value is the disposition of the chunk.
3829 sctp_disposition_t
sctp_sf_eat_fwd_tsn(struct net
*net
,
3830 const struct sctp_endpoint
*ep
,
3831 const struct sctp_association
*asoc
,
3832 const sctp_subtype_t type
,
3834 sctp_cmd_seq_t
*commands
)
3836 struct sctp_chunk
*chunk
= arg
;
3837 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3838 struct sctp_fwdtsn_skip
*skip
;
3842 if (!sctp_vtag_verify(chunk
, asoc
)) {
3843 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3845 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3848 /* Make sure that the FORWARD_TSN chunk has valid length. */
3849 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3850 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3853 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3854 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3855 len
= ntohs(chunk
->chunk_hdr
->length
);
3856 len
-= sizeof(struct sctp_chunkhdr
);
3857 skb_pull(chunk
->skb
, len
);
3859 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3860 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __func__
, tsn
);
3862 /* The TSN is too high--silently discard the chunk and count on it
3863 * getting retransmitted later.
3865 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3866 goto discard_noforce
;
3868 /* Silently discard the chunk if stream-id is not valid */
3869 sctp_walk_fwdtsn(skip
, chunk
) {
3870 if (ntohs(skip
->stream
) >= asoc
->c
.sinit_max_instreams
)
3871 goto discard_noforce
;
3874 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3875 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3876 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3879 /* Count this as receiving DATA. */
3880 if (asoc
->autoclose
) {
3881 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3882 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
3885 /* FIXME: For now send a SACK, but DATA processing may
3888 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
3890 return SCTP_DISPOSITION_CONSUME
;
3893 return SCTP_DISPOSITION_DISCARD
;
3896 sctp_disposition_t
sctp_sf_eat_fwd_tsn_fast(
3898 const struct sctp_endpoint
*ep
,
3899 const struct sctp_association
*asoc
,
3900 const sctp_subtype_t type
,
3902 sctp_cmd_seq_t
*commands
)
3904 struct sctp_chunk
*chunk
= arg
;
3905 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3906 struct sctp_fwdtsn_skip
*skip
;
3910 if (!sctp_vtag_verify(chunk
, asoc
)) {
3911 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3913 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3916 /* Make sure that the FORWARD_TSN chunk has a valid length. */
3917 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3918 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3921 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3922 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3923 len
= ntohs(chunk
->chunk_hdr
->length
);
3924 len
-= sizeof(struct sctp_chunkhdr
);
3925 skb_pull(chunk
->skb
, len
);
3927 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3928 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __func__
, tsn
);
3930 /* The TSN is too high--silently discard the chunk and count on it
3931 * getting retransmitted later.
3933 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3936 /* Silently discard the chunk if stream-id is not valid */
3937 sctp_walk_fwdtsn(skip
, chunk
) {
3938 if (ntohs(skip
->stream
) >= asoc
->c
.sinit_max_instreams
)
3942 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3943 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3944 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3947 /* Go a head and force a SACK, since we are shutting down. */
3949 /* Implementor's Guide.
3951 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3952 * respond to each received packet containing one or more DATA chunk(s)
3953 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3955 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3956 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3957 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3958 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3960 return SCTP_DISPOSITION_CONSUME
;
3964 * SCTP-AUTH Section 6.3 Receiving authenticated chukns
3966 * The receiver MUST use the HMAC algorithm indicated in the HMAC
3967 * Identifier field. If this algorithm was not specified by the
3968 * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk
3969 * during association setup, the AUTH chunk and all chunks after it MUST
3970 * be discarded and an ERROR chunk SHOULD be sent with the error cause
3971 * defined in Section 4.1.
3973 * If an endpoint with no shared key receives a Shared Key Identifier
3974 * other than 0, it MUST silently discard all authenticated chunks. If
3975 * the endpoint has at least one endpoint pair shared key for the peer,
3976 * it MUST use the key specified by the Shared Key Identifier if a
3977 * key has been configured for that Shared Key Identifier. If no
3978 * endpoint pair shared key has been configured for that Shared Key
3979 * Identifier, all authenticated chunks MUST be silently discarded.
3981 * Verification Tag: 8.5 Verification Tag [Normal verification]
3983 * The return value is the disposition of the chunk.
3985 static sctp_ierror_t
sctp_sf_authenticate(struct net
*net
,
3986 const struct sctp_endpoint
*ep
,
3987 const struct sctp_association
*asoc
,
3988 const sctp_subtype_t type
,
3989 struct sctp_chunk
*chunk
)
3991 struct sctp_authhdr
*auth_hdr
;
3992 struct sctp_hmac
*hmac
;
3993 unsigned int sig_len
;
3998 /* Pull in the auth header, so we can do some more verification */
3999 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
4000 chunk
->subh
.auth_hdr
= auth_hdr
;
4001 skb_pull(chunk
->skb
, sizeof(struct sctp_authhdr
));
4003 /* Make sure that we support the HMAC algorithm from the auth
4006 if (!sctp_auth_asoc_verify_hmac_id(asoc
, auth_hdr
->hmac_id
))
4007 return SCTP_IERROR_AUTH_BAD_HMAC
;
4009 /* Make sure that the provided shared key identifier has been
4012 key_id
= ntohs(auth_hdr
->shkey_id
);
4013 if (key_id
!= asoc
->active_key_id
&& !sctp_auth_get_shkey(asoc
, key_id
))
4014 return SCTP_IERROR_AUTH_BAD_KEYID
;
4017 /* Make sure that the length of the signature matches what
4020 sig_len
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(sctp_auth_chunk_t
);
4021 hmac
= sctp_auth_get_hmac(ntohs(auth_hdr
->hmac_id
));
4022 if (sig_len
!= hmac
->hmac_len
)
4023 return SCTP_IERROR_PROTO_VIOLATION
;
4025 /* Now that we've done validation checks, we can compute and
4026 * verify the hmac. The steps involved are:
4027 * 1. Save the digest from the chunk.
4028 * 2. Zero out the digest in the chunk.
4029 * 3. Compute the new digest
4030 * 4. Compare saved and new digests.
4032 digest
= auth_hdr
->hmac
;
4033 skb_pull(chunk
->skb
, sig_len
);
4035 save_digest
= kmemdup(digest
, sig_len
, GFP_ATOMIC
);
4039 memset(digest
, 0, sig_len
);
4041 sctp_auth_calculate_hmac(asoc
, chunk
->skb
,
4042 (struct sctp_auth_chunk
*)chunk
->chunk_hdr
,
4045 /* Discard the packet if the digests do not match */
4046 if (memcmp(save_digest
, digest
, sig_len
)) {
4048 return SCTP_IERROR_BAD_SIG
;
4054 return SCTP_IERROR_NO_ERROR
;
4056 return SCTP_IERROR_NOMEM
;
4059 sctp_disposition_t
sctp_sf_eat_auth(struct net
*net
,
4060 const struct sctp_endpoint
*ep
,
4061 const struct sctp_association
*asoc
,
4062 const sctp_subtype_t type
,
4064 sctp_cmd_seq_t
*commands
)
4066 struct sctp_authhdr
*auth_hdr
;
4067 struct sctp_chunk
*chunk
= arg
;
4068 struct sctp_chunk
*err_chunk
;
4069 sctp_ierror_t error
;
4071 /* Make sure that the peer has AUTH capable */
4072 if (!asoc
->peer
.auth_capable
)
4073 return sctp_sf_unk_chunk(net
, ep
, asoc
, type
, arg
, commands
);
4075 if (!sctp_vtag_verify(chunk
, asoc
)) {
4076 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
4078 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4081 /* Make sure that the AUTH chunk has valid length. */
4082 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_auth_chunk
)))
4083 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4086 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
4087 error
= sctp_sf_authenticate(net
, ep
, asoc
, type
, chunk
);
4089 case SCTP_IERROR_AUTH_BAD_HMAC
:
4090 /* Generate the ERROR chunk and discard the rest
4093 err_chunk
= sctp_make_op_error(asoc
, chunk
,
4094 SCTP_ERROR_UNSUP_HMAC
,
4098 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4099 SCTP_CHUNK(err_chunk
));
4102 case SCTP_IERROR_AUTH_BAD_KEYID
:
4103 case SCTP_IERROR_BAD_SIG
:
4104 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4106 case SCTP_IERROR_PROTO_VIOLATION
:
4107 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4110 case SCTP_IERROR_NOMEM
:
4111 return SCTP_DISPOSITION_NOMEM
;
4113 default: /* Prevent gcc warnings */
4117 if (asoc
->active_key_id
!= ntohs(auth_hdr
->shkey_id
)) {
4118 struct sctp_ulpevent
*ev
;
4120 ev
= sctp_ulpevent_make_authkey(asoc
, ntohs(auth_hdr
->shkey_id
),
4121 SCTP_AUTH_NEWKEY
, GFP_ATOMIC
);
4126 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
4130 return SCTP_DISPOSITION_CONSUME
;
4134 * Process an unknown chunk.
4136 * Section: 3.2. Also, 2.1 in the implementor's guide.
4138 * Chunk Types are encoded such that the highest-order two bits specify
4139 * the action that must be taken if the processing endpoint does not
4140 * recognize the Chunk Type.
4142 * 00 - Stop processing this SCTP packet and discard it, do not process
4143 * any further chunks within it.
4145 * 01 - Stop processing this SCTP packet and discard it, do not process
4146 * any further chunks within it, and report the unrecognized
4147 * chunk in an 'Unrecognized Chunk Type'.
4149 * 10 - Skip this chunk and continue processing.
4151 * 11 - Skip this chunk and continue processing, but report in an ERROR
4152 * Chunk using the 'Unrecognized Chunk Type' cause of error.
4154 * The return value is the disposition of the chunk.
4156 sctp_disposition_t
sctp_sf_unk_chunk(struct net
*net
,
4157 const struct sctp_endpoint
*ep
,
4158 const struct sctp_association
*asoc
,
4159 const sctp_subtype_t type
,
4161 sctp_cmd_seq_t
*commands
)
4163 struct sctp_chunk
*unk_chunk
= arg
;
4164 struct sctp_chunk
*err_chunk
;
4165 sctp_chunkhdr_t
*hdr
;
4167 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type
.chunk
);
4169 if (!sctp_vtag_verify(unk_chunk
, asoc
))
4170 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4172 /* Make sure that the chunk has a valid length.
4173 * Since we don't know the chunk type, we use a general
4174 * chunkhdr structure to make a comparison.
4176 if (!sctp_chunk_length_valid(unk_chunk
, sizeof(sctp_chunkhdr_t
)))
4177 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4180 switch (type
.chunk
& SCTP_CID_ACTION_MASK
) {
4181 case SCTP_CID_ACTION_DISCARD
:
4182 /* Discard the packet. */
4183 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4185 case SCTP_CID_ACTION_DISCARD_ERR
:
4186 /* Generate an ERROR chunk as response. */
4187 hdr
= unk_chunk
->chunk_hdr
;
4188 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4189 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4190 WORD_ROUND(ntohs(hdr
->length
)),
4193 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4194 SCTP_CHUNK(err_chunk
));
4197 /* Discard the packet. */
4198 sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4199 return SCTP_DISPOSITION_CONSUME
;
4201 case SCTP_CID_ACTION_SKIP
:
4202 /* Skip the chunk. */
4203 return SCTP_DISPOSITION_DISCARD
;
4205 case SCTP_CID_ACTION_SKIP_ERR
:
4206 /* Generate an ERROR chunk as response. */
4207 hdr
= unk_chunk
->chunk_hdr
;
4208 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4209 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4210 WORD_ROUND(ntohs(hdr
->length
)),
4213 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4214 SCTP_CHUNK(err_chunk
));
4216 /* Skip the chunk. */
4217 return SCTP_DISPOSITION_CONSUME
;
4223 return SCTP_DISPOSITION_DISCARD
;
4227 * Discard the chunk.
4229 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
4230 * [Too numerous to mention...]
4231 * Verification Tag: No verification needed.
4233 * (endpoint, asoc, chunk)
4236 * (asoc, reply_msg, msg_up, timers, counters)
4238 * The return value is the disposition of the chunk.
4240 sctp_disposition_t
sctp_sf_discard_chunk(struct net
*net
,
4241 const struct sctp_endpoint
*ep
,
4242 const struct sctp_association
*asoc
,
4243 const sctp_subtype_t type
,
4245 sctp_cmd_seq_t
*commands
)
4247 struct sctp_chunk
*chunk
= arg
;
4249 /* Make sure that the chunk has a valid length.
4250 * Since we don't know the chunk type, we use a general
4251 * chunkhdr structure to make a comparison.
4253 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
4254 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4257 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type
.chunk
);
4258 return SCTP_DISPOSITION_DISCARD
;
4262 * Discard the whole packet.
4266 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
4267 * silently discard the OOTB packet and take no further action.
4269 * Verification Tag: No verification necessary
4272 * (endpoint, asoc, chunk)
4275 * (asoc, reply_msg, msg_up, timers, counters)
4277 * The return value is the disposition of the chunk.
4279 sctp_disposition_t
sctp_sf_pdiscard(struct net
*net
,
4280 const struct sctp_endpoint
*ep
,
4281 const struct sctp_association
*asoc
,
4282 const sctp_subtype_t type
,
4284 sctp_cmd_seq_t
*commands
)
4286 SCTP_INC_STATS(net
, SCTP_MIB_IN_PKT_DISCARDS
);
4287 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
4289 return SCTP_DISPOSITION_CONSUME
;
4294 * The other end is violating protocol.
4296 * Section: Not specified
4297 * Verification Tag: Not specified
4299 * (endpoint, asoc, chunk)
4302 * (asoc, reply_msg, msg_up, timers, counters)
4304 * We simply tag the chunk as a violation. The state machine will log
4305 * the violation and continue.
4307 sctp_disposition_t
sctp_sf_violation(struct net
*net
,
4308 const struct sctp_endpoint
*ep
,
4309 const struct sctp_association
*asoc
,
4310 const sctp_subtype_t type
,
4312 sctp_cmd_seq_t
*commands
)
4314 struct sctp_chunk
*chunk
= arg
;
4316 /* Make sure that the chunk has a valid length. */
4317 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
4318 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4321 return SCTP_DISPOSITION_VIOLATION
;
4325 * Common function to handle a protocol violation.
4327 static sctp_disposition_t
sctp_sf_abort_violation(
4329 const struct sctp_endpoint
*ep
,
4330 const struct sctp_association
*asoc
,
4332 sctp_cmd_seq_t
*commands
,
4333 const __u8
*payload
,
4334 const size_t paylen
)
4336 struct sctp_packet
*packet
= NULL
;
4337 struct sctp_chunk
*chunk
= arg
;
4338 struct sctp_chunk
*abort
= NULL
;
4340 /* SCTP-AUTH, Section 6.3:
4341 * It should be noted that if the receiver wants to tear
4342 * down an association in an authenticated way only, the
4343 * handling of malformed packets should not result in
4344 * tearing down the association.
4346 * This means that if we only want to abort associations
4347 * in an authenticated way (i.e AUTH+ABORT), then we
4348 * can't destroy this association just because the packet
4351 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4354 /* Make the abort chunk. */
4355 abort
= sctp_make_abort_violation(asoc
, chunk
, payload
, paylen
);
4360 /* Treat INIT-ACK as a special case during COOKIE-WAIT. */
4361 if (chunk
->chunk_hdr
->type
== SCTP_CID_INIT_ACK
&&
4362 !asoc
->peer
.i
.init_tag
) {
4363 sctp_initack_chunk_t
*initack
;
4365 initack
= (sctp_initack_chunk_t
*)chunk
->chunk_hdr
;
4366 if (!sctp_chunk_length_valid(chunk
,
4367 sizeof(sctp_initack_chunk_t
)))
4368 abort
->chunk_hdr
->flags
|= SCTP_CHUNK_FLAG_T
;
4370 unsigned int inittag
;
4372 inittag
= ntohl(initack
->init_hdr
.init_tag
);
4373 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_INITTAG
,
4378 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4379 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4381 if (asoc
->state
<= SCTP_STATE_COOKIE_ECHOED
) {
4382 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4383 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4384 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4385 SCTP_ERROR(ECONNREFUSED
));
4386 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4387 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4389 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4390 SCTP_ERROR(ECONNABORTED
));
4391 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4392 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4393 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4396 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
4401 if (sctp_test_T_bit(abort
))
4402 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
4404 abort
->skb
->sk
= ep
->base
.sk
;
4406 sctp_packet_append_chunk(packet
, abort
);
4408 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
4409 SCTP_PACKET(packet
));
4411 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4414 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4417 sctp_sf_pdiscard(net
, ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4418 return SCTP_DISPOSITION_ABORT
;
4421 sctp_chunk_free(abort
);
4423 return SCTP_DISPOSITION_NOMEM
;
4427 * Handle a protocol violation when the chunk length is invalid.
4428 * "Invalid" length is identified as smaller than the minimal length a
4429 * given chunk can be. For example, a SACK chunk has invalid length
4430 * if its length is set to be smaller than the size of sctp_sack_chunk_t.
4432 * We inform the other end by sending an ABORT with a Protocol Violation
4435 * Section: Not specified
4436 * Verification Tag: Nothing to do
4438 * (endpoint, asoc, chunk)
4441 * (reply_msg, msg_up, counters)
4443 * Generate an ABORT chunk and terminate the association.
4445 static sctp_disposition_t
sctp_sf_violation_chunklen(
4447 const struct sctp_endpoint
*ep
,
4448 const struct sctp_association
*asoc
,
4449 const sctp_subtype_t type
,
4451 sctp_cmd_seq_t
*commands
)
4453 static const char err_str
[]="The following chunk had invalid length:";
4455 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4460 * Handle a protocol violation when the parameter length is invalid.
4461 * If the length is smaller than the minimum length of a given parameter,
4462 * or accumulated length in multi parameters exceeds the end of the chunk,
4463 * the length is considered as invalid.
4465 static sctp_disposition_t
sctp_sf_violation_paramlen(
4467 const struct sctp_endpoint
*ep
,
4468 const struct sctp_association
*asoc
,
4469 const sctp_subtype_t type
,
4470 void *arg
, void *ext
,
4471 sctp_cmd_seq_t
*commands
)
4473 struct sctp_chunk
*chunk
= arg
;
4474 struct sctp_paramhdr
*param
= ext
;
4475 struct sctp_chunk
*abort
= NULL
;
4477 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4480 /* Make the abort chunk. */
4481 abort
= sctp_make_violation_paramlen(asoc
, chunk
, param
);
4485 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4486 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4488 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4489 SCTP_ERROR(ECONNABORTED
));
4490 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4491 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4492 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4493 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4496 sctp_sf_pdiscard(net
, ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4497 return SCTP_DISPOSITION_ABORT
;
4499 return SCTP_DISPOSITION_NOMEM
;
4502 /* Handle a protocol violation when the peer trying to advance the
4503 * cumulative tsn ack to a point beyond the max tsn currently sent.
4505 * We inform the other end by sending an ABORT with a Protocol Violation
4508 static sctp_disposition_t
sctp_sf_violation_ctsn(
4510 const struct sctp_endpoint
*ep
,
4511 const struct sctp_association
*asoc
,
4512 const sctp_subtype_t type
,
4514 sctp_cmd_seq_t
*commands
)
4516 static const char err_str
[]="The cumulative tsn ack beyond the max tsn currently sent:";
4518 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4522 /* Handle protocol violation of an invalid chunk bundling. For example,
4523 * when we have an association and we receive bundled INIT-ACK, or
4524 * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle"
4525 * statement from the specs. Additionally, there might be an attacker
4526 * on the path and we may not want to continue this communication.
4528 static sctp_disposition_t
sctp_sf_violation_chunk(
4530 const struct sctp_endpoint
*ep
,
4531 const struct sctp_association
*asoc
,
4532 const sctp_subtype_t type
,
4534 sctp_cmd_seq_t
*commands
)
4536 static const char err_str
[]="The following chunk violates protocol:";
4539 return sctp_sf_violation(net
, ep
, asoc
, type
, arg
, commands
);
4541 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4544 /***************************************************************************
4545 * These are the state functions for handling primitive (Section 10) events.
4546 ***************************************************************************/
4548 * sctp_sf_do_prm_asoc
4550 * Section: 10.1 ULP-to-SCTP
4553 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
4554 * outbound stream count)
4555 * -> association id [,destination transport addr list] [,outbound stream
4558 * This primitive allows the upper layer to initiate an association to a
4559 * specific peer endpoint.
4561 * The peer endpoint shall be specified by one of the transport addresses
4562 * which defines the endpoint (see Section 1.4). If the local SCTP
4563 * instance has not been initialized, the ASSOCIATE is considered an
4565 * [This is not relevant for the kernel implementation since we do all
4566 * initialization at boot time. It we hadn't initialized we wouldn't
4567 * get anywhere near this code.]
4569 * An association id, which is a local handle to the SCTP association,
4570 * will be returned on successful establishment of the association. If
4571 * SCTP is not able to open an SCTP association with the peer endpoint,
4572 * an error is returned.
4573 * [In the kernel implementation, the struct sctp_association needs to
4574 * be created BEFORE causing this primitive to run.]
4576 * Other association parameters may be returned, including the
4577 * complete destination transport addresses of the peer as well as the
4578 * outbound stream count of the local endpoint. One of the transport
4579 * address from the returned destination addresses will be selected by
4580 * the local endpoint as default primary path for sending SCTP packets
4581 * to this peer. The returned "destination transport addr list" can
4582 * be used by the ULP to change the default primary path or to force
4583 * sending a packet to a specific transport address. [All of this
4584 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
4587 * Mandatory attributes:
4589 * o local SCTP instance name - obtained from the INITIALIZE operation.
4590 * [This is the argument asoc.]
4591 * o destination transport addr - specified as one of the transport
4592 * addresses of the peer endpoint with which the association is to be
4594 * [This is asoc->peer.active_path.]
4595 * o outbound stream count - the number of outbound streams the ULP
4596 * would like to open towards this peer endpoint.
4597 * [BUG: This is not currently implemented.]
4598 * Optional attributes:
4602 * The return value is a disposition.
4604 sctp_disposition_t
sctp_sf_do_prm_asoc(struct net
*net
,
4605 const struct sctp_endpoint
*ep
,
4606 const struct sctp_association
*asoc
,
4607 const sctp_subtype_t type
,
4609 sctp_cmd_seq_t
*commands
)
4611 struct sctp_chunk
*repl
;
4612 struct sctp_association
* my_asoc
;
4614 /* The comment below says that we enter COOKIE-WAIT AFTER
4615 * sending the INIT, but that doesn't actually work in our
4618 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4619 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
4621 /* RFC 2960 5.1 Normal Establishment of an Association
4623 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
4624 * must provide its Verification Tag (Tag_A) in the Initiate
4625 * Tag field. Tag_A SHOULD be a random number in the range of
4626 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
4629 repl
= sctp_make_init(asoc
, &asoc
->base
.bind_addr
, GFP_ATOMIC
, 0);
4633 /* Cast away the const modifier, as we want to just
4634 * rerun it through as a sideffect.
4636 my_asoc
= (struct sctp_association
*)asoc
;
4637 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(my_asoc
));
4639 /* Choose transport for INIT. */
4640 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
4643 /* After sending the INIT, "A" starts the T1-init timer and
4644 * enters the COOKIE-WAIT state.
4646 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4647 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4648 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
4649 return SCTP_DISPOSITION_CONSUME
;
4652 return SCTP_DISPOSITION_NOMEM
;
4656 * Process the SEND primitive.
4658 * Section: 10.1 ULP-to-SCTP
4661 * Format: SEND(association id, buffer address, byte count [,context]
4662 * [,stream id] [,life time] [,destination transport address]
4663 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
4666 * This is the main method to send user data via SCTP.
4668 * Mandatory attributes:
4670 * o association id - local handle to the SCTP association
4672 * o buffer address - the location where the user message to be
4673 * transmitted is stored;
4675 * o byte count - The size of the user data in number of bytes;
4677 * Optional attributes:
4679 * o context - an optional 32 bit integer that will be carried in the
4680 * sending failure notification to the ULP if the transportation of
4681 * this User Message fails.
4683 * o stream id - to indicate which stream to send the data on. If not
4684 * specified, stream 0 will be used.
4686 * o life time - specifies the life time of the user data. The user data
4687 * will not be sent by SCTP after the life time expires. This
4688 * parameter can be used to avoid efforts to transmit stale
4689 * user messages. SCTP notifies the ULP if the data cannot be
4690 * initiated to transport (i.e. sent to the destination via SCTP's
4691 * send primitive) within the life time variable. However, the
4692 * user data will be transmitted if SCTP has attempted to transmit a
4693 * chunk before the life time expired.
4695 * o destination transport address - specified as one of the destination
4696 * transport addresses of the peer endpoint to which this packet
4697 * should be sent. Whenever possible, SCTP should use this destination
4698 * transport address for sending the packets, instead of the current
4701 * o unorder flag - this flag, if present, indicates that the user
4702 * would like the data delivered in an unordered fashion to the peer
4703 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
4706 * o no-bundle flag - instructs SCTP not to bundle this user data with
4707 * other outbound DATA chunks. SCTP MAY still bundle even when
4708 * this flag is present, when faced with network congestion.
4710 * o payload protocol-id - A 32 bit unsigned integer that is to be
4711 * passed to the peer indicating the type of payload protocol data
4712 * being transmitted. This value is passed as opaque data by SCTP.
4714 * The return value is the disposition.
4716 sctp_disposition_t
sctp_sf_do_prm_send(struct net
*net
,
4717 const struct sctp_endpoint
*ep
,
4718 const struct sctp_association
*asoc
,
4719 const sctp_subtype_t type
,
4721 sctp_cmd_seq_t
*commands
)
4723 struct sctp_datamsg
*msg
= arg
;
4725 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_MSG
, SCTP_DATAMSG(msg
));
4726 return SCTP_DISPOSITION_CONSUME
;
4730 * Process the SHUTDOWN primitive.
4735 * Format: SHUTDOWN(association id)
4738 * Gracefully closes an association. Any locally queued user data
4739 * will be delivered to the peer. The association will be terminated only
4740 * after the peer acknowledges all the SCTP packets sent. A success code
4741 * will be returned on successful termination of the association. If
4742 * attempting to terminate the association results in a failure, an error
4743 * code shall be returned.
4745 * Mandatory attributes:
4747 * o association id - local handle to the SCTP association
4749 * Optional attributes:
4753 * The return value is the disposition.
4755 sctp_disposition_t
sctp_sf_do_9_2_prm_shutdown(
4757 const struct sctp_endpoint
*ep
,
4758 const struct sctp_association
*asoc
,
4759 const sctp_subtype_t type
,
4761 sctp_cmd_seq_t
*commands
)
4765 /* From 9.2 Shutdown of an Association
4766 * Upon receipt of the SHUTDOWN primitive from its upper
4767 * layer, the endpoint enters SHUTDOWN-PENDING state and
4768 * remains there until all outstanding data has been
4769 * acknowledged by its peer. The endpoint accepts no new data
4770 * from its upper layer, but retransmits data to the far end
4771 * if necessary to fill gaps.
4773 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4774 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
4776 disposition
= SCTP_DISPOSITION_CONSUME
;
4777 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
4778 disposition
= sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
, type
,
4785 * Process the ABORT primitive.
4790 * Format: Abort(association id [, cause code])
4793 * Ungracefully closes an association. Any locally queued user data
4794 * will be discarded and an ABORT chunk is sent to the peer. A success code
4795 * will be returned on successful abortion of the association. If
4796 * attempting to abort the association results in a failure, an error
4797 * code shall be returned.
4799 * Mandatory attributes:
4801 * o association id - local handle to the SCTP association
4803 * Optional attributes:
4805 * o cause code - reason of the abort to be passed to the peer
4809 * The return value is the disposition.
4811 sctp_disposition_t
sctp_sf_do_9_1_prm_abort(
4813 const struct sctp_endpoint
*ep
,
4814 const struct sctp_association
*asoc
,
4815 const sctp_subtype_t type
,
4817 sctp_cmd_seq_t
*commands
)
4819 /* From 9.1 Abort of an Association
4820 * Upon receipt of the ABORT primitive from its upper
4821 * layer, the endpoint enters CLOSED state and
4822 * discard all outstanding data has been
4823 * acknowledged by its peer. The endpoint accepts no new data
4824 * from its upper layer, but retransmits data to the far end
4825 * if necessary to fill gaps.
4827 struct sctp_chunk
*abort
= arg
;
4828 sctp_disposition_t retval
;
4830 retval
= SCTP_DISPOSITION_CONSUME
;
4832 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4834 /* Even if we can't send the ABORT due to low memory delete the
4835 * TCB. This is a departure from our typical NOMEM handling.
4838 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4839 SCTP_ERROR(ECONNABORTED
));
4840 /* Delete the established association. */
4841 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4842 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4844 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4845 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4850 /* We tried an illegal operation on an association which is closed. */
4851 sctp_disposition_t
sctp_sf_error_closed(struct net
*net
,
4852 const struct sctp_endpoint
*ep
,
4853 const struct sctp_association
*asoc
,
4854 const sctp_subtype_t type
,
4856 sctp_cmd_seq_t
*commands
)
4858 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
, SCTP_ERROR(-EINVAL
));
4859 return SCTP_DISPOSITION_CONSUME
;
4862 /* We tried an illegal operation on an association which is shutting
4865 sctp_disposition_t
sctp_sf_error_shutdown(struct net
*net
,
4866 const struct sctp_endpoint
*ep
,
4867 const struct sctp_association
*asoc
,
4868 const sctp_subtype_t type
,
4870 sctp_cmd_seq_t
*commands
)
4872 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
,
4873 SCTP_ERROR(-ESHUTDOWN
));
4874 return SCTP_DISPOSITION_CONSUME
;
4878 * sctp_cookie_wait_prm_shutdown
4880 * Section: 4 Note: 2
4885 * The RFC does not explicitly address this issue, but is the route through the
4886 * state table when someone issues a shutdown while in COOKIE_WAIT state.
4891 sctp_disposition_t
sctp_sf_cookie_wait_prm_shutdown(
4893 const struct sctp_endpoint
*ep
,
4894 const struct sctp_association
*asoc
,
4895 const sctp_subtype_t type
,
4897 sctp_cmd_seq_t
*commands
)
4899 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4900 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4902 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4903 SCTP_STATE(SCTP_STATE_CLOSED
));
4905 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
4907 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
4909 return SCTP_DISPOSITION_DELETE_TCB
;
4913 * sctp_cookie_echoed_prm_shutdown
4915 * Section: 4 Note: 2
4920 * The RFC does not explcitly address this issue, but is the route through the
4921 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
4926 sctp_disposition_t
sctp_sf_cookie_echoed_prm_shutdown(
4928 const struct sctp_endpoint
*ep
,
4929 const struct sctp_association
*asoc
,
4930 const sctp_subtype_t type
,
4931 void *arg
, sctp_cmd_seq_t
*commands
)
4933 /* There is a single T1 timer, so we should be able to use
4934 * common function with the COOKIE-WAIT state.
4936 return sctp_sf_cookie_wait_prm_shutdown(net
, ep
, asoc
, type
, arg
, commands
);
4940 * sctp_sf_cookie_wait_prm_abort
4942 * Section: 4 Note: 2
4947 * The RFC does not explicitly address this issue, but is the route through the
4948 * state table when someone issues an abort while in COOKIE_WAIT state.
4953 sctp_disposition_t
sctp_sf_cookie_wait_prm_abort(
4955 const struct sctp_endpoint
*ep
,
4956 const struct sctp_association
*asoc
,
4957 const sctp_subtype_t type
,
4959 sctp_cmd_seq_t
*commands
)
4961 struct sctp_chunk
*abort
= arg
;
4962 sctp_disposition_t retval
;
4964 /* Stop T1-init timer */
4965 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4966 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4967 retval
= SCTP_DISPOSITION_CONSUME
;
4969 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4971 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4972 SCTP_STATE(SCTP_STATE_CLOSED
));
4974 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4976 /* Even if we can't send the ABORT due to low memory delete the
4977 * TCB. This is a departure from our typical NOMEM handling.
4980 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4981 SCTP_ERROR(ECONNREFUSED
));
4982 /* Delete the established association. */
4983 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4984 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4990 * sctp_sf_cookie_echoed_prm_abort
4992 * Section: 4 Note: 3
4997 * The RFC does not explcitly address this issue, but is the route through the
4998 * state table when someone issues an abort while in COOKIE_ECHOED state.
5003 sctp_disposition_t
sctp_sf_cookie_echoed_prm_abort(
5005 const struct sctp_endpoint
*ep
,
5006 const struct sctp_association
*asoc
,
5007 const sctp_subtype_t type
,
5009 sctp_cmd_seq_t
*commands
)
5011 /* There is a single T1 timer, so we should be able to use
5012 * common function with the COOKIE-WAIT state.
5014 return sctp_sf_cookie_wait_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5018 * sctp_sf_shutdown_pending_prm_abort
5023 * The RFC does not explicitly address this issue, but is the route through the
5024 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
5029 sctp_disposition_t
sctp_sf_shutdown_pending_prm_abort(
5031 const struct sctp_endpoint
*ep
,
5032 const struct sctp_association
*asoc
,
5033 const sctp_subtype_t type
,
5035 sctp_cmd_seq_t
*commands
)
5037 /* Stop the T5-shutdown guard timer. */
5038 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5039 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5041 return sctp_sf_do_9_1_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5045 * sctp_sf_shutdown_sent_prm_abort
5050 * The RFC does not explicitly address this issue, but is the route through the
5051 * state table when someone issues an abort while in SHUTDOWN-SENT state.
5056 sctp_disposition_t
sctp_sf_shutdown_sent_prm_abort(
5058 const struct sctp_endpoint
*ep
,
5059 const struct sctp_association
*asoc
,
5060 const sctp_subtype_t type
,
5062 sctp_cmd_seq_t
*commands
)
5064 /* Stop the T2-shutdown timer. */
5065 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5066 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5068 /* Stop the T5-shutdown guard timer. */
5069 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5070 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5072 return sctp_sf_do_9_1_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5076 * sctp_sf_cookie_echoed_prm_abort
5081 * The RFC does not explcitly address this issue, but is the route through the
5082 * state table when someone issues an abort while in COOKIE_ECHOED state.
5087 sctp_disposition_t
sctp_sf_shutdown_ack_sent_prm_abort(
5089 const struct sctp_endpoint
*ep
,
5090 const struct sctp_association
*asoc
,
5091 const sctp_subtype_t type
,
5093 sctp_cmd_seq_t
*commands
)
5095 /* The same T2 timer, so we should be able to use
5096 * common function with the SHUTDOWN-SENT state.
5098 return sctp_sf_shutdown_sent_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5102 * Process the REQUESTHEARTBEAT primitive
5105 * J) Request Heartbeat
5107 * Format: REQUESTHEARTBEAT(association id, destination transport address)
5111 * Instructs the local endpoint to perform a HeartBeat on the specified
5112 * destination transport address of the given association. The returned
5113 * result should indicate whether the transmission of the HEARTBEAT
5114 * chunk to the destination address is successful.
5116 * Mandatory attributes:
5118 * o association id - local handle to the SCTP association
5120 * o destination transport address - the transport address of the
5121 * association on which a heartbeat should be issued.
5123 sctp_disposition_t
sctp_sf_do_prm_requestheartbeat(
5125 const struct sctp_endpoint
*ep
,
5126 const struct sctp_association
*asoc
,
5127 const sctp_subtype_t type
,
5129 sctp_cmd_seq_t
*commands
)
5131 if (SCTP_DISPOSITION_NOMEM
== sctp_sf_heartbeat(ep
, asoc
, type
,
5132 (struct sctp_transport
*)arg
, commands
))
5133 return SCTP_DISPOSITION_NOMEM
;
5136 * RFC 2960 (bis), section 8.3
5138 * D) Request an on-demand HEARTBEAT on a specific destination
5139 * transport address of a given association.
5141 * The endpoint should increment the respective error counter of
5142 * the destination transport address each time a HEARTBEAT is sent
5143 * to that address and not acknowledged within one RTO.
5146 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
5147 SCTP_TRANSPORT(arg
));
5148 return SCTP_DISPOSITION_CONSUME
;
5152 * ADDIP Section 4.1 ASCONF Chunk Procedures
5153 * When an endpoint has an ASCONF signaled change to be sent to the
5154 * remote endpoint it should do A1 to A9
5156 sctp_disposition_t
sctp_sf_do_prm_asconf(struct net
*net
,
5157 const struct sctp_endpoint
*ep
,
5158 const struct sctp_association
*asoc
,
5159 const sctp_subtype_t type
,
5161 sctp_cmd_seq_t
*commands
)
5163 struct sctp_chunk
*chunk
= arg
;
5165 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5166 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5167 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5168 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
5169 return SCTP_DISPOSITION_CONSUME
;
5173 * Ignore the primitive event
5175 * The return value is the disposition of the primitive.
5177 sctp_disposition_t
sctp_sf_ignore_primitive(
5179 const struct sctp_endpoint
*ep
,
5180 const struct sctp_association
*asoc
,
5181 const sctp_subtype_t type
,
5183 sctp_cmd_seq_t
*commands
)
5185 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type
.primitive
);
5186 return SCTP_DISPOSITION_DISCARD
;
5189 /***************************************************************************
5190 * These are the state functions for the OTHER events.
5191 ***************************************************************************/
5194 * When the SCTP stack has no more user data to send or retransmit, this
5195 * notification is given to the user. Also, at the time when a user app
5196 * subscribes to this event, if there is no data to be sent or
5197 * retransmit, the stack will immediately send up this notification.
5199 sctp_disposition_t
sctp_sf_do_no_pending_tsn(
5201 const struct sctp_endpoint
*ep
,
5202 const struct sctp_association
*asoc
,
5203 const sctp_subtype_t type
,
5205 sctp_cmd_seq_t
*commands
)
5207 struct sctp_ulpevent
*event
;
5209 event
= sctp_ulpevent_make_sender_dry_event(asoc
, GFP_ATOMIC
);
5211 return SCTP_DISPOSITION_NOMEM
;
5213 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(event
));
5215 return SCTP_DISPOSITION_CONSUME
;
5219 * Start the shutdown negotiation.
5222 * Once all its outstanding data has been acknowledged, the endpoint
5223 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
5224 * TSN Ack field the last sequential TSN it has received from the peer.
5225 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
5226 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
5227 * with the updated last sequential TSN received from its peer.
5229 * The return value is the disposition.
5231 sctp_disposition_t
sctp_sf_do_9_2_start_shutdown(
5233 const struct sctp_endpoint
*ep
,
5234 const struct sctp_association
*asoc
,
5235 const sctp_subtype_t type
,
5237 sctp_cmd_seq_t
*commands
)
5239 struct sctp_chunk
*reply
;
5241 /* Once all its outstanding data has been acknowledged, the
5242 * endpoint shall send a SHUTDOWN chunk to its peer including
5243 * in the Cumulative TSN Ack field the last sequential TSN it
5244 * has received from the peer.
5246 reply
= sctp_make_shutdown(asoc
, NULL
);
5250 /* Set the transport for the SHUTDOWN chunk and the timeout for the
5251 * T2-shutdown timer.
5253 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5255 /* It shall then start the T2-shutdown timer */
5256 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5257 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5259 /* RFC 4960 Section 9.2
5260 * The sender of the SHUTDOWN MAY also start an overall guard timer
5261 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5263 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5264 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5266 if (asoc
->autoclose
)
5267 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5268 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5270 /* and enter the SHUTDOWN-SENT state. */
5271 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5272 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT
));
5274 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5276 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5279 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5281 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5283 return SCTP_DISPOSITION_CONSUME
;
5286 return SCTP_DISPOSITION_NOMEM
;
5290 * Generate a SHUTDOWN ACK now that everything is SACK'd.
5294 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5295 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
5296 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
5297 * endpoint must re-send the SHUTDOWN ACK.
5299 * The return value is the disposition.
5301 sctp_disposition_t
sctp_sf_do_9_2_shutdown_ack(
5303 const struct sctp_endpoint
*ep
,
5304 const struct sctp_association
*asoc
,
5305 const sctp_subtype_t type
,
5307 sctp_cmd_seq_t
*commands
)
5309 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
5310 struct sctp_chunk
*reply
;
5312 /* There are 2 ways of getting here:
5313 * 1) called in response to a SHUTDOWN chunk
5314 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
5316 * For the case (2), the arg parameter is set to NULL. We need
5317 * to check that we have a chunk before accessing it's fields.
5320 if (!sctp_vtag_verify(chunk
, asoc
))
5321 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
5323 /* Make sure that the SHUTDOWN chunk has a valid length. */
5324 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_shutdown_chunk_t
)))
5325 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
5329 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5330 * shall send a SHUTDOWN ACK ...
5332 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
5336 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
5337 * the T2-shutdown timer.
5339 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5341 /* and start/restart a T2-shutdown timer of its own, */
5342 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5343 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5345 if (asoc
->autoclose
)
5346 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5347 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5349 /* Enter the SHUTDOWN-ACK-SENT state. */
5350 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5351 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT
));
5353 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5355 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5358 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5360 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5362 return SCTP_DISPOSITION_CONSUME
;
5365 return SCTP_DISPOSITION_NOMEM
;
5369 * Ignore the event defined as other
5371 * The return value is the disposition of the event.
5373 sctp_disposition_t
sctp_sf_ignore_other(struct net
*net
,
5374 const struct sctp_endpoint
*ep
,
5375 const struct sctp_association
*asoc
,
5376 const sctp_subtype_t type
,
5378 sctp_cmd_seq_t
*commands
)
5380 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type
.other
);
5381 return SCTP_DISPOSITION_DISCARD
;
5384 /************************************************************
5385 * These are the state functions for handling timeout events.
5386 ************************************************************/
5391 * Section: 6.3.3 Handle T3-rtx Expiration
5393 * Whenever the retransmission timer T3-rtx expires for a destination
5394 * address, do the following:
5397 * The return value is the disposition of the chunk.
5399 sctp_disposition_t
sctp_sf_do_6_3_3_rtx(struct net
*net
,
5400 const struct sctp_endpoint
*ep
,
5401 const struct sctp_association
*asoc
,
5402 const sctp_subtype_t type
,
5404 sctp_cmd_seq_t
*commands
)
5406 struct sctp_transport
*transport
= arg
;
5408 SCTP_INC_STATS(net
, SCTP_MIB_T3_RTX_EXPIREDS
);
5410 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5411 if (asoc
->state
== SCTP_STATE_SHUTDOWN_PENDING
) {
5413 * We are here likely because the receiver had its rwnd
5414 * closed for a while and we have not been able to
5415 * transmit the locally queued data within the maximum
5416 * retransmission attempts limit. Start the T5
5417 * shutdown guard timer to give the receiver one last
5418 * chance and some additional time to recover before
5421 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START_ONCE
,
5422 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5424 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5425 SCTP_ERROR(ETIMEDOUT
));
5426 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5427 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5428 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5429 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5430 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5431 return SCTP_DISPOSITION_DELETE_TCB
;
5435 /* E1) For the destination address for which the timer
5436 * expires, adjust its ssthresh with rules defined in Section
5437 * 7.2.3 and set the cwnd <- MTU.
5440 /* E2) For the destination address for which the timer
5441 * expires, set RTO <- RTO * 2 ("back off the timer"). The
5442 * maximum value discussed in rule C7 above (RTO.max) may be
5443 * used to provide an upper bound to this doubling operation.
5446 /* E3) Determine how many of the earliest (i.e., lowest TSN)
5447 * outstanding DATA chunks for the address for which the
5448 * T3-rtx has expired will fit into a single packet, subject
5449 * to the MTU constraint for the path corresponding to the
5450 * destination transport address to which the retransmission
5451 * is being sent (this may be different from the address for
5452 * which the timer expires [see Section 6.4]). Call this
5453 * value K. Bundle and retransmit those K DATA chunks in a
5454 * single packet to the destination endpoint.
5456 * Note: Any DATA chunks that were sent to the address for
5457 * which the T3-rtx timer expired but did not fit in one MTU
5458 * (rule E3 above), should be marked for retransmission and
5459 * sent as soon as cwnd allows (normally when a SACK arrives).
5462 /* Do some failure management (Section 8.2). */
5463 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
5465 /* NB: Rules E4 and F1 are implicit in R1. */
5466 sctp_add_cmd_sf(commands
, SCTP_CMD_RETRAN
, SCTP_TRANSPORT(transport
));
5468 return SCTP_DISPOSITION_CONSUME
;
5472 * Generate delayed SACK on timeout
5474 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
5476 * The guidelines on delayed acknowledgement algorithm specified in
5477 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
5478 * acknowledgement SHOULD be generated for at least every second packet
5479 * (not every second DATA chunk) received, and SHOULD be generated
5480 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
5481 * some situations it may be beneficial for an SCTP transmitter to be
5482 * more conservative than the algorithms detailed in this document
5483 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
5484 * the following algorithms allow.
5486 sctp_disposition_t
sctp_sf_do_6_2_sack(struct net
*net
,
5487 const struct sctp_endpoint
*ep
,
5488 const struct sctp_association
*asoc
,
5489 const sctp_subtype_t type
,
5491 sctp_cmd_seq_t
*commands
)
5493 SCTP_INC_STATS(net
, SCTP_MIB_DELAY_SACK_EXPIREDS
);
5494 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
5495 return SCTP_DISPOSITION_CONSUME
;
5499 * sctp_sf_t1_init_timer_expire
5501 * Section: 4 Note: 2
5506 * RFC 2960 Section 4 Notes
5507 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
5508 * and re-start the T1-init timer without changing state. This MUST
5509 * be repeated up to 'Max.Init.Retransmits' times. After that, the
5510 * endpoint MUST abort the initialization process and report the
5511 * error to SCTP user.
5517 sctp_disposition_t
sctp_sf_t1_init_timer_expire(struct net
*net
,
5518 const struct sctp_endpoint
*ep
,
5519 const struct sctp_association
*asoc
,
5520 const sctp_subtype_t type
,
5522 sctp_cmd_seq_t
*commands
)
5524 struct sctp_chunk
*repl
= NULL
;
5525 struct sctp_bind_addr
*bp
;
5526 int attempts
= asoc
->init_err_counter
+ 1;
5528 SCTP_DEBUG_PRINTK("Timer T1 expired (INIT).\n");
5529 SCTP_INC_STATS(net
, SCTP_MIB_T1_INIT_EXPIREDS
);
5531 if (attempts
<= asoc
->max_init_attempts
) {
5532 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
5533 repl
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, 0);
5535 return SCTP_DISPOSITION_NOMEM
;
5537 /* Choose transport for INIT. */
5538 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5541 /* Issue a sideeffect to do the needed accounting. */
5542 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_RESTART
,
5543 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5545 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5547 SCTP_DEBUG_PRINTK("Giving up on INIT, attempts: %d"
5548 " max_init_attempts: %d\n",
5549 attempts
, asoc
->max_init_attempts
);
5550 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5551 SCTP_ERROR(ETIMEDOUT
));
5552 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5553 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5554 return SCTP_DISPOSITION_DELETE_TCB
;
5557 return SCTP_DISPOSITION_CONSUME
;
5561 * sctp_sf_t1_cookie_timer_expire
5563 * Section: 4 Note: 2
5568 * RFC 2960 Section 4 Notes
5569 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
5570 * COOKIE ECHO and re-start the T1-cookie timer without changing
5571 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
5572 * After that, the endpoint MUST abort the initialization process and
5573 * report the error to SCTP user.
5579 sctp_disposition_t
sctp_sf_t1_cookie_timer_expire(struct net
*net
,
5580 const struct sctp_endpoint
*ep
,
5581 const struct sctp_association
*asoc
,
5582 const sctp_subtype_t type
,
5584 sctp_cmd_seq_t
*commands
)
5586 struct sctp_chunk
*repl
= NULL
;
5587 int attempts
= asoc
->init_err_counter
+ 1;
5589 SCTP_DEBUG_PRINTK("Timer T1 expired (COOKIE-ECHO).\n");
5590 SCTP_INC_STATS(net
, SCTP_MIB_T1_COOKIE_EXPIREDS
);
5592 if (attempts
<= asoc
->max_init_attempts
) {
5593 repl
= sctp_make_cookie_echo(asoc
, NULL
);
5595 return SCTP_DISPOSITION_NOMEM
;
5597 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5599 /* Issue a sideeffect to do the needed accounting. */
5600 sctp_add_cmd_sf(commands
, SCTP_CMD_COOKIEECHO_RESTART
,
5601 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
5603 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5605 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5606 SCTP_ERROR(ETIMEDOUT
));
5607 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5608 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5609 return SCTP_DISPOSITION_DELETE_TCB
;
5612 return SCTP_DISPOSITION_CONSUME
;
5615 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
5616 * with the updated last sequential TSN received from its peer.
5618 * An endpoint should limit the number of retransmissions of the
5619 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
5620 * If this threshold is exceeded the endpoint should destroy the TCB and
5621 * MUST report the peer endpoint unreachable to the upper layer (and
5622 * thus the association enters the CLOSED state). The reception of any
5623 * packet from its peer (i.e. as the peer sends all of its queued DATA
5624 * chunks) should clear the endpoint's retransmission count and restart
5625 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
5626 * all of its queued DATA chunks that have not yet been sent.
5628 sctp_disposition_t
sctp_sf_t2_timer_expire(struct net
*net
,
5629 const struct sctp_endpoint
*ep
,
5630 const struct sctp_association
*asoc
,
5631 const sctp_subtype_t type
,
5633 sctp_cmd_seq_t
*commands
)
5635 struct sctp_chunk
*reply
= NULL
;
5637 SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
5638 SCTP_INC_STATS(net
, SCTP_MIB_T2_SHUTDOWN_EXPIREDS
);
5640 ((struct sctp_association
*)asoc
)->shutdown_retries
++;
5642 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5643 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5644 SCTP_ERROR(ETIMEDOUT
));
5645 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5646 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5647 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5648 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5649 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5650 return SCTP_DISPOSITION_DELETE_TCB
;
5653 switch (asoc
->state
) {
5654 case SCTP_STATE_SHUTDOWN_SENT
:
5655 reply
= sctp_make_shutdown(asoc
, NULL
);
5658 case SCTP_STATE_SHUTDOWN_ACK_SENT
:
5659 reply
= sctp_make_shutdown_ack(asoc
, NULL
);
5670 /* Do some failure management (Section 8.2).
5671 * If we remove the transport an SHUTDOWN was last sent to, don't
5672 * do failure management.
5674 if (asoc
->shutdown_last_sent_to
)
5675 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5676 SCTP_TRANSPORT(asoc
->shutdown_last_sent_to
));
5678 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
5679 * the T2-shutdown timer.
5681 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5683 /* Restart the T2-shutdown timer. */
5684 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5685 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5686 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5687 return SCTP_DISPOSITION_CONSUME
;
5690 return SCTP_DISPOSITION_NOMEM
;
5694 * ADDIP Section 4.1 ASCONF CHunk Procedures
5695 * If the T4 RTO timer expires the endpoint should do B1 to B5
5697 sctp_disposition_t
sctp_sf_t4_timer_expire(
5699 const struct sctp_endpoint
*ep
,
5700 const struct sctp_association
*asoc
,
5701 const sctp_subtype_t type
,
5703 sctp_cmd_seq_t
*commands
)
5705 struct sctp_chunk
*chunk
= asoc
->addip_last_asconf
;
5706 struct sctp_transport
*transport
= chunk
->transport
;
5708 SCTP_INC_STATS(net
, SCTP_MIB_T4_RTO_EXPIREDS
);
5710 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
5711 * detection on the appropriate destination address as defined in
5712 * RFC2960 [5] section 8.1 and 8.2.
5715 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5716 SCTP_TRANSPORT(transport
));
5718 /* Reconfig T4 timer and transport. */
5719 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5721 /* ADDIP 4.1 B2) Increment the association error counters and perform
5722 * endpoint failure detection on the association as defined in
5723 * RFC2960 [5] section 8.1 and 8.2.
5724 * association error counter is incremented in SCTP_CMD_STRIKE.
5726 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5727 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5728 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5729 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5730 SCTP_ERROR(ETIMEDOUT
));
5731 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5732 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5733 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5734 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5735 return SCTP_DISPOSITION_ABORT
;
5738 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
5739 * the ASCONF chunk was sent by doubling the RTO timer value.
5740 * This is done in SCTP_CMD_STRIKE.
5743 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
5744 * choose an alternate destination address (please refer to RFC2960
5745 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
5746 * chunk, it MUST be the same (including its serial number) as the last
5749 sctp_chunk_hold(asoc
->addip_last_asconf
);
5750 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5751 SCTP_CHUNK(asoc
->addip_last_asconf
));
5753 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
5754 * destination is selected, then the RTO used will be that of the new
5755 * destination address.
5757 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5758 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5760 return SCTP_DISPOSITION_CONSUME
;
5763 /* sctpimpguide-05 Section 2.12.2
5764 * The sender of the SHUTDOWN MAY also start an overall guard timer
5765 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5766 * At the expiration of this timer the sender SHOULD abort the association
5767 * by sending an ABORT chunk.
5769 sctp_disposition_t
sctp_sf_t5_timer_expire(struct net
*net
,
5770 const struct sctp_endpoint
*ep
,
5771 const struct sctp_association
*asoc
,
5772 const sctp_subtype_t type
,
5774 sctp_cmd_seq_t
*commands
)
5776 struct sctp_chunk
*reply
= NULL
;
5778 SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
5779 SCTP_INC_STATS(net
, SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS
);
5781 reply
= sctp_make_abort(asoc
, NULL
, 0);
5785 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5786 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5787 SCTP_ERROR(ETIMEDOUT
));
5788 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5789 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5791 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5792 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5794 return SCTP_DISPOSITION_DELETE_TCB
;
5796 return SCTP_DISPOSITION_NOMEM
;
5799 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
5800 * the association is automatically closed by starting the shutdown process.
5801 * The work that needs to be done is same as when SHUTDOWN is initiated by
5802 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
5804 sctp_disposition_t
sctp_sf_autoclose_timer_expire(
5806 const struct sctp_endpoint
*ep
,
5807 const struct sctp_association
*asoc
,
5808 const sctp_subtype_t type
,
5810 sctp_cmd_seq_t
*commands
)
5814 SCTP_INC_STATS(net
, SCTP_MIB_AUTOCLOSE_EXPIREDS
);
5816 /* From 9.2 Shutdown of an Association
5817 * Upon receipt of the SHUTDOWN primitive from its upper
5818 * layer, the endpoint enters SHUTDOWN-PENDING state and
5819 * remains there until all outstanding data has been
5820 * acknowledged by its peer. The endpoint accepts no new data
5821 * from its upper layer, but retransmits data to the far end
5822 * if necessary to fill gaps.
5824 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5825 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
5827 disposition
= SCTP_DISPOSITION_CONSUME
;
5828 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
5829 disposition
= sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
, type
,
5835 /*****************************************************************************
5836 * These are sa state functions which could apply to all types of events.
5837 ****************************************************************************/
5840 * This table entry is not implemented.
5843 * (endpoint, asoc, chunk)
5845 * The return value is the disposition of the chunk.
5847 sctp_disposition_t
sctp_sf_not_impl(struct net
*net
,
5848 const struct sctp_endpoint
*ep
,
5849 const struct sctp_association
*asoc
,
5850 const sctp_subtype_t type
,
5852 sctp_cmd_seq_t
*commands
)
5854 return SCTP_DISPOSITION_NOT_IMPL
;
5858 * This table entry represents a bug.
5861 * (endpoint, asoc, chunk)
5863 * The return value is the disposition of the chunk.
5865 sctp_disposition_t
sctp_sf_bug(struct net
*net
,
5866 const struct sctp_endpoint
*ep
,
5867 const struct sctp_association
*asoc
,
5868 const sctp_subtype_t type
,
5870 sctp_cmd_seq_t
*commands
)
5872 return SCTP_DISPOSITION_BUG
;
5876 * This table entry represents the firing of a timer in the wrong state.
5877 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
5878 * when the association is in the wrong state. This event should
5879 * be ignored, so as to prevent any rearming of the timer.
5882 * (endpoint, asoc, chunk)
5884 * The return value is the disposition of the chunk.
5886 sctp_disposition_t
sctp_sf_timer_ignore(struct net
*net
,
5887 const struct sctp_endpoint
*ep
,
5888 const struct sctp_association
*asoc
,
5889 const sctp_subtype_t type
,
5891 sctp_cmd_seq_t
*commands
)
5893 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type
.chunk
);
5894 return SCTP_DISPOSITION_CONSUME
;
5897 /********************************************************************
5898 * 2nd Level Abstractions
5899 ********************************************************************/
5901 /* Pull the SACK chunk based on the SACK header. */
5902 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
)
5904 struct sctp_sackhdr
*sack
;
5909 /* Protect ourselves from reading too far into
5910 * the skb from a bogus sender.
5912 sack
= (struct sctp_sackhdr
*) chunk
->skb
->data
;
5914 num_blocks
= ntohs(sack
->num_gap_ack_blocks
);
5915 num_dup_tsns
= ntohs(sack
->num_dup_tsns
);
5916 len
= sizeof(struct sctp_sackhdr
);
5917 len
+= (num_blocks
+ num_dup_tsns
) * sizeof(__u32
);
5918 if (len
> chunk
->skb
->len
)
5921 skb_pull(chunk
->skb
, len
);
5926 /* Create an ABORT packet to be sent as a response, with the specified
5929 static struct sctp_packet
*sctp_abort_pkt_new(struct net
*net
,
5930 const struct sctp_endpoint
*ep
,
5931 const struct sctp_association
*asoc
,
5932 struct sctp_chunk
*chunk
,
5933 const void *payload
,
5936 struct sctp_packet
*packet
;
5937 struct sctp_chunk
*abort
;
5939 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
5943 * The T bit will be set if the asoc is NULL.
5945 abort
= sctp_make_abort(asoc
, chunk
, paylen
);
5947 sctp_ootb_pkt_free(packet
);
5951 /* Reflect vtag if T-Bit is set */
5952 if (sctp_test_T_bit(abort
))
5953 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
5955 /* Add specified error causes, i.e., payload, to the
5958 sctp_addto_chunk(abort
, paylen
, payload
);
5960 /* Set the skb to the belonging sock for accounting. */
5961 abort
->skb
->sk
= ep
->base
.sk
;
5963 sctp_packet_append_chunk(packet
, abort
);
5970 /* Allocate a packet for responding in the OOTB conditions. */
5971 static struct sctp_packet
*sctp_ootb_pkt_new(struct net
*net
,
5972 const struct sctp_association
*asoc
,
5973 const struct sctp_chunk
*chunk
)
5975 struct sctp_packet
*packet
;
5976 struct sctp_transport
*transport
;
5981 /* Get the source and destination port from the inbound packet. */
5982 sport
= ntohs(chunk
->sctp_hdr
->dest
);
5983 dport
= ntohs(chunk
->sctp_hdr
->source
);
5985 /* The V-tag is going to be the same as the inbound packet if no
5986 * association exists, otherwise, use the peer's vtag.
5989 /* Special case the INIT-ACK as there is no peer's vtag
5992 switch(chunk
->chunk_hdr
->type
) {
5993 case SCTP_CID_INIT_ACK
:
5995 sctp_initack_chunk_t
*initack
;
5997 initack
= (sctp_initack_chunk_t
*)chunk
->chunk_hdr
;
5998 vtag
= ntohl(initack
->init_hdr
.init_tag
);
6002 vtag
= asoc
->peer
.i
.init_tag
;
6006 /* Special case the INIT and stale COOKIE_ECHO as there is no
6009 switch(chunk
->chunk_hdr
->type
) {
6012 sctp_init_chunk_t
*init
;
6014 init
= (sctp_init_chunk_t
*)chunk
->chunk_hdr
;
6015 vtag
= ntohl(init
->init_hdr
.init_tag
);
6019 vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
6024 /* Make a transport for the bucket, Eliza... */
6025 transport
= sctp_transport_new(net
, sctp_source(chunk
), GFP_ATOMIC
);
6029 /* Cache a route for the transport with the chunk's destination as
6030 * the source address.
6032 sctp_transport_route(transport
, (union sctp_addr
*)&chunk
->dest
,
6033 sctp_sk(net
->sctp
.ctl_sock
));
6035 packet
= sctp_packet_init(&transport
->packet
, transport
, sport
, dport
);
6036 packet
= sctp_packet_config(packet
, vtag
, 0);
6044 /* Free the packet allocated earlier for responding in the OOTB condition. */
6045 void sctp_ootb_pkt_free(struct sctp_packet
*packet
)
6047 sctp_transport_free(packet
->transport
);
6050 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
6051 static void sctp_send_stale_cookie_err(struct net
*net
,
6052 const struct sctp_endpoint
*ep
,
6053 const struct sctp_association
*asoc
,
6054 const struct sctp_chunk
*chunk
,
6055 sctp_cmd_seq_t
*commands
,
6056 struct sctp_chunk
*err_chunk
)
6058 struct sctp_packet
*packet
;
6061 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
6063 struct sctp_signed_cookie
*cookie
;
6065 /* Override the OOTB vtag from the cookie. */
6066 cookie
= chunk
->subh
.cookie_hdr
;
6067 packet
->vtag
= cookie
->c
.peer_vtag
;
6069 /* Set the skb to the belonging sock for accounting. */
6070 err_chunk
->skb
->sk
= ep
->base
.sk
;
6071 sctp_packet_append_chunk(packet
, err_chunk
);
6072 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
6073 SCTP_PACKET(packet
));
6074 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
6076 sctp_chunk_free (err_chunk
);
6081 /* Process a data chunk */
6082 static int sctp_eat_data(const struct sctp_association
*asoc
,
6083 struct sctp_chunk
*chunk
,
6084 sctp_cmd_seq_t
*commands
)
6086 sctp_datahdr_t
*data_hdr
;
6087 struct sctp_chunk
*err
;
6089 sctp_verb_t deliver
;
6092 struct sctp_tsnmap
*map
= (struct sctp_tsnmap
*)&asoc
->peer
.tsn_map
;
6093 struct sock
*sk
= asoc
->base
.sk
;
6094 struct net
*net
= sock_net(sk
);
6099 data_hdr
= chunk
->subh
.data_hdr
= (sctp_datahdr_t
*)chunk
->skb
->data
;
6100 skb_pull(chunk
->skb
, sizeof(sctp_datahdr_t
));
6102 tsn
= ntohl(data_hdr
->tsn
);
6103 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn
);
6105 /* ASSERT: Now skb->data is really the user data. */
6107 /* Process ECN based congestion.
6109 * Since the chunk structure is reused for all chunks within
6110 * a packet, we use ecn_ce_done to track if we've already
6111 * done CE processing for this packet.
6113 * We need to do ECN processing even if we plan to discard the
6117 if (!chunk
->ecn_ce_done
) {
6119 chunk
->ecn_ce_done
= 1;
6121 af
= sctp_get_af_specific(
6122 ipver2af(ip_hdr(chunk
->skb
)->version
));
6124 if (af
&& af
->is_ce(chunk
->skb
) && asoc
->peer
.ecn_capable
) {
6125 /* Do real work as sideffect. */
6126 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_CE
,
6131 tmp
= sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
);
6133 /* The TSN is too high--silently discard the chunk and
6134 * count on it getting retransmitted later.
6137 chunk
->asoc
->stats
.outofseqtsns
++;
6138 return SCTP_IERROR_HIGH_TSN
;
6139 } else if (tmp
> 0) {
6140 /* This is a duplicate. Record it. */
6141 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_DUP
, SCTP_U32(tsn
));
6142 return SCTP_IERROR_DUP_TSN
;
6145 /* This is a new TSN. */
6147 /* Discard if there is no room in the receive window.
6148 * Actually, allow a little bit of overflow (up to a MTU).
6150 datalen
= ntohs(chunk
->chunk_hdr
->length
);
6151 datalen
-= sizeof(sctp_data_chunk_t
);
6153 deliver
= SCTP_CMD_CHUNK_ULP
;
6155 /* Think about partial delivery. */
6156 if ((datalen
>= asoc
->rwnd
) && (!asoc
->ulpq
.pd_mode
)) {
6158 /* Even if we don't accept this chunk there is
6161 sctp_add_cmd_sf(commands
, SCTP_CMD_PART_DELIVER
, SCTP_NULL());
6164 /* Spill over rwnd a little bit. Note: While allowed, this spill over
6165 * seems a bit troublesome in that frag_point varies based on
6166 * PMTU. In cases, such as loopback, this might be a rather
6169 if ((!chunk
->data_accepted
) && (!asoc
->rwnd
|| asoc
->rwnd_over
||
6170 (datalen
> asoc
->rwnd
+ asoc
->frag_point
))) {
6172 /* If this is the next TSN, consider reneging to make
6173 * room. Note: Playing nice with a confused sender. A
6174 * malicious sender can still eat up all our buffer
6175 * space and in the future we may want to detect and
6176 * do more drastic reneging.
6178 if (sctp_tsnmap_has_gap(map
) &&
6179 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
6180 SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn
);
6181 deliver
= SCTP_CMD_RENEGE
;
6183 SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
6184 "rwnd: %d\n", tsn
, datalen
,
6186 return SCTP_IERROR_IGNORE_TSN
;
6191 * Also try to renege to limit our memory usage in the event that
6192 * we are under memory pressure
6193 * If we can't renege, don't worry about it, the sk_rmem_schedule
6194 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
6195 * memory usage too much
6197 if (*sk
->sk_prot_creator
->memory_pressure
) {
6198 if (sctp_tsnmap_has_gap(map
) &&
6199 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
6200 SCTP_DEBUG_PRINTK("Under Pressure! Reneging for tsn:%u\n", tsn
);
6201 deliver
= SCTP_CMD_RENEGE
;
6206 * Section 3.3.10.9 No User Data (9)
6210 * No User Data: This error cause is returned to the originator of a
6211 * DATA chunk if a received DATA chunk has no user data.
6213 if (unlikely(0 == datalen
)) {
6214 err
= sctp_make_abort_no_data(asoc
, chunk
, tsn
);
6216 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6219 /* We are going to ABORT, so we might as well stop
6220 * processing the rest of the chunks in the packet.
6222 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
6223 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
6224 SCTP_ERROR(ECONNABORTED
));
6225 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
6226 SCTP_PERR(SCTP_ERROR_NO_DATA
));
6227 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
6228 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
6229 return SCTP_IERROR_NO_DATA
;
6232 chunk
->data_accepted
= 1;
6234 /* Note: Some chunks may get overcounted (if we drop) or overcounted
6235 * if we renege and the chunk arrives again.
6237 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_UNORDERED
) {
6238 SCTP_INC_STATS(net
, SCTP_MIB_INUNORDERCHUNKS
);
6240 chunk
->asoc
->stats
.iuodchunks
++;
6242 SCTP_INC_STATS(net
, SCTP_MIB_INORDERCHUNKS
);
6244 chunk
->asoc
->stats
.iodchunks
++;
6248 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
6250 * If an endpoint receive a DATA chunk with an invalid stream
6251 * identifier, it shall acknowledge the reception of the DATA chunk
6252 * following the normal procedure, immediately send an ERROR chunk
6253 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
6254 * and discard the DATA chunk.
6256 sid
= ntohs(data_hdr
->stream
);
6257 if (sid
>= asoc
->c
.sinit_max_instreams
) {
6258 /* Mark tsn as received even though we drop it */
6259 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_TSN
, SCTP_U32(tsn
));
6261 err
= sctp_make_op_error(asoc
, chunk
, SCTP_ERROR_INV_STRM
,
6263 sizeof(data_hdr
->stream
),
6266 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6268 return SCTP_IERROR_BAD_STREAM
;
6271 /* Check to see if the SSN is possible for this TSN.
6272 * The biggest gap we can record is 4K wide. Since SSNs wrap
6273 * at an unsigned short, there is no way that an SSN can
6274 * wrap and for a valid TSN. We can simply check if the current
6275 * SSN is smaller then the next expected one. If it is, it wrapped
6278 ssn
= ntohs(data_hdr
->ssn
);
6279 if (ordered
&& SSN_lt(ssn
, sctp_ssn_peek(&asoc
->ssnmap
->in
, sid
))) {
6280 return SCTP_IERROR_PROTO_VIOLATION
;
6283 /* Send the data up to the user. Note: Schedule the
6284 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
6285 * chunk needs the updated rwnd.
6287 sctp_add_cmd_sf(commands
, deliver
, SCTP_CHUNK(chunk
));
6289 return SCTP_IERROR_NO_ERROR
;