1 /* SCTP kernel implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001-2002 Intel Corp.
6 * Copyright (c) 2002 Nokia Corp.
8 * This is part of the SCTP Linux Kernel Implementation.
10 * These are the state functions for the state machine.
12 * This SCTP implementation is free software;
13 * you can redistribute it and/or modify it under the terms of
14 * the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * This SCTP implementation is distributed in the hope that it
19 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
20 * ************************
21 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 * See the GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with GNU CC; see the file COPYING. If not, see
26 * <http://www.gnu.org/licenses/>.
28 * Please send any bug reports or fixes you make to the
30 * lksctp developers <linux-sctp@vger.kernel.org>
32 * Written or modified by:
33 * La Monte H.P. Yarroll <piggy@acm.org>
34 * Karl Knutson <karl@athena.chicago.il.us>
35 * Mathew Kotowsky <kotowsky@sctp.org>
36 * Sridhar Samudrala <samudrala@us.ibm.com>
37 * Jon Grimm <jgrimm@us.ibm.com>
38 * Hui Huang <hui.huang@nokia.com>
39 * Dajiang Zhang <dajiang.zhang@nokia.com>
40 * Daisy Chang <daisyc@us.ibm.com>
41 * Ardelle Fan <ardelle.fan@intel.com>
42 * Ryan Layer <rmlayer@us.ibm.com>
43 * Kevin Gao <kevin.gao@intel.com>
46 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
48 #include <linux/types.h>
49 #include <linux/kernel.h>
51 #include <linux/ipv6.h>
52 #include <linux/net.h>
53 #include <linux/inet.h>
54 #include <linux/slab.h>
56 #include <net/inet_ecn.h>
57 #include <linux/skbuff.h>
58 #include <net/sctp/sctp.h>
59 #include <net/sctp/sm.h>
60 #include <net/sctp/structs.h>
62 static struct sctp_packet
*sctp_abort_pkt_new(
64 const struct sctp_endpoint
*ep
,
65 const struct sctp_association
*asoc
,
66 struct sctp_chunk
*chunk
,
67 const void *payload
, size_t paylen
);
68 static int sctp_eat_data(const struct sctp_association
*asoc
,
69 struct sctp_chunk
*chunk
,
70 struct sctp_cmd_seq
*commands
);
71 static struct sctp_packet
*sctp_ootb_pkt_new(
73 const struct sctp_association
*asoc
,
74 const struct sctp_chunk
*chunk
);
75 static void sctp_send_stale_cookie_err(struct net
*net
,
76 const struct sctp_endpoint
*ep
,
77 const struct sctp_association
*asoc
,
78 const struct sctp_chunk
*chunk
,
79 struct sctp_cmd_seq
*commands
,
80 struct sctp_chunk
*err_chunk
);
81 static enum sctp_disposition
sctp_sf_do_5_2_6_stale(
83 const struct sctp_endpoint
*ep
,
84 const struct sctp_association
*asoc
,
85 const union sctp_subtype type
,
87 struct sctp_cmd_seq
*commands
);
88 static enum sctp_disposition
sctp_sf_shut_8_4_5(
90 const struct sctp_endpoint
*ep
,
91 const struct sctp_association
*asoc
,
92 const union sctp_subtype type
,
94 struct sctp_cmd_seq
*commands
);
95 static enum sctp_disposition
sctp_sf_tabort_8_4_8(
97 const struct sctp_endpoint
*ep
,
98 const struct sctp_association
*asoc
,
99 const union sctp_subtype type
,
101 struct sctp_cmd_seq
*commands
);
102 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
);
104 static enum sctp_disposition
sctp_stop_t1_and_abort(
106 struct sctp_cmd_seq
*commands
,
107 __be16 error
, int sk_err
,
108 const struct sctp_association
*asoc
,
109 struct sctp_transport
*transport
);
111 static enum sctp_disposition
sctp_sf_abort_violation(
113 const struct sctp_endpoint
*ep
,
114 const struct sctp_association
*asoc
,
116 struct sctp_cmd_seq
*commands
,
118 const size_t paylen
);
120 static enum sctp_disposition
sctp_sf_violation_chunklen(
122 const struct sctp_endpoint
*ep
,
123 const struct sctp_association
*asoc
,
124 const union sctp_subtype type
,
126 struct sctp_cmd_seq
*commands
);
128 static enum sctp_disposition
sctp_sf_violation_paramlen(
130 const struct sctp_endpoint
*ep
,
131 const struct sctp_association
*asoc
,
132 const union sctp_subtype type
,
133 void *arg
, void *ext
,
134 struct sctp_cmd_seq
*commands
);
136 static enum sctp_disposition
sctp_sf_violation_ctsn(
138 const struct sctp_endpoint
*ep
,
139 const struct sctp_association
*asoc
,
140 const union sctp_subtype type
,
142 struct sctp_cmd_seq
*commands
);
144 static enum sctp_disposition
sctp_sf_violation_chunk(
146 const struct sctp_endpoint
*ep
,
147 const struct sctp_association
*asoc
,
148 const union sctp_subtype type
,
150 struct sctp_cmd_seq
*commands
);
152 static enum sctp_ierror
sctp_sf_authenticate(
154 const struct sctp_endpoint
*ep
,
155 const struct sctp_association
*asoc
,
156 const union sctp_subtype type
,
157 struct sctp_chunk
*chunk
);
159 static enum sctp_disposition
__sctp_sf_do_9_1_abort(
161 const struct sctp_endpoint
*ep
,
162 const struct sctp_association
*asoc
,
163 const union sctp_subtype type
,
165 struct sctp_cmd_seq
*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: true = Valid length
171 * false = Invalid length
174 static inline bool sctp_chunk_length_valid(struct sctp_chunk
*chunk
,
175 __u16 required_length
)
177 __u16 chunk_length
= ntohs(chunk
->chunk_hdr
->length
);
179 /* Previously already marked? */
180 if (unlikely(chunk
->pdiscard
))
182 if (unlikely(chunk_length
< required_length
))
188 /**********************************************************
189 * These are the state functions for handling chunk events.
190 **********************************************************/
193 * Process the final SHUTDOWN COMPLETE.
195 * Section: 4 (C) (diagram), 9.2
196 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
197 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
198 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
199 * should stop the T2-shutdown timer and remove all knowledge of the
200 * association (and thus the association enters the CLOSED state).
202 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
203 * C) Rules for packet carrying SHUTDOWN COMPLETE:
205 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
206 * if the Verification Tag field of the packet matches its own tag and
207 * the T bit is not set
209 * it is set to its peer's tag and the T bit is set in the Chunk
211 * Otherwise, the receiver MUST silently discard the packet
212 * and take no further action. An endpoint MUST ignore the
213 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
216 * (endpoint, asoc, chunk)
219 * (asoc, reply_msg, msg_up, timers, counters)
221 * The return value is the disposition of the chunk.
223 enum sctp_disposition
sctp_sf_do_4_C(struct net
*net
,
224 const struct sctp_endpoint
*ep
,
225 const struct sctp_association
*asoc
,
226 const union sctp_subtype type
,
227 void *arg
, struct sctp_cmd_seq
*commands
)
229 struct sctp_chunk
*chunk
= arg
;
230 struct sctp_ulpevent
*ev
;
232 if (!sctp_vtag_verify_either(chunk
, asoc
))
233 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
235 /* RFC 2960 6.10 Bundling
237 * An endpoint MUST NOT bundle INIT, INIT ACK or
238 * SHUTDOWN COMPLETE with any other chunks.
240 if (!chunk
->singleton
)
241 return sctp_sf_violation_chunk(net
, ep
, asoc
, type
, arg
, commands
);
243 /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */
244 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
245 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
248 /* RFC 2960 10.2 SCTP-to-ULP
250 * H) SHUTDOWN COMPLETE notification
252 * When SCTP completes the shutdown procedures (section 9.2) this
253 * notification is passed to the upper layer.
255 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
256 0, 0, 0, NULL
, GFP_ATOMIC
);
258 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
261 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
262 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
263 * not the chunk should be discarded. If the endpoint is in
264 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
265 * T2-shutdown timer and remove all knowledge of the
266 * association (and thus the association enters the CLOSED
269 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
270 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
272 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
273 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
275 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
276 SCTP_STATE(SCTP_STATE_CLOSED
));
278 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
279 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
281 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
283 return SCTP_DISPOSITION_DELETE_TCB
;
287 * Respond to a normal INIT chunk.
288 * We are the side that is being asked for an association.
290 * Section: 5.1 Normal Establishment of an Association, B
291 * B) "Z" shall respond immediately with an INIT ACK chunk. The
292 * destination IP address of the INIT ACK MUST be set to the source
293 * IP address of the INIT to which this INIT ACK is responding. In
294 * the response, besides filling in other parameters, "Z" must set the
295 * Verification Tag field to Tag_A, and also provide its own
296 * Verification Tag (Tag_Z) in the Initiate Tag field.
298 * Verification Tag: Must be 0.
301 * (endpoint, asoc, chunk)
304 * (asoc, reply_msg, msg_up, timers, counters)
306 * The return value is the disposition of the chunk.
308 enum sctp_disposition
sctp_sf_do_5_1B_init(struct net
*net
,
309 const struct sctp_endpoint
*ep
,
310 const struct sctp_association
*asoc
,
311 const union sctp_subtype type
,
313 struct sctp_cmd_seq
*commands
)
315 struct sctp_chunk
*chunk
= arg
, *repl
, *err_chunk
;
316 struct sctp_unrecognized_param
*unk_param
;
317 struct sctp_association
*new_asoc
;
318 struct sctp_packet
*packet
;
322 * An endpoint MUST NOT bundle INIT, INIT ACK or
323 * SHUTDOWN COMPLETE with any other chunks.
326 * Furthermore, we require that the receiver of an INIT chunk MUST
327 * enforce these rules by silently discarding an arriving packet
328 * with an INIT chunk that is bundled with other chunks.
330 if (!chunk
->singleton
)
331 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
333 /* If the packet is an OOTB packet which is temporarily on the
334 * control endpoint, respond with an ABORT.
336 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
) {
337 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
338 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
341 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
344 if (chunk
->sctp_hdr
->vtag
!= 0)
345 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
347 /* Make sure that the INIT chunk has a valid length.
348 * Normally, this would cause an ABORT with a Protocol Violation
349 * error, but since we don't have an association, we'll
350 * just discard the packet.
352 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_init_chunk
)))
353 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
355 /* If the INIT is coming toward a closing socket, we'll send back
356 * and ABORT. Essentially, this catches the race of INIT being
357 * backloged to the socket at the same time as the user isses close().
358 * Since the socket and all its associations are going away, we
359 * can treat this OOTB
361 if (sctp_sstate(ep
->base
.sk
, CLOSING
))
362 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
364 /* Verify the INIT chunk before processing it. */
366 if (!sctp_verify_init(net
, ep
, asoc
, chunk
->chunk_hdr
->type
,
367 (struct sctp_init_chunk
*)chunk
->chunk_hdr
, chunk
,
369 /* This chunk contains fatal error. It is to be discarded.
370 * Send an ABORT, with causes if there is any.
373 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
374 (__u8
*)(err_chunk
->chunk_hdr
) +
375 sizeof(struct sctp_chunkhdr
),
376 ntohs(err_chunk
->chunk_hdr
->length
) -
377 sizeof(struct sctp_chunkhdr
));
379 sctp_chunk_free(err_chunk
);
382 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
383 SCTP_PACKET(packet
));
384 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
385 return SCTP_DISPOSITION_CONSUME
;
387 return SCTP_DISPOSITION_NOMEM
;
390 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
,
395 /* Grab the INIT header. */
396 chunk
->subh
.init_hdr
= (struct sctp_inithdr
*)chunk
->skb
->data
;
398 /* Tag the variable length parameters. */
399 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(struct sctp_inithdr
));
401 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
405 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
,
406 sctp_scope(sctp_source(chunk
)),
410 /* The call, sctp_process_init(), can fail on memory allocation. */
411 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
),
412 (struct sctp_init_chunk
*)chunk
->chunk_hdr
,
416 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
418 /* If there are errors need to be reported for unknown parameters,
419 * make sure to reserve enough room in the INIT ACK for them.
423 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
424 sizeof(struct sctp_chunkhdr
);
426 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
430 /* If there are errors need to be reported for unknown parameters,
431 * include them in the outgoing INIT ACK as "Unrecognized parameter"
435 /* Get the "Unrecognized parameter" parameter(s) out of the
436 * ERROR chunk generated by sctp_verify_init(). Since the
437 * error cause code for "unknown parameter" and the
438 * "Unrecognized parameter" type is the same, we can
439 * construct the parameters in INIT ACK by copying the
442 unk_param
= (struct sctp_unrecognized_param
*)
443 ((__u8
*)(err_chunk
->chunk_hdr
) +
444 sizeof(struct sctp_chunkhdr
));
445 /* Replace the cause code with the "Unrecognized parameter"
448 sctp_addto_chunk(repl
, len
, unk_param
);
449 sctp_chunk_free(err_chunk
);
452 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
454 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
457 * Note: After sending out INIT ACK with the State Cookie parameter,
458 * "Z" MUST NOT allocate any resources, nor keep any states for the
459 * new association. Otherwise, "Z" will be vulnerable to resource
462 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
464 return SCTP_DISPOSITION_DELETE_TCB
;
467 sctp_association_free(new_asoc
);
470 sctp_chunk_free(err_chunk
);
471 return SCTP_DISPOSITION_NOMEM
;
475 * Respond to a normal INIT ACK chunk.
476 * We are the side that is initiating the association.
478 * Section: 5.1 Normal Establishment of an Association, C
479 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
480 * timer and leave COOKIE-WAIT state. "A" shall then send the State
481 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
482 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
484 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
485 * DATA chunks, but it MUST be the first chunk in the packet and
486 * until the COOKIE ACK is returned the sender MUST NOT send any
487 * other packets to the peer.
489 * Verification Tag: 3.3.3
490 * If the value of the Initiate Tag in a received INIT ACK chunk is
491 * found to be 0, the receiver MUST treat it as an error and close the
492 * association by transmitting an ABORT.
495 * (endpoint, asoc, chunk)
498 * (asoc, reply_msg, msg_up, timers, counters)
500 * The return value is the disposition of the chunk.
502 enum sctp_disposition
sctp_sf_do_5_1C_ack(struct net
*net
,
503 const struct sctp_endpoint
*ep
,
504 const struct sctp_association
*asoc
,
505 const union sctp_subtype type
,
507 struct sctp_cmd_seq
*commands
)
509 struct sctp_init_chunk
*initchunk
;
510 struct sctp_chunk
*chunk
= arg
;
511 struct sctp_chunk
*err_chunk
;
512 struct sctp_packet
*packet
;
514 if (!sctp_vtag_verify(chunk
, asoc
))
515 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
518 * An endpoint MUST NOT bundle INIT, INIT ACK or
519 * SHUTDOWN COMPLETE with any other chunks.
521 if (!chunk
->singleton
)
522 return sctp_sf_violation_chunk(net
, ep
, asoc
, type
, arg
, commands
);
524 /* Make sure that the INIT-ACK chunk has a valid length */
525 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_initack_chunk
)))
526 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
528 /* Grab the INIT header. */
529 chunk
->subh
.init_hdr
= (struct sctp_inithdr
*)chunk
->skb
->data
;
531 /* Verify the INIT chunk before processing it. */
533 if (!sctp_verify_init(net
, ep
, asoc
, chunk
->chunk_hdr
->type
,
534 (struct sctp_init_chunk
*)chunk
->chunk_hdr
, chunk
,
537 enum sctp_error error
= SCTP_ERROR_NO_RESOURCE
;
539 /* This chunk contains fatal error. It is to be discarded.
540 * Send an ABORT, with causes. If there are no causes,
541 * then there wasn't enough memory. Just terminate
545 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
546 (__u8
*)(err_chunk
->chunk_hdr
) +
547 sizeof(struct sctp_chunkhdr
),
548 ntohs(err_chunk
->chunk_hdr
->length
) -
549 sizeof(struct sctp_chunkhdr
));
551 sctp_chunk_free(err_chunk
);
554 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
555 SCTP_PACKET(packet
));
556 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
557 error
= SCTP_ERROR_INV_PARAM
;
561 /* SCTP-AUTH, Section 6.3:
562 * It should be noted that if the receiver wants to tear
563 * down an association in an authenticated way only, the
564 * handling of malformed packets should not result in
565 * tearing down the association.
567 * This means that if we only want to abort associations
568 * in an authenticated way (i.e AUTH+ABORT), then we
569 * can't destroy this association just because the packet
572 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
573 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
575 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
576 return sctp_stop_t1_and_abort(net
, commands
, error
, ECONNREFUSED
,
577 asoc
, chunk
->transport
);
580 /* Tag the variable length parameters. Note that we never
581 * convert the parameters in an INIT chunk.
583 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(struct sctp_inithdr
));
585 initchunk
= (struct sctp_init_chunk
*)chunk
->chunk_hdr
;
587 sctp_add_cmd_sf(commands
, SCTP_CMD_PEER_INIT
,
588 SCTP_PEER_INIT(initchunk
));
590 /* Reset init error count upon receipt of INIT-ACK. */
591 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
593 /* 5.1 C) "A" shall stop the T1-init timer and leave
594 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
595 * timer, and enter the COOKIE-ECHOED state.
597 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
598 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
599 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
600 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
601 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
602 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED
));
604 /* SCTP-AUTH: genereate the assocition shared keys so that
605 * we can potentially signe the COOKIE-ECHO.
607 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_SHKEY
, SCTP_NULL());
609 /* 5.1 C) "A" shall then send the State Cookie received in the
610 * INIT ACK chunk in a COOKIE ECHO chunk, ...
612 /* If there is any errors to report, send the ERROR chunk generated
613 * for unknown parameters as well.
615 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_COOKIE_ECHO
,
616 SCTP_CHUNK(err_chunk
));
618 return SCTP_DISPOSITION_CONSUME
;
622 * Respond to a normal COOKIE ECHO chunk.
623 * We are the side that is being asked for an association.
625 * Section: 5.1 Normal Establishment of an Association, D
626 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
627 * with a COOKIE ACK chunk after building a TCB and moving to
628 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
629 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
630 * chunk MUST be the first chunk in the packet.
632 * IMPLEMENTATION NOTE: An implementation may choose to send the
633 * Communication Up notification to the SCTP user upon reception
634 * of a valid COOKIE ECHO chunk.
636 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
637 * D) Rules for packet carrying a COOKIE ECHO
639 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
640 * Initial Tag received in the INIT ACK.
642 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
645 * (endpoint, asoc, chunk)
648 * (asoc, reply_msg, msg_up, timers, counters)
650 * The return value is the disposition of the chunk.
652 enum sctp_disposition
sctp_sf_do_5_1D_ce(struct net
*net
,
653 const struct sctp_endpoint
*ep
,
654 const struct sctp_association
*asoc
,
655 const union sctp_subtype type
,
657 struct sctp_cmd_seq
*commands
)
659 struct sctp_ulpevent
*ev
, *ai_ev
= NULL
;
660 struct sctp_association
*new_asoc
;
661 struct sctp_init_chunk
*peer_init
;
662 struct sctp_chunk
*chunk
= arg
;
663 struct sctp_chunk
*err_chk_p
;
664 struct sctp_chunk
*repl
;
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(struct sctp_chunkhdr
)))
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(struct sctp_chunkhdr
)))
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
;
766 enum sctp_ierror ret
;
768 /* Make sure that we and the peer are AUTH capable */
769 if (!net
->sctp
.auth_enable
|| !new_asoc
->peer
.auth_capable
) {
770 sctp_association_free(new_asoc
);
771 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
774 /* set-up our fake chunk so that we can process it */
775 auth
.skb
= chunk
->auth_chunk
;
776 auth
.asoc
= chunk
->asoc
;
777 auth
.sctp_hdr
= chunk
->sctp_hdr
;
778 auth
.chunk_hdr
= (struct sctp_chunkhdr
*)
779 skb_push(chunk
->auth_chunk
,
780 sizeof(struct sctp_chunkhdr
));
781 skb_pull(chunk
->auth_chunk
, sizeof(struct sctp_chunkhdr
));
782 auth
.transport
= chunk
->transport
;
784 ret
= sctp_sf_authenticate(net
, ep
, new_asoc
, type
, &auth
);
785 if (ret
!= SCTP_IERROR_NO_ERROR
) {
786 sctp_association_free(new_asoc
);
787 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
791 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
795 /* RFC 2960 5.1 Normal Establishment of an Association
797 * D) IMPLEMENTATION NOTE: An implementation may choose to
798 * send the Communication Up notification to the SCTP user
799 * upon reception of a valid COOKIE ECHO chunk.
801 ev
= sctp_ulpevent_make_assoc_change(new_asoc
, 0, SCTP_COMM_UP
, 0,
802 new_asoc
->c
.sinit_num_ostreams
,
803 new_asoc
->c
.sinit_max_instreams
,
808 /* Sockets API Draft Section 5.3.1.6
809 * When a peer sends a Adaptation Layer Indication parameter , SCTP
810 * delivers this notification to inform the application that of the
811 * peers requested adaptation layer.
813 if (new_asoc
->peer
.adaptation_ind
) {
814 ai_ev
= sctp_ulpevent_make_adaptation_indication(new_asoc
,
820 /* Add all the state machine commands now since we've created
821 * everything. This way we don't introduce memory corruptions
822 * during side-effect processing and correclty count established
825 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
826 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
827 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
828 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
829 SCTP_INC_STATS(net
, SCTP_MIB_PASSIVEESTABS
);
830 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
832 if (new_asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
833 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
834 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
836 /* This will send the COOKIE ACK */
837 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
839 /* Queue the ASSOC_CHANGE event */
840 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
842 /* Send up the Adaptation Layer Indication event */
844 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
845 SCTP_ULPEVENT(ai_ev
));
847 return SCTP_DISPOSITION_CONSUME
;
850 sctp_ulpevent_free(ev
);
852 sctp_chunk_free(repl
);
854 sctp_association_free(new_asoc
);
856 return SCTP_DISPOSITION_NOMEM
;
860 * Respond to a normal COOKIE ACK chunk.
861 * We are the side that is asking for an association.
863 * RFC 2960 5.1 Normal Establishment of an Association
865 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
866 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
867 * timer. It may also notify its ULP about the successful
868 * establishment of the association with a Communication Up
869 * notification (see Section 10).
873 * (endpoint, asoc, chunk)
876 * (asoc, reply_msg, msg_up, timers, counters)
878 * The return value is the disposition of the chunk.
880 enum sctp_disposition
sctp_sf_do_5_1E_ca(struct net
*net
,
881 const struct sctp_endpoint
*ep
,
882 const struct sctp_association
*asoc
,
883 const union sctp_subtype type
,
885 struct sctp_cmd_seq
*commands
)
887 struct sctp_chunk
*chunk
= arg
;
888 struct sctp_ulpevent
*ev
;
890 if (!sctp_vtag_verify(chunk
, asoc
))
891 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
893 /* Verify that the chunk length for the COOKIE-ACK is OK.
894 * If we don't do this, any bundled chunks may be junked.
896 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
897 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
900 /* Reset init error count upon receipt of COOKIE-ACK,
901 * to avoid problems with the managemement of this
902 * counter in stale cookie situations when a transition back
903 * from the COOKIE-ECHOED state to the COOKIE-WAIT
904 * state is performed.
906 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
908 /* RFC 2960 5.1 Normal Establishment of an Association
910 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
911 * from the COOKIE-ECHOED state to the ESTABLISHED state,
912 * stopping the T1-cookie timer.
914 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
915 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
916 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
917 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
918 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
919 SCTP_INC_STATS(net
, SCTP_MIB_ACTIVEESTABS
);
920 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
921 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
922 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
923 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
925 /* It may also notify its ULP about the successful
926 * establishment of the association with a Communication Up
927 * notification (see Section 10).
929 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_COMM_UP
,
930 0, asoc
->c
.sinit_num_ostreams
,
931 asoc
->c
.sinit_max_instreams
,
937 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
939 /* Sockets API Draft Section 5.3.1.6
940 * When a peer sends a Adaptation Layer Indication parameter , SCTP
941 * delivers this notification to inform the application that of the
942 * peers requested adaptation layer.
944 if (asoc
->peer
.adaptation_ind
) {
945 ev
= sctp_ulpevent_make_adaptation_indication(asoc
, GFP_ATOMIC
);
949 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
953 return SCTP_DISPOSITION_CONSUME
;
955 return SCTP_DISPOSITION_NOMEM
;
958 /* Generate and sendout a heartbeat packet. */
959 static enum sctp_disposition
sctp_sf_heartbeat(
960 const struct sctp_endpoint
*ep
,
961 const struct sctp_association
*asoc
,
962 const union sctp_subtype type
,
964 struct sctp_cmd_seq
*commands
)
966 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
967 struct sctp_chunk
*reply
;
969 /* Send a heartbeat to our peer. */
970 reply
= sctp_make_heartbeat(asoc
, transport
);
972 return SCTP_DISPOSITION_NOMEM
;
974 /* Set rto_pending indicating that an RTT measurement
975 * is started with this heartbeat chunk.
977 sctp_add_cmd_sf(commands
, SCTP_CMD_RTO_PENDING
,
978 SCTP_TRANSPORT(transport
));
980 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
981 return SCTP_DISPOSITION_CONSUME
;
984 /* Generate a HEARTBEAT packet on the given transport. */
985 enum sctp_disposition
sctp_sf_sendbeat_8_3(struct net
*net
,
986 const struct sctp_endpoint
*ep
,
987 const struct sctp_association
*asoc
,
988 const union sctp_subtype type
,
990 struct sctp_cmd_seq
*commands
)
992 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
994 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
995 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
996 SCTP_ERROR(ETIMEDOUT
));
997 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
998 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
999 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
1000 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
1001 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
1002 return SCTP_DISPOSITION_DELETE_TCB
;
1006 * The Sender-specific Heartbeat Info field should normally include
1007 * information about the sender's current time when this HEARTBEAT
1008 * chunk is sent and the destination transport address to which this
1009 * HEARTBEAT is sent (see Section 8.3).
1012 if (transport
->param_flags
& SPP_HB_ENABLE
) {
1013 if (SCTP_DISPOSITION_NOMEM
==
1014 sctp_sf_heartbeat(ep
, asoc
, type
, arg
,
1016 return SCTP_DISPOSITION_NOMEM
;
1018 /* Set transport error counter and association error counter
1019 * when sending heartbeat.
1021 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
1022 SCTP_TRANSPORT(transport
));
1024 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_IDLE
,
1025 SCTP_TRANSPORT(transport
));
1026 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMER_UPDATE
,
1027 SCTP_TRANSPORT(transport
));
1029 return SCTP_DISPOSITION_CONSUME
;
1032 /* resend asoc strreset_chunk. */
1033 enum sctp_disposition
sctp_sf_send_reconf(struct net
*net
,
1034 const struct sctp_endpoint
*ep
,
1035 const struct sctp_association
*asoc
,
1036 const union sctp_subtype type
,
1038 struct sctp_cmd_seq
*commands
)
1040 struct sctp_transport
*transport
= arg
;
1042 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
1043 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
1044 SCTP_ERROR(ETIMEDOUT
));
1045 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
1046 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
1047 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
1048 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
1049 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
1050 return SCTP_DISPOSITION_DELETE_TCB
;
1053 sctp_chunk_hold(asoc
->strreset_chunk
);
1054 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1055 SCTP_CHUNK(asoc
->strreset_chunk
));
1056 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
1058 return SCTP_DISPOSITION_CONSUME
;
1062 * Process an heartbeat request.
1064 * Section: 8.3 Path Heartbeat
1065 * The receiver of the HEARTBEAT should immediately respond with a
1066 * HEARTBEAT ACK that contains the Heartbeat Information field copied
1067 * from the received HEARTBEAT chunk.
1069 * Verification Tag: 8.5 Verification Tag [Normal verification]
1070 * When receiving an SCTP packet, the endpoint MUST ensure that the
1071 * value in the Verification Tag field of the received SCTP packet
1072 * matches its own Tag. If the received Verification Tag value does not
1073 * match the receiver's own tag value, the receiver shall silently
1074 * discard the packet and shall not process it any further except for
1075 * those cases listed in Section 8.5.1 below.
1078 * (endpoint, asoc, chunk)
1081 * (asoc, reply_msg, msg_up, timers, counters)
1083 * The return value is the disposition of the chunk.
1085 enum sctp_disposition
sctp_sf_beat_8_3(struct net
*net
,
1086 const struct sctp_endpoint
*ep
,
1087 const struct sctp_association
*asoc
,
1088 const union sctp_subtype type
,
1089 void *arg
, struct sctp_cmd_seq
*commands
)
1091 struct sctp_paramhdr
*param_hdr
;
1092 struct sctp_chunk
*chunk
= arg
;
1093 struct sctp_chunk
*reply
;
1096 if (!sctp_vtag_verify(chunk
, asoc
))
1097 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1099 /* Make sure that the HEARTBEAT chunk has a valid length. */
1100 if (!sctp_chunk_length_valid(chunk
,
1101 sizeof(struct sctp_heartbeat_chunk
)))
1102 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1105 /* 8.3 The receiver of the HEARTBEAT should immediately
1106 * respond with a HEARTBEAT ACK that contains the Heartbeat
1107 * Information field copied from the received HEARTBEAT chunk.
1109 chunk
->subh
.hb_hdr
= (struct sctp_heartbeathdr
*)chunk
->skb
->data
;
1110 param_hdr
= (struct sctp_paramhdr
*)chunk
->subh
.hb_hdr
;
1111 paylen
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(struct sctp_chunkhdr
);
1113 if (ntohs(param_hdr
->length
) > paylen
)
1114 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
1115 param_hdr
, commands
);
1117 if (!pskb_pull(chunk
->skb
, paylen
))
1120 reply
= sctp_make_heartbeat_ack(asoc
, chunk
, param_hdr
, paylen
);
1124 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
1125 return SCTP_DISPOSITION_CONSUME
;
1128 return SCTP_DISPOSITION_NOMEM
;
1132 * Process the returning HEARTBEAT ACK.
1134 * Section: 8.3 Path Heartbeat
1135 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
1136 * should clear the error counter of the destination transport
1137 * address to which the HEARTBEAT was sent, and mark the destination
1138 * transport address as active if it is not so marked. The endpoint may
1139 * optionally report to the upper layer when an inactive destination
1140 * address is marked as active due to the reception of the latest
1141 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
1142 * clear the association overall error count as well (as defined
1145 * The receiver of the HEARTBEAT ACK should also perform an RTT
1146 * measurement for that destination transport address using the time
1147 * value carried in the HEARTBEAT ACK chunk.
1149 * Verification Tag: 8.5 Verification Tag [Normal verification]
1152 * (endpoint, asoc, chunk)
1155 * (asoc, reply_msg, msg_up, timers, counters)
1157 * The return value is the disposition of the chunk.
1159 enum sctp_disposition
sctp_sf_backbeat_8_3(struct net
*net
,
1160 const struct sctp_endpoint
*ep
,
1161 const struct sctp_association
*asoc
,
1162 const union sctp_subtype type
,
1164 struct sctp_cmd_seq
*commands
)
1166 struct sctp_sender_hb_info
*hbinfo
;
1167 struct sctp_chunk
*chunk
= arg
;
1168 struct sctp_transport
*link
;
1169 unsigned long max_interval
;
1170 union sctp_addr from_addr
;
1172 if (!sctp_vtag_verify(chunk
, asoc
))
1173 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1175 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1176 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
) +
1178 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1181 hbinfo
= (struct sctp_sender_hb_info
*)chunk
->skb
->data
;
1182 /* Make sure that the length of the parameter is what we expect */
1183 if (ntohs(hbinfo
->param_hdr
.length
) != sizeof(*hbinfo
))
1184 return SCTP_DISPOSITION_DISCARD
;
1186 from_addr
= hbinfo
->daddr
;
1187 link
= sctp_assoc_lookup_paddr(asoc
, &from_addr
);
1189 /* This should never happen, but lets log it if so. */
1190 if (unlikely(!link
)) {
1191 if (from_addr
.sa
.sa_family
== AF_INET6
) {
1192 net_warn_ratelimited("%s association %p could not find address %pI6\n",
1195 &from_addr
.v6
.sin6_addr
);
1197 net_warn_ratelimited("%s association %p could not find address %pI4\n",
1200 &from_addr
.v4
.sin_addr
.s_addr
);
1202 return SCTP_DISPOSITION_DISCARD
;
1205 /* Validate the 64-bit random nonce. */
1206 if (hbinfo
->hb_nonce
!= link
->hb_nonce
)
1207 return SCTP_DISPOSITION_DISCARD
;
1209 max_interval
= link
->hbinterval
+ link
->rto
;
1211 /* Check if the timestamp looks valid. */
1212 if (time_after(hbinfo
->sent_at
, jiffies
) ||
1213 time_after(jiffies
, hbinfo
->sent_at
+ max_interval
)) {
1214 pr_debug("%s: HEARTBEAT ACK with invalid timestamp received "
1215 "for transport:%p\n", __func__
, link
);
1217 return SCTP_DISPOSITION_DISCARD
;
1220 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1221 * the HEARTBEAT should clear the error counter of the
1222 * destination transport address to which the HEARTBEAT was
1223 * sent and mark the destination transport address as active if
1224 * it is not so marked.
1226 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_ON
, SCTP_TRANSPORT(link
));
1228 return SCTP_DISPOSITION_CONSUME
;
1231 /* Helper function to send out an abort for the restart
1234 static int sctp_sf_send_restart_abort(struct net
*net
, union sctp_addr
*ssa
,
1235 struct sctp_chunk
*init
,
1236 struct sctp_cmd_seq
*commands
)
1238 struct sctp_af
*af
= sctp_get_af_specific(ssa
->v4
.sin_family
);
1239 union sctp_addr_param
*addrparm
;
1240 struct sctp_errhdr
*errhdr
;
1241 char buffer
[sizeof(*errhdr
) + sizeof(*addrparm
)];
1242 struct sctp_endpoint
*ep
;
1243 struct sctp_packet
*pkt
;
1246 /* Build the error on the stack. We are way to malloc crazy
1247 * throughout the code today.
1249 errhdr
= (struct sctp_errhdr
*)buffer
;
1250 addrparm
= (union sctp_addr_param
*)errhdr
->variable
;
1252 /* Copy into a parm format. */
1253 len
= af
->to_addr_param(ssa
, addrparm
);
1254 len
+= sizeof(*errhdr
);
1256 errhdr
->cause
= SCTP_ERROR_RESTART
;
1257 errhdr
->length
= htons(len
);
1259 /* Assign to the control socket. */
1260 ep
= sctp_sk(net
->sctp
.ctl_sock
)->ep
;
1262 /* Association is NULL since this may be a restart attack and we
1263 * want to send back the attacker's vtag.
1265 pkt
= sctp_abort_pkt_new(net
, ep
, NULL
, init
, errhdr
, len
);
1269 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
, SCTP_PACKET(pkt
));
1271 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
1273 /* Discard the rest of the inbound packet. */
1274 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
1277 /* Even if there is no memory, treat as a failure so
1278 * the packet will get dropped.
1283 static bool list_has_sctp_addr(const struct list_head
*list
,
1284 union sctp_addr
*ipaddr
)
1286 struct sctp_transport
*addr
;
1288 list_for_each_entry(addr
, list
, transports
) {
1289 if (sctp_cmp_addr_exact(ipaddr
, &addr
->ipaddr
))
1295 /* A restart is occurring, check to make sure no new addresses
1296 * are being added as we may be under a takeover attack.
1298 static int sctp_sf_check_restart_addrs(const struct sctp_association
*new_asoc
,
1299 const struct sctp_association
*asoc
,
1300 struct sctp_chunk
*init
,
1301 struct sctp_cmd_seq
*commands
)
1303 struct net
*net
= sock_net(new_asoc
->base
.sk
);
1304 struct sctp_transport
*new_addr
;
1307 /* Implementor's Guide - Section 5.2.2
1309 * Before responding the endpoint MUST check to see if the
1310 * unexpected INIT adds new addresses to the association. If new
1311 * addresses are added to the association, the endpoint MUST respond
1315 /* Search through all current addresses and make sure
1316 * we aren't adding any new ones.
1318 list_for_each_entry(new_addr
, &new_asoc
->peer
.transport_addr_list
,
1320 if (!list_has_sctp_addr(&asoc
->peer
.transport_addr_list
,
1321 &new_addr
->ipaddr
)) {
1322 sctp_sf_send_restart_abort(net
, &new_addr
->ipaddr
, init
,
1329 /* Return success if all addresses were found. */
1333 /* Populate the verification/tie tags based on overlapping INIT
1336 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1338 static void sctp_tietags_populate(struct sctp_association
*new_asoc
,
1339 const struct sctp_association
*asoc
)
1341 switch (asoc
->state
) {
1343 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1345 case SCTP_STATE_COOKIE_WAIT
:
1346 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1347 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1348 new_asoc
->c
.peer_ttag
= 0;
1351 case SCTP_STATE_COOKIE_ECHOED
:
1352 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1353 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1354 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1357 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1358 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1361 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1362 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1366 /* Other parameters for the endpoint SHOULD be copied from the
1367 * existing parameters of the association (e.g. number of
1368 * outbound streams) into the INIT ACK and cookie.
1370 new_asoc
->rwnd
= asoc
->rwnd
;
1371 new_asoc
->c
.sinit_num_ostreams
= asoc
->c
.sinit_num_ostreams
;
1372 new_asoc
->c
.sinit_max_instreams
= asoc
->c
.sinit_max_instreams
;
1373 new_asoc
->c
.initial_tsn
= asoc
->c
.initial_tsn
;
1377 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1380 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1382 * Returns value representing action to be taken. These action values
1383 * correspond to Action/Description values in RFC 2960, Table 2.
1385 static char sctp_tietags_compare(struct sctp_association
*new_asoc
,
1386 const struct sctp_association
*asoc
)
1388 /* In this case, the peer may have restarted. */
1389 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1390 (asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) &&
1391 (asoc
->c
.my_vtag
== new_asoc
->c
.my_ttag
) &&
1392 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_ttag
))
1395 /* Collision case B. */
1396 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1397 ((asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) ||
1398 (0 == asoc
->c
.peer_vtag
))) {
1402 /* Collision case D. */
1403 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1404 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
))
1407 /* Collision case C. */
1408 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1409 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
) &&
1410 (0 == new_asoc
->c
.my_ttag
) &&
1411 (0 == new_asoc
->c
.peer_ttag
))
1414 /* No match to any of the special cases; discard this packet. */
1418 /* Common helper routine for both duplicate and simulataneous INIT
1421 static enum sctp_disposition
sctp_sf_do_unexpected_init(
1423 const struct sctp_endpoint
*ep
,
1424 const struct sctp_association
*asoc
,
1425 const union sctp_subtype type
,
1427 struct sctp_cmd_seq
*commands
)
1429 struct sctp_chunk
*chunk
= arg
, *repl
, *err_chunk
;
1430 struct sctp_unrecognized_param
*unk_param
;
1431 struct sctp_association
*new_asoc
;
1432 enum sctp_disposition retval
;
1433 struct sctp_packet
*packet
;
1437 * An endpoint MUST NOT bundle INIT, INIT ACK or
1438 * SHUTDOWN COMPLETE with any other chunks.
1441 * Furthermore, we require that the receiver of an INIT chunk MUST
1442 * enforce these rules by silently discarding an arriving packet
1443 * with an INIT chunk that is bundled with other chunks.
1445 if (!chunk
->singleton
)
1446 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1448 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1451 if (chunk
->sctp_hdr
->vtag
!= 0)
1452 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
1454 /* Make sure that the INIT chunk has a valid length.
1455 * In this case, we generate a protocol violation since we have
1456 * an association established.
1458 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_init_chunk
)))
1459 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1461 /* Grab the INIT header. */
1462 chunk
->subh
.init_hdr
= (struct sctp_inithdr
*)chunk
->skb
->data
;
1464 /* Tag the variable length parameters. */
1465 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(struct sctp_inithdr
));
1467 /* Verify the INIT chunk before processing it. */
1469 if (!sctp_verify_init(net
, ep
, asoc
, chunk
->chunk_hdr
->type
,
1470 (struct sctp_init_chunk
*)chunk
->chunk_hdr
, chunk
,
1472 /* This chunk contains fatal error. It is to be discarded.
1473 * Send an ABORT, with causes if there is any.
1476 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
1477 (__u8
*)(err_chunk
->chunk_hdr
) +
1478 sizeof(struct sctp_chunkhdr
),
1479 ntohs(err_chunk
->chunk_hdr
->length
) -
1480 sizeof(struct sctp_chunkhdr
));
1483 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
1484 SCTP_PACKET(packet
));
1485 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
1486 retval
= SCTP_DISPOSITION_CONSUME
;
1488 retval
= SCTP_DISPOSITION_NOMEM
;
1492 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
,
1498 * Other parameters for the endpoint SHOULD be copied from the
1499 * existing parameters of the association (e.g. number of
1500 * outbound streams) into the INIT ACK and cookie.
1501 * FIXME: We are copying parameters from the endpoint not the
1504 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
1508 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
,
1509 sctp_scope(sctp_source(chunk
)), GFP_ATOMIC
) < 0)
1512 /* In the outbound INIT ACK the endpoint MUST copy its current
1513 * Verification Tag and Peers Verification tag into a reserved
1514 * place (local tie-tag and per tie-tag) within the state cookie.
1516 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
),
1517 (struct sctp_init_chunk
*)chunk
->chunk_hdr
,
1521 /* Make sure no new addresses are being added during the
1522 * restart. Do not do this check for COOKIE-WAIT state,
1523 * since there are no peer addresses to check against.
1524 * Upon return an ABORT will have been sent if needed.
1526 if (!sctp_state(asoc
, COOKIE_WAIT
)) {
1527 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
,
1529 retval
= SCTP_DISPOSITION_CONSUME
;
1534 sctp_tietags_populate(new_asoc
, asoc
);
1536 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1538 /* If there are errors need to be reported for unknown parameters,
1539 * make sure to reserve enough room in the INIT ACK for them.
1543 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
1544 sizeof(struct sctp_chunkhdr
);
1547 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
1551 /* If there are errors need to be reported for unknown parameters,
1552 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1556 /* Get the "Unrecognized parameter" parameter(s) out of the
1557 * ERROR chunk generated by sctp_verify_init(). Since the
1558 * error cause code for "unknown parameter" and the
1559 * "Unrecognized parameter" type is the same, we can
1560 * construct the parameters in INIT ACK by copying the
1561 * ERROR causes over.
1563 unk_param
= (struct sctp_unrecognized_param
*)
1564 ((__u8
*)(err_chunk
->chunk_hdr
) +
1565 sizeof(struct sctp_chunkhdr
));
1566 /* Replace the cause code with the "Unrecognized parameter"
1569 sctp_addto_chunk(repl
, len
, unk_param
);
1572 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
1573 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1576 * Note: After sending out INIT ACK with the State Cookie parameter,
1577 * "Z" MUST NOT allocate any resources for this new association.
1578 * Otherwise, "Z" will be vulnerable to resource attacks.
1580 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
1581 retval
= SCTP_DISPOSITION_CONSUME
;
1586 retval
= SCTP_DISPOSITION_NOMEM
;
1589 sctp_association_free(new_asoc
);
1592 sctp_chunk_free(err_chunk
);
1597 * Handle simultaneous INIT.
1598 * This means we started an INIT and then we got an INIT request from
1601 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1602 * This usually indicates an initialization collision, i.e., each
1603 * endpoint is attempting, at about the same time, to establish an
1604 * association with the other endpoint.
1606 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1607 * endpoint MUST respond with an INIT ACK using the same parameters it
1608 * sent in its original INIT chunk (including its Verification Tag,
1609 * unchanged). These original parameters are combined with those from the
1610 * newly received INIT chunk. The endpoint shall also generate a State
1611 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1612 * INIT to calculate the State Cookie.
1614 * After that, the endpoint MUST NOT change its state, the T1-init
1615 * timer shall be left running and the corresponding TCB MUST NOT be
1616 * destroyed. The normal procedures for handling State Cookies when
1617 * a TCB exists will resolve the duplicate INITs to a single association.
1619 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1620 * its Tie-Tags with the Tag information of itself and its peer (see
1621 * section 5.2.2 for a description of the Tie-Tags).
1623 * Verification Tag: Not explicit, but an INIT can not have a valid
1624 * verification tag, so we skip the check.
1627 * (endpoint, asoc, chunk)
1630 * (asoc, reply_msg, msg_up, timers, counters)
1632 * The return value is the disposition of the chunk.
1634 enum sctp_disposition
sctp_sf_do_5_2_1_siminit(
1636 const struct sctp_endpoint
*ep
,
1637 const struct sctp_association
*asoc
,
1638 const union sctp_subtype type
,
1640 struct sctp_cmd_seq
*commands
)
1642 /* Call helper to do the real work for both simulataneous and
1643 * duplicate INIT chunk handling.
1645 return sctp_sf_do_unexpected_init(net
, ep
, asoc
, type
, arg
, commands
);
1649 * Handle duplicated INIT messages. These are usually delayed
1652 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1653 * COOKIE-ECHOED and COOKIE-WAIT
1655 * Unless otherwise stated, upon reception of an unexpected INIT for
1656 * this association, the endpoint shall generate an INIT ACK with a
1657 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1658 * current Verification Tag and peer's Verification Tag into a reserved
1659 * place within the state cookie. We shall refer to these locations as
1660 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1661 * containing this INIT ACK MUST carry a Verification Tag value equal to
1662 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1663 * MUST contain a new Initiation Tag (randomly generated see Section
1664 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1665 * existing parameters of the association (e.g. number of outbound
1666 * streams) into the INIT ACK and cookie.
1668 * After sending out the INIT ACK, the endpoint shall take no further
1669 * actions, i.e., the existing association, including its current state,
1670 * and the corresponding TCB MUST NOT be changed.
1672 * Note: Only when a TCB exists and the association is not in a COOKIE-
1673 * WAIT state are the Tie-Tags populated. For a normal association INIT
1674 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1675 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1676 * State Cookie are populated as specified in section 5.2.1.
1678 * Verification Tag: Not specified, but an INIT has no way of knowing
1679 * what the verification tag could be, so we ignore it.
1682 * (endpoint, asoc, chunk)
1685 * (asoc, reply_msg, msg_up, timers, counters)
1687 * The return value is the disposition of the chunk.
1689 enum sctp_disposition
sctp_sf_do_5_2_2_dupinit(
1691 const struct sctp_endpoint
*ep
,
1692 const struct sctp_association
*asoc
,
1693 const union sctp_subtype type
,
1695 struct sctp_cmd_seq
*commands
)
1697 /* Call helper to do the real work for both simulataneous and
1698 * duplicate INIT chunk handling.
1700 return sctp_sf_do_unexpected_init(net
, ep
, asoc
, type
, arg
, commands
);
1705 * Unexpected INIT-ACK handler.
1708 * If an INIT ACK received by an endpoint in any state other than the
1709 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1710 * An unexpected INIT ACK usually indicates the processing of an old or
1711 * duplicated INIT chunk.
1713 enum sctp_disposition
sctp_sf_do_5_2_3_initack(
1715 const struct sctp_endpoint
*ep
,
1716 const struct sctp_association
*asoc
,
1717 const union sctp_subtype type
,
1719 struct sctp_cmd_seq
*commands
)
1721 /* Per the above section, we'll discard the chunk if we have an
1722 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1724 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
)
1725 return sctp_sf_ootb(net
, ep
, asoc
, type
, arg
, commands
);
1727 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
1730 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1733 * A) In this case, the peer may have restarted.
1735 static enum sctp_disposition
sctp_sf_do_dupcook_a(
1737 const struct sctp_endpoint
*ep
,
1738 const struct sctp_association
*asoc
,
1739 struct sctp_chunk
*chunk
,
1740 struct sctp_cmd_seq
*commands
,
1741 struct sctp_association
*new_asoc
)
1743 struct sctp_init_chunk
*peer_init
;
1744 enum sctp_disposition disposition
;
1745 struct sctp_ulpevent
*ev
;
1746 struct sctp_chunk
*repl
;
1747 struct sctp_chunk
*err
;
1749 /* new_asoc is a brand-new association, so these are not yet
1750 * side effects--it is safe to run them here.
1752 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1754 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
), peer_init
,
1758 /* Make sure no new addresses are being added during the
1759 * restart. Though this is a pretty complicated attack
1760 * since you'd have to get inside the cookie.
1762 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
, commands
)) {
1763 return SCTP_DISPOSITION_CONSUME
;
1766 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1767 * the peer has restarted (Action A), it MUST NOT setup a new
1768 * association but instead resend the SHUTDOWN ACK and send an ERROR
1769 * chunk with a "Cookie Received while Shutting Down" error cause to
1772 if (sctp_state(asoc
, SHUTDOWN_ACK_SENT
)) {
1773 disposition
= sctp_sf_do_9_2_reshutack(net
, ep
, asoc
,
1774 SCTP_ST_CHUNK(chunk
->chunk_hdr
->type
),
1776 if (SCTP_DISPOSITION_NOMEM
== disposition
)
1779 err
= sctp_make_op_error(asoc
, chunk
,
1780 SCTP_ERROR_COOKIE_IN_SHUTDOWN
,
1783 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1786 return SCTP_DISPOSITION_CONSUME
;
1789 /* For now, stop pending T3-rtx and SACK timers, fail any unsent/unacked
1790 * data. Consider the optional choice of resending of this data.
1792 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
1793 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1794 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK
));
1795 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_OUTQUEUE
, SCTP_NULL());
1797 /* Stop pending T4-rto timer, teardown ASCONF queue, ASCONF-ACK queue
1798 * and ASCONF-ACK cache.
1800 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1801 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
1802 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_ASCONF_QUEUE
, SCTP_NULL());
1804 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1808 /* Report association restart to upper layer. */
1809 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_RESTART
, 0,
1810 new_asoc
->c
.sinit_num_ostreams
,
1811 new_asoc
->c
.sinit_max_instreams
,
1816 /* Update the content of current association. */
1817 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1818 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
1819 if (sctp_state(asoc
, SHUTDOWN_PENDING
) &&
1820 (sctp_sstate(asoc
->base
.sk
, CLOSING
) ||
1821 sock_flag(asoc
->base
.sk
, SOCK_DEAD
))) {
1822 /* if were currently in SHUTDOWN_PENDING, but the socket
1823 * has been closed by user, don't transition to ESTABLISHED.
1824 * Instead trigger SHUTDOWN bundled with COOKIE_ACK.
1826 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1827 return sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
,
1828 SCTP_ST_CHUNK(0), NULL
,
1831 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1832 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1833 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1835 return SCTP_DISPOSITION_CONSUME
;
1838 sctp_chunk_free(repl
);
1840 return SCTP_DISPOSITION_NOMEM
;
1843 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1846 * B) In this case, both sides may be attempting to start an association
1847 * at about the same time but the peer endpoint started its INIT
1848 * after responding to the local endpoint's INIT
1850 /* This case represents an initialization collision. */
1851 static enum sctp_disposition
sctp_sf_do_dupcook_b(
1853 const struct sctp_endpoint
*ep
,
1854 const struct sctp_association
*asoc
,
1855 struct sctp_chunk
*chunk
,
1856 struct sctp_cmd_seq
*commands
,
1857 struct sctp_association
*new_asoc
)
1859 struct sctp_init_chunk
*peer_init
;
1860 struct sctp_chunk
*repl
;
1862 /* new_asoc is a brand-new association, so these are not yet
1863 * side effects--it is safe to run them here.
1865 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1866 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
), peer_init
,
1870 /* Update the content of current association. */
1871 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1872 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1873 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1874 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
1875 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
1877 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1881 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1883 /* RFC 2960 5.1 Normal Establishment of an Association
1885 * D) IMPLEMENTATION NOTE: An implementation may choose to
1886 * send the Communication Up notification to the SCTP user
1887 * upon reception of a valid COOKIE ECHO chunk.
1889 * Sadly, this needs to be implemented as a side-effect, because
1890 * we are not guaranteed to have set the association id of the real
1891 * association and so these notifications need to be delayed until
1892 * the association id is allocated.
1895 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_CHANGE
, SCTP_U8(SCTP_COMM_UP
));
1897 /* Sockets API Draft Section 5.3.1.6
1898 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1899 * delivers this notification to inform the application that of the
1900 * peers requested adaptation layer.
1902 * This also needs to be done as a side effect for the same reason as
1905 if (asoc
->peer
.adaptation_ind
)
1906 sctp_add_cmd_sf(commands
, SCTP_CMD_ADAPTATION_IND
, SCTP_NULL());
1908 return SCTP_DISPOSITION_CONSUME
;
1911 return SCTP_DISPOSITION_NOMEM
;
1914 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1917 * C) In this case, the local endpoint's cookie has arrived late.
1918 * Before it arrived, the local endpoint sent an INIT and received an
1919 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1920 * but a new tag of its own.
1922 /* This case represents an initialization collision. */
1923 static enum sctp_disposition
sctp_sf_do_dupcook_c(
1925 const struct sctp_endpoint
*ep
,
1926 const struct sctp_association
*asoc
,
1927 struct sctp_chunk
*chunk
,
1928 struct sctp_cmd_seq
*commands
,
1929 struct sctp_association
*new_asoc
)
1931 /* The cookie should be silently discarded.
1932 * The endpoint SHOULD NOT change states and should leave
1933 * any timers running.
1935 return SCTP_DISPOSITION_DISCARD
;
1938 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1942 * D) When both local and remote tags match the endpoint should always
1943 * enter the ESTABLISHED state, if it has not already done so.
1945 /* This case represents an initialization collision. */
1946 static enum sctp_disposition
sctp_sf_do_dupcook_d(
1948 const struct sctp_endpoint
*ep
,
1949 const struct sctp_association
*asoc
,
1950 struct sctp_chunk
*chunk
,
1951 struct sctp_cmd_seq
*commands
,
1952 struct sctp_association
*new_asoc
)
1954 struct sctp_ulpevent
*ev
= NULL
, *ai_ev
= NULL
;
1955 struct sctp_chunk
*repl
;
1957 /* Clarification from Implementor's Guide:
1958 * D) When both local and remote tags match the endpoint should
1959 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1960 * It should stop any cookie timer that may be running and send
1964 /* Don't accidentally move back into established state. */
1965 if (asoc
->state
< SCTP_STATE_ESTABLISHED
) {
1966 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1967 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
1968 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1969 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1970 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
1971 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
,
1974 /* RFC 2960 5.1 Normal Establishment of an Association
1976 * D) IMPLEMENTATION NOTE: An implementation may choose
1977 * to send the Communication Up notification to the
1978 * SCTP user upon reception of a valid COOKIE
1981 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0,
1983 asoc
->c
.sinit_num_ostreams
,
1984 asoc
->c
.sinit_max_instreams
,
1989 /* Sockets API Draft Section 5.3.1.6
1990 * When a peer sends a Adaptation Layer Indication parameter,
1991 * SCTP delivers this notification to inform the application
1992 * that of the peers requested adaptation layer.
1994 if (asoc
->peer
.adaptation_ind
) {
1995 ai_ev
= sctp_ulpevent_make_adaptation_indication(asoc
,
2003 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
2007 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
2010 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
2013 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
2014 SCTP_ULPEVENT(ai_ev
));
2016 return SCTP_DISPOSITION_CONSUME
;
2020 sctp_ulpevent_free(ai_ev
);
2022 sctp_ulpevent_free(ev
);
2023 return SCTP_DISPOSITION_NOMEM
;
2027 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
2028 * chunk was retransmitted and then delayed in the network.
2030 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
2032 * Verification Tag: None. Do cookie validation.
2035 * (endpoint, asoc, chunk)
2038 * (asoc, reply_msg, msg_up, timers, counters)
2040 * The return value is the disposition of the chunk.
2042 enum sctp_disposition
sctp_sf_do_5_2_4_dupcook(
2044 const struct sctp_endpoint
*ep
,
2045 const struct sctp_association
*asoc
,
2046 const union sctp_subtype type
,
2048 struct sctp_cmd_seq
*commands
)
2050 struct sctp_association
*new_asoc
;
2051 struct sctp_chunk
*chunk
= arg
;
2052 enum sctp_disposition retval
;
2053 struct sctp_chunk
*err_chk_p
;
2057 /* Make sure that the chunk has a valid length from the protocol
2058 * perspective. In this case check to make sure we have at least
2059 * enough for the chunk header. Cookie length verification is
2062 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
2063 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2066 /* "Decode" the chunk. We have no optional parameters so we
2067 * are in good shape.
2069 chunk
->subh
.cookie_hdr
= (struct sctp_signed_cookie
*)chunk
->skb
->data
;
2070 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
2071 sizeof(struct sctp_chunkhdr
)))
2074 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
2075 * of a duplicate COOKIE ECHO match the Verification Tags of the
2076 * current association, consider the State Cookie valid even if
2077 * the lifespan is exceeded.
2079 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
2083 * If the re-build failed, what is the proper error path
2086 * [We should abort the association. --piggy]
2089 /* FIXME: Several errors are possible. A bad cookie should
2090 * be silently discarded, but think about logging it too.
2093 case -SCTP_IERROR_NOMEM
:
2096 case -SCTP_IERROR_STALE_COOKIE
:
2097 sctp_send_stale_cookie_err(net
, ep
, asoc
, chunk
, commands
,
2099 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2100 case -SCTP_IERROR_BAD_SIG
:
2102 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2106 /* Set temp so that it won't be added into hashtable */
2109 /* Compare the tie_tag in cookie with the verification tag of
2110 * current association.
2112 action
= sctp_tietags_compare(new_asoc
, asoc
);
2115 case 'A': /* Association restart. */
2116 retval
= sctp_sf_do_dupcook_a(net
, ep
, asoc
, chunk
, commands
,
2120 case 'B': /* Collision case B. */
2121 retval
= sctp_sf_do_dupcook_b(net
, ep
, asoc
, chunk
, commands
,
2125 case 'C': /* Collision case C. */
2126 retval
= sctp_sf_do_dupcook_c(net
, ep
, asoc
, chunk
, commands
,
2130 case 'D': /* Collision case D. */
2131 retval
= sctp_sf_do_dupcook_d(net
, ep
, asoc
, chunk
, commands
,
2135 default: /* Discard packet for all others. */
2136 retval
= sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2140 /* Delete the tempory new association. */
2141 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_ASOC
, SCTP_ASOC(new_asoc
));
2142 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
2144 /* Restore association pointer to provide SCTP command interpeter
2145 * with a valid context in case it needs to manipulate
2147 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_ASOC
,
2148 SCTP_ASOC((struct sctp_association
*)asoc
));
2153 return SCTP_DISPOSITION_NOMEM
;
2157 * Process an ABORT. (SHUTDOWN-PENDING state)
2159 * See sctp_sf_do_9_1_abort().
2161 enum sctp_disposition
sctp_sf_shutdown_pending_abort(
2163 const struct sctp_endpoint
*ep
,
2164 const struct sctp_association
*asoc
,
2165 const union sctp_subtype type
,
2167 struct sctp_cmd_seq
*commands
)
2169 struct sctp_chunk
*chunk
= arg
;
2171 if (!sctp_vtag_verify_either(chunk
, asoc
))
2172 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2174 /* Make sure that the ABORT chunk has a valid length.
2175 * Since this is an ABORT chunk, we have to discard it
2176 * because of the following text:
2177 * RFC 2960, Section 3.3.7
2178 * If an endpoint receives an ABORT with a format error or for an
2179 * association that doesn't exist, it MUST silently discard it.
2180 * Because the length is "invalid", we can't really discard just
2181 * as we do not know its true length. So, to be safe, discard the
2184 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_abort_chunk
)))
2185 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2187 /* ADD-IP: Special case for ABORT chunks
2188 * F4) One special consideration is that ABORT Chunks arriving
2189 * destined to the IP address being deleted MUST be
2190 * ignored (see Section 5.3.1 for further details).
2192 if (SCTP_ADDR_DEL
==
2193 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2194 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2196 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2200 * Process an ABORT. (SHUTDOWN-SENT state)
2202 * See sctp_sf_do_9_1_abort().
2204 enum sctp_disposition
sctp_sf_shutdown_sent_abort(
2206 const struct sctp_endpoint
*ep
,
2207 const struct sctp_association
*asoc
,
2208 const union sctp_subtype type
,
2210 struct sctp_cmd_seq
*commands
)
2212 struct sctp_chunk
*chunk
= arg
;
2214 if (!sctp_vtag_verify_either(chunk
, asoc
))
2215 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2217 /* Make sure that the ABORT chunk has a valid length.
2218 * Since this is an ABORT chunk, we have to discard it
2219 * because of the following text:
2220 * RFC 2960, Section 3.3.7
2221 * If an endpoint receives an ABORT with a format error or for an
2222 * association that doesn't exist, it MUST silently discard it.
2223 * Because the length is "invalid", we can't really discard just
2224 * as we do not know its true length. So, to be safe, discard the
2227 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_abort_chunk
)))
2228 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2230 /* ADD-IP: Special case for ABORT chunks
2231 * F4) One special consideration is that ABORT Chunks arriving
2232 * destined to the IP address being deleted MUST be
2233 * ignored (see Section 5.3.1 for further details).
2235 if (SCTP_ADDR_DEL
==
2236 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2237 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2239 /* Stop the T2-shutdown timer. */
2240 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2241 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2243 /* Stop the T5-shutdown guard timer. */
2244 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2245 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
2247 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2251 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2253 * See sctp_sf_do_9_1_abort().
2255 enum sctp_disposition
sctp_sf_shutdown_ack_sent_abort(
2257 const struct sctp_endpoint
*ep
,
2258 const struct sctp_association
*asoc
,
2259 const union sctp_subtype type
,
2261 struct sctp_cmd_seq
*commands
)
2263 /* The same T2 timer, so we should be able to use
2264 * common function with the SHUTDOWN-SENT state.
2266 return sctp_sf_shutdown_sent_abort(net
, ep
, asoc
, type
, arg
, commands
);
2270 * Handle an Error received in COOKIE_ECHOED state.
2272 * Only handle the error type of stale COOKIE Error, the other errors will
2276 * (endpoint, asoc, chunk)
2279 * (asoc, reply_msg, msg_up, timers, counters)
2281 * The return value is the disposition of the chunk.
2283 enum sctp_disposition
sctp_sf_cookie_echoed_err(
2285 const struct sctp_endpoint
*ep
,
2286 const struct sctp_association
*asoc
,
2287 const union sctp_subtype type
,
2289 struct sctp_cmd_seq
*commands
)
2291 struct sctp_chunk
*chunk
= arg
;
2292 struct sctp_errhdr
*err
;
2294 if (!sctp_vtag_verify(chunk
, asoc
))
2295 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2297 /* Make sure that the ERROR chunk has a valid length.
2298 * The parameter walking depends on this as well.
2300 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_operr_chunk
)))
2301 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2304 /* Process the error here */
2305 /* FUTURE FIXME: When PR-SCTP related and other optional
2306 * parms are emitted, this will have to change to handle multiple
2309 sctp_walk_errors(err
, chunk
->chunk_hdr
) {
2310 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
)
2311 return sctp_sf_do_5_2_6_stale(net
, ep
, asoc
, type
,
2315 /* It is possible to have malformed error causes, and that
2316 * will cause us to end the walk early. However, since
2317 * we are discarding the packet, there should be no adverse
2320 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2324 * Handle a Stale COOKIE Error
2326 * Section: 5.2.6 Handle Stale COOKIE Error
2327 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2328 * one of the following three alternatives.
2330 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2331 * Preservative parameter requesting an extension to the lifetime of
2332 * the State Cookie. When calculating the time extension, an
2333 * implementation SHOULD use the RTT information measured based on the
2334 * previous COOKIE ECHO / ERROR exchange, and should add no more
2335 * than 1 second beyond the measured RTT, due to long State Cookie
2336 * lifetimes making the endpoint more subject to a replay attack.
2338 * Verification Tag: Not explicit, but safe to ignore.
2341 * (endpoint, asoc, chunk)
2344 * (asoc, reply_msg, msg_up, timers, counters)
2346 * The return value is the disposition of the chunk.
2348 static enum sctp_disposition
sctp_sf_do_5_2_6_stale(
2350 const struct sctp_endpoint
*ep
,
2351 const struct sctp_association
*asoc
,
2352 const union sctp_subtype type
,
2354 struct sctp_cmd_seq
*commands
)
2356 int attempts
= asoc
->init_err_counter
+ 1;
2357 struct sctp_chunk
*chunk
= arg
, *reply
;
2358 struct sctp_cookie_preserve_param bht
;
2359 struct sctp_bind_addr
*bp
;
2360 struct sctp_errhdr
*err
;
2363 if (attempts
> asoc
->max_init_attempts
) {
2364 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
2365 SCTP_ERROR(ETIMEDOUT
));
2366 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2367 SCTP_PERR(SCTP_ERROR_STALE_COOKIE
));
2368 return SCTP_DISPOSITION_DELETE_TCB
;
2371 err
= (struct sctp_errhdr
*)(chunk
->skb
->data
);
2373 /* When calculating the time extension, an implementation
2374 * SHOULD use the RTT information measured based on the
2375 * previous COOKIE ECHO / ERROR exchange, and should add no
2376 * more than 1 second beyond the measured RTT, due to long
2377 * State Cookie lifetimes making the endpoint more subject to
2379 * Measure of Staleness's unit is usec. (1/1000000 sec)
2380 * Suggested Cookie Life-span Increment's unit is msec.
2382 * In general, if you use the suggested cookie life, the value
2383 * found in the field of measure of staleness should be doubled
2384 * to give ample time to retransmit the new cookie and thus
2385 * yield a higher probability of success on the reattempt.
2387 stale
= ntohl(*(__be32
*)((u8
*)err
+ sizeof(*err
)));
2388 stale
= (stale
* 2) / 1000;
2390 bht
.param_hdr
.type
= SCTP_PARAM_COOKIE_PRESERVATIVE
;
2391 bht
.param_hdr
.length
= htons(sizeof(bht
));
2392 bht
.lifespan_increment
= htonl(stale
);
2394 /* Build that new INIT chunk. */
2395 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
2396 reply
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, sizeof(bht
));
2400 sctp_addto_chunk(reply
, sizeof(bht
), &bht
);
2402 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2403 sctp_add_cmd_sf(commands
, SCTP_CMD_CLEAR_INIT_TAG
, SCTP_NULL());
2405 /* Stop pending T3-rtx and heartbeat timers */
2406 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
2407 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
2409 /* Delete non-primary peer ip addresses since we are transitioning
2410 * back to the COOKIE-WAIT state
2412 sctp_add_cmd_sf(commands
, SCTP_CMD_DEL_NON_PRIMARY
, SCTP_NULL());
2414 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2417 sctp_add_cmd_sf(commands
, SCTP_CMD_T1_RETRAN
,
2418 SCTP_TRANSPORT(asoc
->peer
.primary_path
));
2420 /* Cast away the const modifier, as we want to just
2421 * rerun it through as a sideffect.
2423 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_INC
, SCTP_NULL());
2425 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2426 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
2427 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2428 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
2429 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
2430 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2432 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2434 return SCTP_DISPOSITION_CONSUME
;
2437 return SCTP_DISPOSITION_NOMEM
;
2444 * After checking the Verification Tag, the receiving endpoint shall
2445 * remove the association from its record, and shall report the
2446 * termination to its upper layer.
2448 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2449 * B) Rules for packet carrying ABORT:
2451 * - The endpoint shall always fill in the Verification Tag field of the
2452 * outbound packet with the destination endpoint's tag value if it
2455 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2456 * MUST follow the procedure described in Section 8.4.
2458 * - The receiver MUST accept the packet if the Verification Tag
2459 * matches either its own tag, OR the tag of its peer. Otherwise, the
2460 * receiver MUST silently discard the packet and take no further
2464 * (endpoint, asoc, chunk)
2467 * (asoc, reply_msg, msg_up, timers, counters)
2469 * The return value is the disposition of the chunk.
2471 enum sctp_disposition
sctp_sf_do_9_1_abort(
2473 const struct sctp_endpoint
*ep
,
2474 const struct sctp_association
*asoc
,
2475 const union sctp_subtype type
,
2477 struct sctp_cmd_seq
*commands
)
2479 struct sctp_chunk
*chunk
= arg
;
2481 if (!sctp_vtag_verify_either(chunk
, asoc
))
2482 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2484 /* Make sure that the ABORT chunk has a valid length.
2485 * Since this is an ABORT chunk, we have to discard it
2486 * because of the following text:
2487 * RFC 2960, Section 3.3.7
2488 * If an endpoint receives an ABORT with a format error or for an
2489 * association that doesn't exist, it MUST silently discard it.
2490 * Because the length is "invalid", we can't really discard just
2491 * as we do not know its true length. So, to be safe, discard the
2494 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_abort_chunk
)))
2495 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2497 /* ADD-IP: Special case for ABORT chunks
2498 * F4) One special consideration is that ABORT Chunks arriving
2499 * destined to the IP address being deleted MUST be
2500 * ignored (see Section 5.3.1 for further details).
2502 if (SCTP_ADDR_DEL
==
2503 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2504 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2506 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2509 static enum sctp_disposition
__sctp_sf_do_9_1_abort(
2511 const struct sctp_endpoint
*ep
,
2512 const struct sctp_association
*asoc
,
2513 const union sctp_subtype type
,
2515 struct sctp_cmd_seq
*commands
)
2517 __be16 error
= SCTP_ERROR_NO_ERROR
;
2518 struct sctp_chunk
*chunk
= arg
;
2521 /* See if we have an error cause code in the chunk. */
2522 len
= ntohs(chunk
->chunk_hdr
->length
);
2523 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
)) {
2524 struct sctp_errhdr
*err
;
2526 sctp_walk_errors(err
, chunk
->chunk_hdr
);
2527 if ((void *)err
!= (void *)chunk
->chunk_end
)
2528 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
,
2531 error
= ((struct sctp_errhdr
*)chunk
->skb
->data
)->cause
;
2534 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(ECONNRESET
));
2535 /* ASSOC_FAILED will DELETE_TCB. */
2536 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
, SCTP_PERR(error
));
2537 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
2538 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
2540 return SCTP_DISPOSITION_ABORT
;
2544 * Process an ABORT. (COOKIE-WAIT state)
2546 * See sctp_sf_do_9_1_abort() above.
2548 enum sctp_disposition
sctp_sf_cookie_wait_abort(
2550 const struct sctp_endpoint
*ep
,
2551 const struct sctp_association
*asoc
,
2552 const union sctp_subtype type
,
2554 struct sctp_cmd_seq
*commands
)
2556 __be16 error
= SCTP_ERROR_NO_ERROR
;
2557 struct sctp_chunk
*chunk
= arg
;
2560 if (!sctp_vtag_verify_either(chunk
, asoc
))
2561 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2563 /* Make sure that the ABORT chunk has a valid length.
2564 * Since this is an ABORT chunk, we have to discard it
2565 * because of the following text:
2566 * RFC 2960, Section 3.3.7
2567 * If an endpoint receives an ABORT with a format error or for an
2568 * association that doesn't exist, it MUST silently discard it.
2569 * Because the length is "invalid", we can't really discard just
2570 * as we do not know its true length. So, to be safe, discard the
2573 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_abort_chunk
)))
2574 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2576 /* See if we have an error cause code in the chunk. */
2577 len
= ntohs(chunk
->chunk_hdr
->length
);
2578 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2579 error
= ((struct sctp_errhdr
*)chunk
->skb
->data
)->cause
;
2581 return sctp_stop_t1_and_abort(net
, commands
, error
, ECONNREFUSED
, asoc
,
2586 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2588 enum sctp_disposition
sctp_sf_cookie_wait_icmp_abort(
2590 const struct sctp_endpoint
*ep
,
2591 const struct sctp_association
*asoc
,
2592 const union sctp_subtype type
,
2594 struct sctp_cmd_seq
*commands
)
2596 return sctp_stop_t1_and_abort(net
, commands
, SCTP_ERROR_NO_ERROR
,
2598 (struct sctp_transport
*)arg
);
2602 * Process an ABORT. (COOKIE-ECHOED state)
2604 enum sctp_disposition
sctp_sf_cookie_echoed_abort(
2606 const struct sctp_endpoint
*ep
,
2607 const struct sctp_association
*asoc
,
2608 const union sctp_subtype type
,
2610 struct sctp_cmd_seq
*commands
)
2612 /* There is a single T1 timer, so we should be able to use
2613 * common function with the COOKIE-WAIT state.
2615 return sctp_sf_cookie_wait_abort(net
, ep
, asoc
, type
, arg
, commands
);
2619 * Stop T1 timer and abort association with "INIT failed".
2621 * This is common code called by several sctp_sf_*_abort() functions above.
2623 static enum sctp_disposition
sctp_stop_t1_and_abort(
2625 struct sctp_cmd_seq
*commands
,
2626 __be16 error
, int sk_err
,
2627 const struct sctp_association
*asoc
,
2628 struct sctp_transport
*transport
)
2630 pr_debug("%s: ABORT received (INIT)\n", __func__
);
2632 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2633 SCTP_STATE(SCTP_STATE_CLOSED
));
2634 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
2635 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2636 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2637 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(sk_err
));
2638 /* CMD_INIT_FAILED will DELETE_TCB. */
2639 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2642 return SCTP_DISPOSITION_ABORT
;
2646 * sctp_sf_do_9_2_shut
2649 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2650 * - enter the SHUTDOWN-RECEIVED state,
2652 * - stop accepting new data from its SCTP user
2654 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2655 * that all its outstanding DATA chunks have been received by the
2658 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2659 * send a SHUTDOWN in response to a ULP request. And should discard
2660 * subsequent SHUTDOWN chunks.
2662 * If there are still outstanding DATA chunks left, the SHUTDOWN
2663 * receiver shall continue to follow normal data transmission
2664 * procedures defined in Section 6 until all outstanding DATA chunks
2665 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2666 * new data from its SCTP user.
2668 * Verification Tag: 8.5 Verification Tag [Normal verification]
2671 * (endpoint, asoc, chunk)
2674 * (asoc, reply_msg, msg_up, timers, counters)
2676 * The return value is the disposition of the chunk.
2678 enum sctp_disposition
sctp_sf_do_9_2_shutdown(
2680 const struct sctp_endpoint
*ep
,
2681 const struct sctp_association
*asoc
,
2682 const union sctp_subtype type
,
2684 struct sctp_cmd_seq
*commands
)
2686 enum sctp_disposition disposition
;
2687 struct sctp_chunk
*chunk
= arg
;
2688 struct sctp_shutdownhdr
*sdh
;
2689 struct sctp_ulpevent
*ev
;
2692 if (!sctp_vtag_verify(chunk
, asoc
))
2693 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2695 /* Make sure that the SHUTDOWN chunk has a valid length. */
2696 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_shutdown_chunk
)))
2697 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2700 /* Convert the elaborate header. */
2701 sdh
= (struct sctp_shutdownhdr
*)chunk
->skb
->data
;
2702 skb_pull(chunk
->skb
, sizeof(*sdh
));
2703 chunk
->subh
.shutdown_hdr
= sdh
;
2704 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2706 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2707 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__
, ctsn
,
2708 asoc
->ctsn_ack_point
);
2710 return SCTP_DISPOSITION_DISCARD
;
2713 /* If Cumulative TSN Ack beyond the max tsn currently
2714 * send, terminating the association and respond to the
2715 * sender with an ABORT.
2717 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2718 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
2720 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2721 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2722 * inform the application that it should cease sending data.
2724 ev
= sctp_ulpevent_make_shutdown_event(asoc
, 0, GFP_ATOMIC
);
2726 disposition
= SCTP_DISPOSITION_NOMEM
;
2729 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
2731 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2732 * - enter the SHUTDOWN-RECEIVED state,
2733 * - stop accepting new data from its SCTP user
2735 * [This is implicit in the new state.]
2737 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2738 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED
));
2739 disposition
= SCTP_DISPOSITION_CONSUME
;
2741 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
2742 disposition
= sctp_sf_do_9_2_shutdown_ack(net
, ep
, asoc
, type
,
2746 if (SCTP_DISPOSITION_NOMEM
== disposition
)
2749 /* - verify, by checking the Cumulative TSN Ack field of the
2750 * chunk, that all its outstanding DATA chunks have been
2751 * received by the SHUTDOWN sender.
2753 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2754 SCTP_BE32(chunk
->subh
.shutdown_hdr
->cum_tsn_ack
));
2761 * sctp_sf_do_9_2_shut_ctsn
2763 * Once an endpoint has reached the SHUTDOWN-RECEIVED state,
2764 * it MUST NOT send a SHUTDOWN in response to a ULP request.
2765 * The Cumulative TSN Ack of the received SHUTDOWN chunk
2766 * MUST be processed.
2768 enum sctp_disposition
sctp_sf_do_9_2_shut_ctsn(
2770 const struct sctp_endpoint
*ep
,
2771 const struct sctp_association
*asoc
,
2772 const union sctp_subtype type
,
2774 struct sctp_cmd_seq
*commands
)
2776 struct sctp_chunk
*chunk
= arg
;
2777 struct sctp_shutdownhdr
*sdh
;
2780 if (!sctp_vtag_verify(chunk
, asoc
))
2781 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2783 /* Make sure that the SHUTDOWN chunk has a valid length. */
2784 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_shutdown_chunk
)))
2785 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2788 sdh
= (struct sctp_shutdownhdr
*)chunk
->skb
->data
;
2789 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2791 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2792 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__
, ctsn
,
2793 asoc
->ctsn_ack_point
);
2795 return SCTP_DISPOSITION_DISCARD
;
2798 /* If Cumulative TSN Ack beyond the max tsn currently
2799 * send, terminating the association and respond to the
2800 * sender with an ABORT.
2802 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2803 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
2805 /* verify, by checking the Cumulative TSN Ack field of the
2806 * chunk, that all its outstanding DATA chunks have been
2807 * received by the SHUTDOWN sender.
2809 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2810 SCTP_BE32(sdh
->cum_tsn_ack
));
2812 return SCTP_DISPOSITION_CONSUME
;
2816 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2817 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2818 * transport addresses (either in the IP addresses or in the INIT chunk)
2819 * that belong to this association, it should discard the INIT chunk and
2820 * retransmit the SHUTDOWN ACK chunk.
2822 enum sctp_disposition
sctp_sf_do_9_2_reshutack(
2824 const struct sctp_endpoint
*ep
,
2825 const struct sctp_association
*asoc
,
2826 const union sctp_subtype type
,
2828 struct sctp_cmd_seq
*commands
)
2830 struct sctp_chunk
*chunk
= arg
;
2831 struct sctp_chunk
*reply
;
2833 /* Make sure that the chunk has a valid length */
2834 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
2835 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2838 /* Since we are not going to really process this INIT, there
2839 * is no point in verifying chunk boundries. Just generate
2842 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
2846 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2847 * the T2-SHUTDOWN timer.
2849 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
2851 /* and restart the T2-shutdown timer. */
2852 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2853 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2855 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2857 return SCTP_DISPOSITION_CONSUME
;
2859 return SCTP_DISPOSITION_NOMEM
;
2863 * sctp_sf_do_ecn_cwr
2865 * Section: Appendix A: Explicit Congestion Notification
2869 * RFC 2481 details a specific bit for a sender to send in the header of
2870 * its next outbound TCP segment to indicate to its peer that it has
2871 * reduced its congestion window. This is termed the CWR bit. For
2872 * SCTP the same indication is made by including the CWR chunk.
2873 * This chunk contains one data element, i.e. the TSN number that
2874 * was sent in the ECNE chunk. This element represents the lowest
2875 * TSN number in the datagram that was originally marked with the
2878 * Verification Tag: 8.5 Verification Tag [Normal verification]
2880 * (endpoint, asoc, chunk)
2883 * (asoc, reply_msg, msg_up, timers, counters)
2885 * The return value is the disposition of the chunk.
2887 enum sctp_disposition
sctp_sf_do_ecn_cwr(struct net
*net
,
2888 const struct sctp_endpoint
*ep
,
2889 const struct sctp_association
*asoc
,
2890 const union sctp_subtype type
,
2892 struct sctp_cmd_seq
*commands
)
2894 struct sctp_chunk
*chunk
= arg
;
2895 struct sctp_cwrhdr
*cwr
;
2898 if (!sctp_vtag_verify(chunk
, asoc
))
2899 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2901 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_ecne_chunk
)))
2902 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2905 cwr
= (struct sctp_cwrhdr
*)chunk
->skb
->data
;
2906 skb_pull(chunk
->skb
, sizeof(*cwr
));
2908 lowest_tsn
= ntohl(cwr
->lowest_tsn
);
2910 /* Does this CWR ack the last sent congestion notification? */
2911 if (TSN_lte(asoc
->last_ecne_tsn
, lowest_tsn
)) {
2912 /* Stop sending ECNE. */
2913 sctp_add_cmd_sf(commands
,
2915 SCTP_U32(lowest_tsn
));
2917 return SCTP_DISPOSITION_CONSUME
;
2923 * Section: Appendix A: Explicit Congestion Notification
2927 * RFC 2481 details a specific bit for a receiver to send back in its
2928 * TCP acknowledgements to notify the sender of the Congestion
2929 * Experienced (CE) bit having arrived from the network. For SCTP this
2930 * same indication is made by including the ECNE chunk. This chunk
2931 * contains one data element, i.e. the lowest TSN associated with the IP
2932 * datagram marked with the CE bit.....
2934 * Verification Tag: 8.5 Verification Tag [Normal verification]
2936 * (endpoint, asoc, chunk)
2939 * (asoc, reply_msg, msg_up, timers, counters)
2941 * The return value is the disposition of the chunk.
2943 enum sctp_disposition
sctp_sf_do_ecne(struct net
*net
,
2944 const struct sctp_endpoint
*ep
,
2945 const struct sctp_association
*asoc
,
2946 const union sctp_subtype type
,
2947 void *arg
, struct sctp_cmd_seq
*commands
)
2949 struct sctp_chunk
*chunk
= arg
;
2950 struct sctp_ecnehdr
*ecne
;
2952 if (!sctp_vtag_verify(chunk
, asoc
))
2953 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2955 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_ecne_chunk
)))
2956 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2959 ecne
= (struct sctp_ecnehdr
*)chunk
->skb
->data
;
2960 skb_pull(chunk
->skb
, sizeof(*ecne
));
2962 /* If this is a newer ECNE than the last CWR packet we sent out */
2963 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_ECNE
,
2964 SCTP_U32(ntohl(ecne
->lowest_tsn
)));
2966 return SCTP_DISPOSITION_CONSUME
;
2970 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2972 * The SCTP endpoint MUST always acknowledge the reception of each valid
2975 * The guidelines on delayed acknowledgement algorithm specified in
2976 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2977 * acknowledgement SHOULD be generated for at least every second packet
2978 * (not every second DATA chunk) received, and SHOULD be generated within
2979 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2980 * situations it may be beneficial for an SCTP transmitter to be more
2981 * conservative than the algorithms detailed in this document allow.
2982 * However, an SCTP transmitter MUST NOT be more aggressive than the
2983 * following algorithms allow.
2985 * A SCTP receiver MUST NOT generate more than one SACK for every
2986 * incoming packet, other than to update the offered window as the
2987 * receiving application consumes new data.
2989 * Verification Tag: 8.5 Verification Tag [Normal verification]
2992 * (endpoint, asoc, chunk)
2995 * (asoc, reply_msg, msg_up, timers, counters)
2997 * The return value is the disposition of the chunk.
2999 enum sctp_disposition
sctp_sf_eat_data_6_2(struct net
*net
,
3000 const struct sctp_endpoint
*ep
,
3001 const struct sctp_association
*asoc
,
3002 const union sctp_subtype type
,
3004 struct sctp_cmd_seq
*commands
)
3006 union sctp_arg force
= SCTP_NOFORCE();
3007 struct sctp_chunk
*chunk
= arg
;
3010 if (!sctp_vtag_verify(chunk
, asoc
)) {
3011 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3013 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3016 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_data_chunk
)))
3017 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3020 error
= sctp_eat_data(asoc
, chunk
, commands
);
3022 case SCTP_IERROR_NO_ERROR
:
3024 case SCTP_IERROR_HIGH_TSN
:
3025 case SCTP_IERROR_BAD_STREAM
:
3026 SCTP_INC_STATS(net
, SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
3027 goto discard_noforce
;
3028 case SCTP_IERROR_DUP_TSN
:
3029 case SCTP_IERROR_IGNORE_TSN
:
3030 SCTP_INC_STATS(net
, SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
3032 case SCTP_IERROR_NO_DATA
:
3033 return SCTP_DISPOSITION_ABORT
;
3034 case SCTP_IERROR_PROTO_VIOLATION
:
3035 return sctp_sf_abort_violation(net
, ep
, asoc
, chunk
, commands
,
3036 (u8
*)chunk
->subh
.data_hdr
,
3037 sizeof(struct sctp_datahdr
));
3042 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_SACK_IMM
)
3043 force
= SCTP_FORCE();
3045 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
]) {
3046 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3047 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
3050 /* If this is the last chunk in a packet, we need to count it
3051 * toward sack generation. Note that we need to SACK every
3052 * OTHER packet containing data chunks, EVEN IF WE DISCARD
3053 * THEM. We elect to NOT generate SACK's if the chunk fails
3054 * the verification tag test.
3056 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
3058 * The SCTP endpoint MUST always acknowledge the reception of
3059 * each valid DATA chunk.
3061 * The guidelines on delayed acknowledgement algorithm
3062 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
3063 * Specifically, an acknowledgement SHOULD be generated for at
3064 * least every second packet (not every second DATA chunk)
3065 * received, and SHOULD be generated within 200 ms of the
3066 * arrival of any unacknowledged DATA chunk. In some
3067 * situations it may be beneficial for an SCTP transmitter to
3068 * be more conservative than the algorithms detailed in this
3069 * document allow. However, an SCTP transmitter MUST NOT be
3070 * more aggressive than the following algorithms allow.
3072 if (chunk
->end_of_packet
)
3073 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, force
);
3075 return SCTP_DISPOSITION_CONSUME
;
3078 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
3080 * When a packet arrives with duplicate DATA chunk(s) and with
3081 * no new DATA chunk(s), the endpoint MUST immediately send a
3082 * SACK with no delay. If a packet arrives with duplicate
3083 * DATA chunk(s) bundled with new DATA chunks, the endpoint
3084 * MAY immediately send a SACK. Normally receipt of duplicate
3085 * DATA chunks will occur when the original SACK chunk was lost
3086 * and the peer's RTO has expired. The duplicate TSN number(s)
3087 * SHOULD be reported in the SACK as duplicate.
3089 /* In our case, we split the MAY SACK advice up whether or not
3090 * the last chunk is a duplicate.'
3092 if (chunk
->end_of_packet
)
3093 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3094 return SCTP_DISPOSITION_DISCARD
;
3097 if (chunk
->end_of_packet
)
3098 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, force
);
3100 return SCTP_DISPOSITION_DISCARD
;
3104 * sctp_sf_eat_data_fast_4_4
3107 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
3108 * DATA chunks without delay.
3110 * Verification Tag: 8.5 Verification Tag [Normal verification]
3112 * (endpoint, asoc, chunk)
3115 * (asoc, reply_msg, msg_up, timers, counters)
3117 * The return value is the disposition of the chunk.
3119 enum sctp_disposition
sctp_sf_eat_data_fast_4_4(
3121 const struct sctp_endpoint
*ep
,
3122 const struct sctp_association
*asoc
,
3123 const union sctp_subtype type
,
3125 struct sctp_cmd_seq
*commands
)
3127 struct sctp_chunk
*chunk
= arg
;
3130 if (!sctp_vtag_verify(chunk
, asoc
)) {
3131 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3133 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3136 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_data_chunk
)))
3137 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3140 error
= sctp_eat_data(asoc
, chunk
, commands
);
3142 case SCTP_IERROR_NO_ERROR
:
3143 case SCTP_IERROR_HIGH_TSN
:
3144 case SCTP_IERROR_DUP_TSN
:
3145 case SCTP_IERROR_IGNORE_TSN
:
3146 case SCTP_IERROR_BAD_STREAM
:
3148 case SCTP_IERROR_NO_DATA
:
3149 return SCTP_DISPOSITION_ABORT
;
3150 case SCTP_IERROR_PROTO_VIOLATION
:
3151 return sctp_sf_abort_violation(net
, ep
, asoc
, chunk
, commands
,
3152 (u8
*)chunk
->subh
.data_hdr
,
3153 sizeof(struct sctp_datahdr
));
3158 /* Go a head and force a SACK, since we are shutting down. */
3160 /* Implementor's Guide.
3162 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3163 * respond to each received packet containing one or more DATA chunk(s)
3164 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3166 if (chunk
->end_of_packet
) {
3167 /* We must delay the chunk creation since the cumulative
3168 * TSN has not been updated yet.
3170 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3171 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3172 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3173 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3176 return SCTP_DISPOSITION_CONSUME
;
3180 * Section: 6.2 Processing a Received SACK
3181 * D) Any time a SACK arrives, the endpoint performs the following:
3183 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
3184 * then drop the SACK. Since Cumulative TSN Ack is monotonically
3185 * increasing, a SACK whose Cumulative TSN Ack is less than the
3186 * Cumulative TSN Ack Point indicates an out-of-order SACK.
3188 * ii) Set rwnd equal to the newly received a_rwnd minus the number
3189 * of bytes still outstanding after processing the Cumulative TSN Ack
3190 * and the Gap Ack Blocks.
3192 * iii) If the SACK is missing a TSN that was previously
3193 * acknowledged via a Gap Ack Block (e.g., the data receiver
3194 * reneged on the data), then mark the corresponding DATA chunk
3195 * as available for retransmit: Mark it as missing for fast
3196 * retransmit as described in Section 7.2.4 and if no retransmit
3197 * timer is running for the destination address to which the DATA
3198 * chunk was originally transmitted, then T3-rtx is started for
3199 * that destination address.
3201 * Verification Tag: 8.5 Verification Tag [Normal verification]
3204 * (endpoint, asoc, chunk)
3207 * (asoc, reply_msg, msg_up, timers, counters)
3209 * The return value is the disposition of the chunk.
3211 enum sctp_disposition
sctp_sf_eat_sack_6_2(struct net
*net
,
3212 const struct sctp_endpoint
*ep
,
3213 const struct sctp_association
*asoc
,
3214 const union sctp_subtype type
,
3216 struct sctp_cmd_seq
*commands
)
3218 struct sctp_chunk
*chunk
= arg
;
3219 struct sctp_sackhdr
*sackh
;
3222 if (!sctp_vtag_verify(chunk
, asoc
))
3223 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3225 /* Make sure that the SACK chunk has a valid length. */
3226 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_sack_chunk
)))
3227 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3230 /* Pull the SACK chunk from the data buffer */
3231 sackh
= sctp_sm_pull_sack(chunk
);
3232 /* Was this a bogus SACK? */
3234 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3235 chunk
->subh
.sack_hdr
= sackh
;
3236 ctsn
= ntohl(sackh
->cum_tsn_ack
);
3238 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
3239 * Ack Point, then drop the SACK. Since Cumulative TSN
3240 * Ack is monotonically increasing, a SACK whose
3241 * Cumulative TSN Ack is less than the Cumulative TSN Ack
3242 * Point indicates an out-of-order SACK.
3244 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
3245 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__
, ctsn
,
3246 asoc
->ctsn_ack_point
);
3248 return SCTP_DISPOSITION_DISCARD
;
3251 /* If Cumulative TSN Ack beyond the max tsn currently
3252 * send, terminating the association and respond to the
3253 * sender with an ABORT.
3255 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
3256 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
3258 /* Return this SACK for further processing. */
3259 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_SACK
, SCTP_CHUNK(chunk
));
3261 /* Note: We do the rest of the work on the PROCESS_SACK
3264 return SCTP_DISPOSITION_CONSUME
;
3268 * Generate an ABORT in response to a packet.
3270 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
3272 * 8) The receiver should respond to the sender of the OOTB packet with
3273 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3274 * MUST fill in the Verification Tag field of the outbound packet
3275 * with the value found in the Verification Tag field of the OOTB
3276 * packet and set the T-bit in the Chunk Flags to indicate that the
3277 * Verification Tag is reflected. After sending this ABORT, the
3278 * receiver of the OOTB packet shall discard the OOTB packet and take
3279 * no further action.
3283 * The return value is the disposition of the chunk.
3285 static enum sctp_disposition
sctp_sf_tabort_8_4_8(
3287 const struct sctp_endpoint
*ep
,
3288 const struct sctp_association
*asoc
,
3289 const union sctp_subtype type
,
3291 struct sctp_cmd_seq
*commands
)
3293 struct sctp_packet
*packet
= NULL
;
3294 struct sctp_chunk
*chunk
= arg
;
3295 struct sctp_chunk
*abort
;
3297 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
3299 return SCTP_DISPOSITION_NOMEM
;
3301 /* Make an ABORT. The T bit will be set if the asoc
3304 abort
= sctp_make_abort(asoc
, chunk
, 0);
3306 sctp_ootb_pkt_free(packet
);
3307 return SCTP_DISPOSITION_NOMEM
;
3310 /* Reflect vtag if T-Bit is set */
3311 if (sctp_test_T_bit(abort
))
3312 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3314 /* Set the skb to the belonging sock for accounting. */
3315 abort
->skb
->sk
= ep
->base
.sk
;
3317 sctp_packet_append_chunk(packet
, abort
);
3319 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3320 SCTP_PACKET(packet
));
3322 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
3324 sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3325 return SCTP_DISPOSITION_CONSUME
;
3329 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
3330 * event as ULP notification for each cause included in the chunk.
3332 * API 5.3.1.3 - SCTP_REMOTE_ERROR
3334 * The return value is the disposition of the chunk.
3336 enum sctp_disposition
sctp_sf_operr_notify(struct net
*net
,
3337 const struct sctp_endpoint
*ep
,
3338 const struct sctp_association
*asoc
,
3339 const union sctp_subtype type
,
3341 struct sctp_cmd_seq
*commands
)
3343 struct sctp_chunk
*chunk
= arg
;
3344 struct sctp_errhdr
*err
;
3346 if (!sctp_vtag_verify(chunk
, asoc
))
3347 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3349 /* Make sure that the ERROR chunk has a valid length. */
3350 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_operr_chunk
)))
3351 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3353 sctp_walk_errors(err
, chunk
->chunk_hdr
);
3354 if ((void *)err
!= (void *)chunk
->chunk_end
)
3355 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3356 (void *)err
, commands
);
3358 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_OPERR
,
3361 return SCTP_DISPOSITION_CONSUME
;
3365 * Process an inbound SHUTDOWN ACK.
3368 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3369 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3370 * peer, and remove all record of the association.
3372 * The return value is the disposition.
3374 enum sctp_disposition
sctp_sf_do_9_2_final(struct net
*net
,
3375 const struct sctp_endpoint
*ep
,
3376 const struct sctp_association
*asoc
,
3377 const union sctp_subtype type
,
3379 struct sctp_cmd_seq
*commands
)
3381 struct sctp_chunk
*chunk
= arg
;
3382 struct sctp_chunk
*reply
;
3383 struct sctp_ulpevent
*ev
;
3385 if (!sctp_vtag_verify(chunk
, asoc
))
3386 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3388 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3389 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
3390 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3392 /* 10.2 H) SHUTDOWN COMPLETE notification
3394 * When SCTP completes the shutdown procedures (section 9.2) this
3395 * notification is passed to the upper layer.
3397 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
3398 0, 0, 0, NULL
, GFP_ATOMIC
);
3402 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3403 reply
= sctp_make_shutdown_complete(asoc
, chunk
);
3407 /* Do all the commands now (after allocation), so that we
3408 * have consistent state if memory allocation failes
3410 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
3412 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3413 * stop the T2-shutdown timer,
3415 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3416 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3418 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3419 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
3421 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
3422 SCTP_STATE(SCTP_STATE_CLOSED
));
3423 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
3424 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3425 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
3427 /* ...and remove all record of the association. */
3428 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
3429 return SCTP_DISPOSITION_DELETE_TCB
;
3432 sctp_ulpevent_free(ev
);
3434 return SCTP_DISPOSITION_NOMEM
;
3438 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3440 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3441 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3442 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3443 * packet must fill in the Verification Tag field of the outbound
3444 * packet with the Verification Tag received in the SHUTDOWN ACK and
3445 * set the T-bit in the Chunk Flags to indicate that the Verification
3448 * 8) The receiver should respond to the sender of the OOTB packet with
3449 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3450 * MUST fill in the Verification Tag field of the outbound packet
3451 * with the value found in the Verification Tag field of the OOTB
3452 * packet and set the T-bit in the Chunk Flags to indicate that the
3453 * Verification Tag is reflected. After sending this ABORT, the
3454 * receiver of the OOTB packet shall discard the OOTB packet and take
3455 * no further action.
3457 enum sctp_disposition
sctp_sf_ootb(struct net
*net
,
3458 const struct sctp_endpoint
*ep
,
3459 const struct sctp_association
*asoc
,
3460 const union sctp_subtype type
,
3461 void *arg
, struct sctp_cmd_seq
*commands
)
3463 struct sctp_chunk
*chunk
= arg
;
3464 struct sk_buff
*skb
= chunk
->skb
;
3465 struct sctp_chunkhdr
*ch
;
3466 struct sctp_errhdr
*err
;
3467 int ootb_cookie_ack
= 0;
3468 int ootb_shut_ack
= 0;
3471 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
3473 ch
= (struct sctp_chunkhdr
*)chunk
->chunk_hdr
;
3475 /* Report violation if the chunk is less then minimal */
3476 if (ntohs(ch
->length
) < sizeof(*ch
))
3477 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3480 /* Report violation if chunk len overflows */
3481 ch_end
= ((__u8
*)ch
) + SCTP_PAD4(ntohs(ch
->length
));
3482 if (ch_end
> skb_tail_pointer(skb
))
3483 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3486 /* Now that we know we at least have a chunk header,
3487 * do things that are type appropriate.
3489 if (SCTP_CID_SHUTDOWN_ACK
== ch
->type
)
3492 /* RFC 2960, Section 3.3.7
3493 * Moreover, under any circumstances, an endpoint that
3494 * receives an ABORT MUST NOT respond to that ABORT by
3495 * sending an ABORT of its own.
3497 if (SCTP_CID_ABORT
== ch
->type
)
3498 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3500 /* RFC 8.4, 7) If the packet contains a "Stale cookie" ERROR
3501 * or a COOKIE ACK the SCTP Packet should be silently
3505 if (SCTP_CID_COOKIE_ACK
== ch
->type
)
3506 ootb_cookie_ack
= 1;
3508 if (SCTP_CID_ERROR
== ch
->type
) {
3509 sctp_walk_errors(err
, ch
) {
3510 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
) {
3511 ootb_cookie_ack
= 1;
3517 ch
= (struct sctp_chunkhdr
*)ch_end
;
3518 } while (ch_end
< skb_tail_pointer(skb
));
3521 return sctp_sf_shut_8_4_5(net
, ep
, asoc
, type
, arg
, commands
);
3522 else if (ootb_cookie_ack
)
3523 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3525 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
3529 * Handle an "Out of the blue" SHUTDOWN ACK.
3531 * Section: 8.4 5, sctpimpguide 2.41.
3533 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3534 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3535 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3536 * packet must fill in the Verification Tag field of the outbound
3537 * packet with the Verification Tag received in the SHUTDOWN ACK and
3538 * set the T-bit in the Chunk Flags to indicate that the Verification
3542 * (endpoint, asoc, type, arg, commands)
3545 * (enum sctp_disposition)
3547 * The return value is the disposition of the chunk.
3549 static enum sctp_disposition
sctp_sf_shut_8_4_5(
3551 const struct sctp_endpoint
*ep
,
3552 const struct sctp_association
*asoc
,
3553 const union sctp_subtype type
,
3555 struct sctp_cmd_seq
*commands
)
3557 struct sctp_packet
*packet
= NULL
;
3558 struct sctp_chunk
*chunk
= arg
;
3559 struct sctp_chunk
*shut
;
3561 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
3563 return SCTP_DISPOSITION_NOMEM
;
3565 /* Make an SHUTDOWN_COMPLETE.
3566 * The T bit will be set if the asoc is NULL.
3568 shut
= sctp_make_shutdown_complete(asoc
, chunk
);
3570 sctp_ootb_pkt_free(packet
);
3571 return SCTP_DISPOSITION_NOMEM
;
3574 /* Reflect vtag if T-Bit is set */
3575 if (sctp_test_T_bit(shut
))
3576 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3578 /* Set the skb to the belonging sock for accounting. */
3579 shut
->skb
->sk
= ep
->base
.sk
;
3581 sctp_packet_append_chunk(packet
, shut
);
3583 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3584 SCTP_PACKET(packet
));
3586 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
3588 /* If the chunk length is invalid, we don't want to process
3589 * the reset of the packet.
3591 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
3592 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3594 /* We need to discard the rest of the packet to prevent
3595 * potential bomming attacks from additional bundled chunks.
3596 * This is documented in SCTP Threats ID.
3598 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3602 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3604 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3605 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3606 * procedures in section 8.4 SHOULD be followed, in other words it
3607 * should be treated as an Out Of The Blue packet.
3608 * [This means that we do NOT check the Verification Tag on these
3612 enum sctp_disposition
sctp_sf_do_8_5_1_E_sa(struct net
*net
,
3613 const struct sctp_endpoint
*ep
,
3614 const struct sctp_association
*asoc
,
3615 const union sctp_subtype type
,
3617 struct sctp_cmd_seq
*commands
)
3619 struct sctp_chunk
*chunk
= arg
;
3621 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3622 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
3623 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3626 /* Although we do have an association in this case, it corresponds
3627 * to a restarted association. So the packet is treated as an OOTB
3628 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3629 * called with a NULL association.
3631 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
3633 return sctp_sf_shut_8_4_5(net
, ep
, NULL
, type
, arg
, commands
);
3636 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3637 enum sctp_disposition
sctp_sf_do_asconf(struct net
*net
,
3638 const struct sctp_endpoint
*ep
,
3639 const struct sctp_association
*asoc
,
3640 const union sctp_subtype type
,
3642 struct sctp_cmd_seq
*commands
)
3644 struct sctp_paramhdr
*err_param
= NULL
;
3645 struct sctp_chunk
*asconf_ack
= NULL
;
3646 struct sctp_chunk
*chunk
= arg
;
3647 struct sctp_addiphdr
*hdr
;
3650 if (!sctp_vtag_verify(chunk
, asoc
)) {
3651 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3653 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3656 /* ADD-IP: Section 4.1.1
3657 * This chunk MUST be sent in an authenticated way by using
3658 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3659 * is received unauthenticated it MUST be silently discarded as
3660 * described in [I-D.ietf-tsvwg-sctp-auth].
3662 if (!net
->sctp
.addip_noauth
&& !chunk
->auth
)
3663 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
,
3666 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3667 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_addip_chunk
)))
3668 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3671 hdr
= (struct sctp_addiphdr
*)chunk
->skb
->data
;
3672 serial
= ntohl(hdr
->serial
);
3674 /* Verify the ASCONF chunk before processing it. */
3675 if (!sctp_verify_asconf(asoc
, chunk
, true, &err_param
))
3676 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3677 (void *)err_param
, commands
);
3679 /* ADDIP 5.2 E1) Compare the value of the serial number to the value
3680 * the endpoint stored in a new association variable
3681 * 'Peer-Serial-Number'.
3683 if (serial
== asoc
->peer
.addip_serial
+ 1) {
3684 /* If this is the first instance of ASCONF in the packet,
3685 * we can clean our old ASCONF-ACKs.
3687 if (!chunk
->has_asconf
)
3688 sctp_assoc_clean_asconf_ack_cache(asoc
);
3690 /* ADDIP 5.2 E4) When the Sequence Number matches the next one
3691 * expected, process the ASCONF as described below and after
3692 * processing the ASCONF Chunk, append an ASCONF-ACK Chunk to
3693 * the response packet and cache a copy of it (in the event it
3694 * later needs to be retransmitted).
3696 * Essentially, do V1-V5.
3698 asconf_ack
= sctp_process_asconf((struct sctp_association
*)
3701 return SCTP_DISPOSITION_NOMEM
;
3702 } else if (serial
< asoc
->peer
.addip_serial
+ 1) {
3704 * If the value found in the Sequence Number is less than the
3705 * ('Peer- Sequence-Number' + 1), simply skip to the next
3706 * ASCONF, and include in the outbound response packet
3707 * any previously cached ASCONF-ACK response that was
3708 * sent and saved that matches the Sequence Number of the
3709 * ASCONF. Note: It is possible that no cached ASCONF-ACK
3710 * Chunk exists. This will occur when an older ASCONF
3711 * arrives out of order. In such a case, the receiver
3712 * should skip the ASCONF Chunk and not include ASCONF-ACK
3713 * Chunk for that chunk.
3715 asconf_ack
= sctp_assoc_lookup_asconf_ack(asoc
, hdr
->serial
);
3717 return SCTP_DISPOSITION_DISCARD
;
3719 /* Reset the transport so that we select the correct one
3720 * this time around. This is to make sure that we don't
3721 * accidentally use a stale transport that's been removed.
3723 asconf_ack
->transport
= NULL
;
3725 /* ADDIP 5.2 E5) Otherwise, the ASCONF Chunk is discarded since
3726 * it must be either a stale packet or from an attacker.
3728 return SCTP_DISPOSITION_DISCARD
;
3731 /* ADDIP 5.2 E6) The destination address of the SCTP packet
3732 * containing the ASCONF-ACK Chunks MUST be the source address of
3733 * the SCTP packet that held the ASCONF Chunks.
3735 * To do this properly, we'll set the destination address of the chunk
3736 * and at the transmit time, will try look up the transport to use.
3737 * Since ASCONFs may be bundled, the correct transport may not be
3738 * created until we process the entire packet, thus this workaround.
3740 asconf_ack
->dest
= chunk
->source
;
3741 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(asconf_ack
));
3742 if (asoc
->new_transport
) {
3743 sctp_sf_heartbeat(ep
, asoc
, type
, asoc
->new_transport
, commands
);
3744 ((struct sctp_association
*)asoc
)->new_transport
= NULL
;
3747 return SCTP_DISPOSITION_CONSUME
;
3751 * ADDIP Section 4.3 General rules for address manipulation
3752 * When building TLV parameters for the ASCONF Chunk that will add or
3753 * delete IP addresses the D0 to D13 rules should be applied:
3755 enum sctp_disposition
sctp_sf_do_asconf_ack(struct net
*net
,
3756 const struct sctp_endpoint
*ep
,
3757 const struct sctp_association
*asoc
,
3758 const union sctp_subtype type
,
3760 struct sctp_cmd_seq
*commands
)
3762 struct sctp_chunk
*last_asconf
= asoc
->addip_last_asconf
;
3763 struct sctp_paramhdr
*err_param
= NULL
;
3764 struct sctp_chunk
*asconf_ack
= arg
;
3765 struct sctp_addiphdr
*addip_hdr
;
3766 __u32 sent_serial
, rcvd_serial
;
3767 struct sctp_chunk
*abort
;
3769 if (!sctp_vtag_verify(asconf_ack
, asoc
)) {
3770 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3772 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3775 /* ADD-IP, Section 4.1.2:
3776 * This chunk MUST be sent in an authenticated way by using
3777 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3778 * is received unauthenticated it MUST be silently discarded as
3779 * described in [I-D.ietf-tsvwg-sctp-auth].
3781 if (!net
->sctp
.addip_noauth
&& !asconf_ack
->auth
)
3782 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
,
3785 /* Make sure that the ADDIP chunk has a valid length. */
3786 if (!sctp_chunk_length_valid(asconf_ack
,
3787 sizeof(struct sctp_addip_chunk
)))
3788 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3791 addip_hdr
= (struct sctp_addiphdr
*)asconf_ack
->skb
->data
;
3792 rcvd_serial
= ntohl(addip_hdr
->serial
);
3794 /* Verify the ASCONF-ACK chunk before processing it. */
3795 if (!sctp_verify_asconf(asoc
, asconf_ack
, false, &err_param
))
3796 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3797 (void *)err_param
, commands
);
3800 addip_hdr
= (struct sctp_addiphdr
*)last_asconf
->subh
.addip_hdr
;
3801 sent_serial
= ntohl(addip_hdr
->serial
);
3803 sent_serial
= asoc
->addip_serial
- 1;
3806 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3807 * equal to the next serial number to be used but no ASCONF chunk is
3808 * outstanding the endpoint MUST ABORT the association. Note that a
3809 * sequence number is greater than if it is no more than 2^^31-1
3810 * larger than the current sequence number (using serial arithmetic).
3812 if (ADDIP_SERIAL_gte(rcvd_serial
, sent_serial
+ 1) &&
3813 !(asoc
->addip_last_asconf
)) {
3814 abort
= sctp_make_abort(asoc
, asconf_ack
,
3815 sizeof(struct sctp_errhdr
));
3817 sctp_init_cause(abort
, SCTP_ERROR_ASCONF_ACK
, 0);
3818 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3821 /* We are going to ABORT, so we might as well stop
3822 * processing the rest of the chunks in the packet.
3824 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3825 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3826 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
3827 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3828 SCTP_ERROR(ECONNABORTED
));
3829 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3830 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3831 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
3832 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3833 return SCTP_DISPOSITION_ABORT
;
3836 if ((rcvd_serial
== sent_serial
) && asoc
->addip_last_asconf
) {
3837 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3838 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3840 if (!sctp_process_asconf_ack((struct sctp_association
*)asoc
,
3842 /* Successfully processed ASCONF_ACK. We can
3843 * release the next asconf if we have one.
3845 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_NEXT_ASCONF
,
3847 return SCTP_DISPOSITION_CONSUME
;
3850 abort
= sctp_make_abort(asoc
, asconf_ack
,
3851 sizeof(struct sctp_errhdr
));
3853 sctp_init_cause(abort
, SCTP_ERROR_RSRC_LOW
, 0);
3854 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3857 /* We are going to ABORT, so we might as well stop
3858 * processing the rest of the chunks in the packet.
3860 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
3861 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3862 SCTP_ERROR(ECONNABORTED
));
3863 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3864 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3865 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
3866 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3867 return SCTP_DISPOSITION_ABORT
;
3870 return SCTP_DISPOSITION_DISCARD
;
3873 /* RE-CONFIG Section 5.2 Upon reception of an RECONF Chunk. */
3874 enum sctp_disposition
sctp_sf_do_reconf(struct net
*net
,
3875 const struct sctp_endpoint
*ep
,
3876 const struct sctp_association
*asoc
,
3877 const union sctp_subtype type
,
3879 struct sctp_cmd_seq
*commands
)
3881 struct sctp_paramhdr
*err_param
= NULL
;
3882 struct sctp_chunk
*chunk
= arg
;
3883 struct sctp_reconf_chunk
*hdr
;
3884 union sctp_params param
;
3886 if (!sctp_vtag_verify(chunk
, asoc
)) {
3887 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3889 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3892 /* Make sure that the RECONF chunk has a valid length. */
3893 if (!sctp_chunk_length_valid(chunk
, sizeof(*hdr
)))
3894 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3897 if (!sctp_verify_reconf(asoc
, chunk
, &err_param
))
3898 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3899 (void *)err_param
, commands
);
3901 hdr
= (struct sctp_reconf_chunk
*)chunk
->chunk_hdr
;
3902 sctp_walk_params(param
, hdr
, params
) {
3903 struct sctp_chunk
*reply
= NULL
;
3904 struct sctp_ulpevent
*ev
= NULL
;
3906 if (param
.p
->type
== SCTP_PARAM_RESET_OUT_REQUEST
)
3907 reply
= sctp_process_strreset_outreq(
3908 (struct sctp_association
*)asoc
, param
, &ev
);
3909 else if (param
.p
->type
== SCTP_PARAM_RESET_IN_REQUEST
)
3910 reply
= sctp_process_strreset_inreq(
3911 (struct sctp_association
*)asoc
, param
, &ev
);
3912 else if (param
.p
->type
== SCTP_PARAM_RESET_TSN_REQUEST
)
3913 reply
= sctp_process_strreset_tsnreq(
3914 (struct sctp_association
*)asoc
, param
, &ev
);
3915 else if (param
.p
->type
== SCTP_PARAM_RESET_ADD_OUT_STREAMS
)
3916 reply
= sctp_process_strreset_addstrm_out(
3917 (struct sctp_association
*)asoc
, param
, &ev
);
3918 else if (param
.p
->type
== SCTP_PARAM_RESET_ADD_IN_STREAMS
)
3919 reply
= sctp_process_strreset_addstrm_in(
3920 (struct sctp_association
*)asoc
, param
, &ev
);
3921 else if (param
.p
->type
== SCTP_PARAM_RESET_RESPONSE
)
3922 reply
= sctp_process_strreset_resp(
3923 (struct sctp_association
*)asoc
, param
, &ev
);
3926 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
3930 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3934 return SCTP_DISPOSITION_CONSUME
;
3938 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3940 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3941 * its cumulative TSN point to the value carried in the FORWARD TSN
3942 * chunk, and then MUST further advance its cumulative TSN point locally
3944 * After the above processing, the data receiver MUST stop reporting any
3945 * missing TSNs earlier than or equal to the new cumulative TSN point.
3947 * Verification Tag: 8.5 Verification Tag [Normal verification]
3949 * The return value is the disposition of the chunk.
3951 enum sctp_disposition
sctp_sf_eat_fwd_tsn(struct net
*net
,
3952 const struct sctp_endpoint
*ep
,
3953 const struct sctp_association
*asoc
,
3954 const union sctp_subtype type
,
3956 struct sctp_cmd_seq
*commands
)
3958 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3959 struct sctp_chunk
*chunk
= arg
;
3960 struct sctp_fwdtsn_skip
*skip
;
3964 if (!sctp_vtag_verify(chunk
, asoc
)) {
3965 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3967 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3970 if (!asoc
->peer
.prsctp_capable
)
3971 return sctp_sf_unk_chunk(net
, ep
, asoc
, type
, arg
, commands
);
3973 /* Make sure that the FORWARD_TSN chunk has valid length. */
3974 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3975 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3978 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3979 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3980 len
= ntohs(chunk
->chunk_hdr
->length
);
3981 len
-= sizeof(struct sctp_chunkhdr
);
3982 skb_pull(chunk
->skb
, len
);
3984 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3985 pr_debug("%s: TSN 0x%x\n", __func__
, tsn
);
3987 /* The TSN is too high--silently discard the chunk and count on it
3988 * getting retransmitted later.
3990 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3991 goto discard_noforce
;
3993 /* Silently discard the chunk if stream-id is not valid */
3994 sctp_walk_fwdtsn(skip
, chunk
) {
3995 if (ntohs(skip
->stream
) >= asoc
->stream
.incnt
)
3996 goto discard_noforce
;
3999 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
4000 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
4001 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
4004 /* Count this as receiving DATA. */
4005 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
]) {
4006 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
4007 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
4010 /* FIXME: For now send a SACK, but DATA processing may
4013 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
4015 return SCTP_DISPOSITION_CONSUME
;
4018 return SCTP_DISPOSITION_DISCARD
;
4021 enum sctp_disposition
sctp_sf_eat_fwd_tsn_fast(
4023 const struct sctp_endpoint
*ep
,
4024 const struct sctp_association
*asoc
,
4025 const union sctp_subtype type
,
4027 struct sctp_cmd_seq
*commands
)
4029 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
4030 struct sctp_chunk
*chunk
= arg
;
4031 struct sctp_fwdtsn_skip
*skip
;
4035 if (!sctp_vtag_verify(chunk
, asoc
)) {
4036 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
4038 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4041 if (!asoc
->peer
.prsctp_capable
)
4042 return sctp_sf_unk_chunk(net
, ep
, asoc
, type
, arg
, commands
);
4044 /* Make sure that the FORWARD_TSN chunk has a valid length. */
4045 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
4046 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4049 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
4050 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
4051 len
= ntohs(chunk
->chunk_hdr
->length
);
4052 len
-= sizeof(struct sctp_chunkhdr
);
4053 skb_pull(chunk
->skb
, len
);
4055 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
4056 pr_debug("%s: TSN 0x%x\n", __func__
, tsn
);
4058 /* The TSN is too high--silently discard the chunk and count on it
4059 * getting retransmitted later.
4061 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
4064 /* Silently discard the chunk if stream-id is not valid */
4065 sctp_walk_fwdtsn(skip
, chunk
) {
4066 if (ntohs(skip
->stream
) >= asoc
->stream
.incnt
)
4070 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
4071 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
4072 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
4075 /* Go a head and force a SACK, since we are shutting down. */
4077 /* Implementor's Guide.
4079 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
4080 * respond to each received packet containing one or more DATA chunk(s)
4081 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
4083 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
4084 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
4085 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
4086 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
4088 return SCTP_DISPOSITION_CONSUME
;
4092 * SCTP-AUTH Section 6.3 Receiving authenticated chukns
4094 * The receiver MUST use the HMAC algorithm indicated in the HMAC
4095 * Identifier field. If this algorithm was not specified by the
4096 * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk
4097 * during association setup, the AUTH chunk and all chunks after it MUST
4098 * be discarded and an ERROR chunk SHOULD be sent with the error cause
4099 * defined in Section 4.1.
4101 * If an endpoint with no shared key receives a Shared Key Identifier
4102 * other than 0, it MUST silently discard all authenticated chunks. If
4103 * the endpoint has at least one endpoint pair shared key for the peer,
4104 * it MUST use the key specified by the Shared Key Identifier if a
4105 * key has been configured for that Shared Key Identifier. If no
4106 * endpoint pair shared key has been configured for that Shared Key
4107 * Identifier, all authenticated chunks MUST be silently discarded.
4109 * Verification Tag: 8.5 Verification Tag [Normal verification]
4111 * The return value is the disposition of the chunk.
4113 static enum sctp_ierror
sctp_sf_authenticate(
4115 const struct sctp_endpoint
*ep
,
4116 const struct sctp_association
*asoc
,
4117 const union sctp_subtype type
,
4118 struct sctp_chunk
*chunk
)
4120 struct sctp_authhdr
*auth_hdr
;
4121 __u8
*save_digest
, *digest
;
4122 struct sctp_hmac
*hmac
;
4123 unsigned int sig_len
;
4126 /* Pull in the auth header, so we can do some more verification */
4127 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
4128 chunk
->subh
.auth_hdr
= auth_hdr
;
4129 skb_pull(chunk
->skb
, sizeof(*auth_hdr
));
4131 /* Make sure that we support the HMAC algorithm from the auth
4134 if (!sctp_auth_asoc_verify_hmac_id(asoc
, auth_hdr
->hmac_id
))
4135 return SCTP_IERROR_AUTH_BAD_HMAC
;
4137 /* Make sure that the provided shared key identifier has been
4140 key_id
= ntohs(auth_hdr
->shkey_id
);
4141 if (key_id
!= asoc
->active_key_id
&& !sctp_auth_get_shkey(asoc
, key_id
))
4142 return SCTP_IERROR_AUTH_BAD_KEYID
;
4145 /* Make sure that the length of the signature matches what
4148 sig_len
= ntohs(chunk
->chunk_hdr
->length
) -
4149 sizeof(struct sctp_auth_chunk
);
4150 hmac
= sctp_auth_get_hmac(ntohs(auth_hdr
->hmac_id
));
4151 if (sig_len
!= hmac
->hmac_len
)
4152 return SCTP_IERROR_PROTO_VIOLATION
;
4154 /* Now that we've done validation checks, we can compute and
4155 * verify the hmac. The steps involved are:
4156 * 1. Save the digest from the chunk.
4157 * 2. Zero out the digest in the chunk.
4158 * 3. Compute the new digest
4159 * 4. Compare saved and new digests.
4161 digest
= auth_hdr
->hmac
;
4162 skb_pull(chunk
->skb
, sig_len
);
4164 save_digest
= kmemdup(digest
, sig_len
, GFP_ATOMIC
);
4168 memset(digest
, 0, sig_len
);
4170 sctp_auth_calculate_hmac(asoc
, chunk
->skb
,
4171 (struct sctp_auth_chunk
*)chunk
->chunk_hdr
,
4174 /* Discard the packet if the digests do not match */
4175 if (memcmp(save_digest
, digest
, sig_len
)) {
4177 return SCTP_IERROR_BAD_SIG
;
4183 return SCTP_IERROR_NO_ERROR
;
4185 return SCTP_IERROR_NOMEM
;
4188 enum sctp_disposition
sctp_sf_eat_auth(struct net
*net
,
4189 const struct sctp_endpoint
*ep
,
4190 const struct sctp_association
*asoc
,
4191 const union sctp_subtype type
,
4192 void *arg
, struct sctp_cmd_seq
*commands
)
4194 struct sctp_chunk
*chunk
= arg
;
4195 struct sctp_authhdr
*auth_hdr
;
4196 struct sctp_chunk
*err_chunk
;
4197 enum sctp_ierror error
;
4199 /* Make sure that the peer has AUTH capable */
4200 if (!asoc
->peer
.auth_capable
)
4201 return sctp_sf_unk_chunk(net
, ep
, asoc
, type
, arg
, commands
);
4203 if (!sctp_vtag_verify(chunk
, asoc
)) {
4204 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
4206 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4209 /* Make sure that the AUTH chunk has valid length. */
4210 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_auth_chunk
)))
4211 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4214 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
4215 error
= sctp_sf_authenticate(net
, ep
, asoc
, type
, chunk
);
4217 case SCTP_IERROR_AUTH_BAD_HMAC
:
4218 /* Generate the ERROR chunk and discard the rest
4221 err_chunk
= sctp_make_op_error(asoc
, chunk
,
4222 SCTP_ERROR_UNSUP_HMAC
,
4226 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4227 SCTP_CHUNK(err_chunk
));
4230 case SCTP_IERROR_AUTH_BAD_KEYID
:
4231 case SCTP_IERROR_BAD_SIG
:
4232 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4234 case SCTP_IERROR_PROTO_VIOLATION
:
4235 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4238 case SCTP_IERROR_NOMEM
:
4239 return SCTP_DISPOSITION_NOMEM
;
4241 default: /* Prevent gcc warnings */
4245 if (asoc
->active_key_id
!= ntohs(auth_hdr
->shkey_id
)) {
4246 struct sctp_ulpevent
*ev
;
4248 ev
= sctp_ulpevent_make_authkey(asoc
, ntohs(auth_hdr
->shkey_id
),
4249 SCTP_AUTH_NEWKEY
, GFP_ATOMIC
);
4254 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
4258 return SCTP_DISPOSITION_CONSUME
;
4262 * Process an unknown chunk.
4264 * Section: 3.2. Also, 2.1 in the implementor's guide.
4266 * Chunk Types are encoded such that the highest-order two bits specify
4267 * the action that must be taken if the processing endpoint does not
4268 * recognize the Chunk Type.
4270 * 00 - Stop processing this SCTP packet and discard it, do not process
4271 * any further chunks within it.
4273 * 01 - Stop processing this SCTP packet and discard it, do not process
4274 * any further chunks within it, and report the unrecognized
4275 * chunk in an 'Unrecognized Chunk Type'.
4277 * 10 - Skip this chunk and continue processing.
4279 * 11 - Skip this chunk and continue processing, but report in an ERROR
4280 * Chunk using the 'Unrecognized Chunk Type' cause of error.
4282 * The return value is the disposition of the chunk.
4284 enum sctp_disposition
sctp_sf_unk_chunk(struct net
*net
,
4285 const struct sctp_endpoint
*ep
,
4286 const struct sctp_association
*asoc
,
4287 const union sctp_subtype type
,
4289 struct sctp_cmd_seq
*commands
)
4291 struct sctp_chunk
*unk_chunk
= arg
;
4292 struct sctp_chunk
*err_chunk
;
4293 struct sctp_chunkhdr
*hdr
;
4295 pr_debug("%s: processing unknown chunk id:%d\n", __func__
, type
.chunk
);
4297 if (!sctp_vtag_verify(unk_chunk
, asoc
))
4298 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4300 /* Make sure that the chunk has a valid length.
4301 * Since we don't know the chunk type, we use a general
4302 * chunkhdr structure to make a comparison.
4304 if (!sctp_chunk_length_valid(unk_chunk
, sizeof(*hdr
)))
4305 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4308 switch (type
.chunk
& SCTP_CID_ACTION_MASK
) {
4309 case SCTP_CID_ACTION_DISCARD
:
4310 /* Discard the packet. */
4311 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4312 case SCTP_CID_ACTION_DISCARD_ERR
:
4313 /* Generate an ERROR chunk as response. */
4314 hdr
= unk_chunk
->chunk_hdr
;
4315 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4316 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4317 SCTP_PAD4(ntohs(hdr
->length
)),
4320 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4321 SCTP_CHUNK(err_chunk
));
4324 /* Discard the packet. */
4325 sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4326 return SCTP_DISPOSITION_CONSUME
;
4327 case SCTP_CID_ACTION_SKIP
:
4328 /* Skip the chunk. */
4329 return SCTP_DISPOSITION_DISCARD
;
4330 case SCTP_CID_ACTION_SKIP_ERR
:
4331 /* Generate an ERROR chunk as response. */
4332 hdr
= unk_chunk
->chunk_hdr
;
4333 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4334 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4335 SCTP_PAD4(ntohs(hdr
->length
)),
4338 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4339 SCTP_CHUNK(err_chunk
));
4341 /* Skip the chunk. */
4342 return SCTP_DISPOSITION_CONSUME
;
4347 return SCTP_DISPOSITION_DISCARD
;
4351 * Discard the chunk.
4353 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
4354 * [Too numerous to mention...]
4355 * Verification Tag: No verification needed.
4357 * (endpoint, asoc, chunk)
4360 * (asoc, reply_msg, msg_up, timers, counters)
4362 * The return value is the disposition of the chunk.
4364 enum sctp_disposition
sctp_sf_discard_chunk(struct net
*net
,
4365 const struct sctp_endpoint
*ep
,
4366 const struct sctp_association
*asoc
,
4367 const union sctp_subtype type
,
4369 struct sctp_cmd_seq
*commands
)
4371 struct sctp_chunk
*chunk
= arg
;
4373 /* Make sure that the chunk has a valid length.
4374 * Since we don't know the chunk type, we use a general
4375 * chunkhdr structure to make a comparison.
4377 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
4378 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4381 pr_debug("%s: chunk:%d is discarded\n", __func__
, type
.chunk
);
4383 return SCTP_DISPOSITION_DISCARD
;
4387 * Discard the whole packet.
4391 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
4392 * silently discard the OOTB packet and take no further action.
4394 * Verification Tag: No verification necessary
4397 * (endpoint, asoc, chunk)
4400 * (asoc, reply_msg, msg_up, timers, counters)
4402 * The return value is the disposition of the chunk.
4404 enum sctp_disposition
sctp_sf_pdiscard(struct net
*net
,
4405 const struct sctp_endpoint
*ep
,
4406 const struct sctp_association
*asoc
,
4407 const union sctp_subtype type
,
4408 void *arg
, struct sctp_cmd_seq
*commands
)
4410 SCTP_INC_STATS(net
, SCTP_MIB_IN_PKT_DISCARDS
);
4411 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
4413 return SCTP_DISPOSITION_CONSUME
;
4418 * The other end is violating protocol.
4420 * Section: Not specified
4421 * Verification Tag: Not specified
4423 * (endpoint, asoc, chunk)
4426 * (asoc, reply_msg, msg_up, timers, counters)
4428 * We simply tag the chunk as a violation. The state machine will log
4429 * the violation and continue.
4431 enum sctp_disposition
sctp_sf_violation(struct net
*net
,
4432 const struct sctp_endpoint
*ep
,
4433 const struct sctp_association
*asoc
,
4434 const union sctp_subtype type
,
4436 struct sctp_cmd_seq
*commands
)
4438 struct sctp_chunk
*chunk
= arg
;
4440 /* Make sure that the chunk has a valid length. */
4441 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
4442 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4445 return SCTP_DISPOSITION_VIOLATION
;
4449 * Common function to handle a protocol violation.
4451 static enum sctp_disposition
sctp_sf_abort_violation(
4453 const struct sctp_endpoint
*ep
,
4454 const struct sctp_association
*asoc
,
4456 struct sctp_cmd_seq
*commands
,
4457 const __u8
*payload
,
4458 const size_t paylen
)
4460 struct sctp_packet
*packet
= NULL
;
4461 struct sctp_chunk
*chunk
= arg
;
4462 struct sctp_chunk
*abort
= NULL
;
4464 /* SCTP-AUTH, Section 6.3:
4465 * It should be noted that if the receiver wants to tear
4466 * down an association in an authenticated way only, the
4467 * handling of malformed packets should not result in
4468 * tearing down the association.
4470 * This means that if we only want to abort associations
4471 * in an authenticated way (i.e AUTH+ABORT), then we
4472 * can't destroy this association just because the packet
4475 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4478 /* Make the abort chunk. */
4479 abort
= sctp_make_abort_violation(asoc
, chunk
, payload
, paylen
);
4484 /* Treat INIT-ACK as a special case during COOKIE-WAIT. */
4485 if (chunk
->chunk_hdr
->type
== SCTP_CID_INIT_ACK
&&
4486 !asoc
->peer
.i
.init_tag
) {
4487 struct sctp_initack_chunk
*initack
;
4489 initack
= (struct sctp_initack_chunk
*)chunk
->chunk_hdr
;
4490 if (!sctp_chunk_length_valid(chunk
, sizeof(*initack
)))
4491 abort
->chunk_hdr
->flags
|= SCTP_CHUNK_FLAG_T
;
4493 unsigned int inittag
;
4495 inittag
= ntohl(initack
->init_hdr
.init_tag
);
4496 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_INITTAG
,
4501 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4502 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4504 if (asoc
->state
<= SCTP_STATE_COOKIE_ECHOED
) {
4505 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4506 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4507 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4508 SCTP_ERROR(ECONNREFUSED
));
4509 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4510 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4512 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4513 SCTP_ERROR(ECONNABORTED
));
4514 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4515 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4516 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4519 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
4524 if (sctp_test_T_bit(abort
))
4525 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
4527 abort
->skb
->sk
= ep
->base
.sk
;
4529 sctp_packet_append_chunk(packet
, abort
);
4531 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
4532 SCTP_PACKET(packet
));
4534 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4537 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4540 sctp_sf_pdiscard(net
, ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4541 return SCTP_DISPOSITION_ABORT
;
4544 sctp_chunk_free(abort
);
4546 return SCTP_DISPOSITION_NOMEM
;
4550 * Handle a protocol violation when the chunk length is invalid.
4551 * "Invalid" length is identified as smaller than the minimal length a
4552 * given chunk can be. For example, a SACK chunk has invalid length
4553 * if its length is set to be smaller than the size of struct sctp_sack_chunk.
4555 * We inform the other end by sending an ABORT with a Protocol Violation
4558 * Section: Not specified
4559 * Verification Tag: Nothing to do
4561 * (endpoint, asoc, chunk)
4564 * (reply_msg, msg_up, counters)
4566 * Generate an ABORT chunk and terminate the association.
4568 static enum sctp_disposition
sctp_sf_violation_chunklen(
4570 const struct sctp_endpoint
*ep
,
4571 const struct sctp_association
*asoc
,
4572 const union sctp_subtype type
,
4574 struct sctp_cmd_seq
*commands
)
4576 static const char err_str
[] = "The following chunk had invalid length:";
4578 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4583 * Handle a protocol violation when the parameter length is invalid.
4584 * If the length is smaller than the minimum length of a given parameter,
4585 * or accumulated length in multi parameters exceeds the end of the chunk,
4586 * the length is considered as invalid.
4588 static enum sctp_disposition
sctp_sf_violation_paramlen(
4590 const struct sctp_endpoint
*ep
,
4591 const struct sctp_association
*asoc
,
4592 const union sctp_subtype type
,
4593 void *arg
, void *ext
,
4594 struct sctp_cmd_seq
*commands
)
4596 struct sctp_paramhdr
*param
= ext
;
4597 struct sctp_chunk
*abort
= NULL
;
4598 struct sctp_chunk
*chunk
= arg
;
4600 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4603 /* Make the abort chunk. */
4604 abort
= sctp_make_violation_paramlen(asoc
, chunk
, param
);
4608 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4609 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4611 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4612 SCTP_ERROR(ECONNABORTED
));
4613 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4614 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4615 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4616 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4619 sctp_sf_pdiscard(net
, ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4620 return SCTP_DISPOSITION_ABORT
;
4622 return SCTP_DISPOSITION_NOMEM
;
4625 /* Handle a protocol violation when the peer trying to advance the
4626 * cumulative tsn ack to a point beyond the max tsn currently sent.
4628 * We inform the other end by sending an ABORT with a Protocol Violation
4631 static enum sctp_disposition
sctp_sf_violation_ctsn(
4633 const struct sctp_endpoint
*ep
,
4634 const struct sctp_association
*asoc
,
4635 const union sctp_subtype type
,
4637 struct sctp_cmd_seq
*commands
)
4639 static const char err_str
[] = "The cumulative tsn ack beyond the max tsn currently sent:";
4641 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4645 /* Handle protocol violation of an invalid chunk bundling. For example,
4646 * when we have an association and we receive bundled INIT-ACK, or
4647 * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle"
4648 * statement from the specs. Additionally, there might be an attacker
4649 * on the path and we may not want to continue this communication.
4651 static enum sctp_disposition
sctp_sf_violation_chunk(
4653 const struct sctp_endpoint
*ep
,
4654 const struct sctp_association
*asoc
,
4655 const union sctp_subtype type
,
4657 struct sctp_cmd_seq
*commands
)
4659 static const char err_str
[] = "The following chunk violates protocol:";
4662 return sctp_sf_violation(net
, ep
, asoc
, type
, arg
, commands
);
4664 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4667 /***************************************************************************
4668 * These are the state functions for handling primitive (Section 10) events.
4669 ***************************************************************************/
4671 * sctp_sf_do_prm_asoc
4673 * Section: 10.1 ULP-to-SCTP
4676 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
4677 * outbound stream count)
4678 * -> association id [,destination transport addr list] [,outbound stream
4681 * This primitive allows the upper layer to initiate an association to a
4682 * specific peer endpoint.
4684 * The peer endpoint shall be specified by one of the transport addresses
4685 * which defines the endpoint (see Section 1.4). If the local SCTP
4686 * instance has not been initialized, the ASSOCIATE is considered an
4688 * [This is not relevant for the kernel implementation since we do all
4689 * initialization at boot time. It we hadn't initialized we wouldn't
4690 * get anywhere near this code.]
4692 * An association id, which is a local handle to the SCTP association,
4693 * will be returned on successful establishment of the association. If
4694 * SCTP is not able to open an SCTP association with the peer endpoint,
4695 * an error is returned.
4696 * [In the kernel implementation, the struct sctp_association needs to
4697 * be created BEFORE causing this primitive to run.]
4699 * Other association parameters may be returned, including the
4700 * complete destination transport addresses of the peer as well as the
4701 * outbound stream count of the local endpoint. One of the transport
4702 * address from the returned destination addresses will be selected by
4703 * the local endpoint as default primary path for sending SCTP packets
4704 * to this peer. The returned "destination transport addr list" can
4705 * be used by the ULP to change the default primary path or to force
4706 * sending a packet to a specific transport address. [All of this
4707 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
4710 * Mandatory attributes:
4712 * o local SCTP instance name - obtained from the INITIALIZE operation.
4713 * [This is the argument asoc.]
4714 * o destination transport addr - specified as one of the transport
4715 * addresses of the peer endpoint with which the association is to be
4717 * [This is asoc->peer.active_path.]
4718 * o outbound stream count - the number of outbound streams the ULP
4719 * would like to open towards this peer endpoint.
4720 * [BUG: This is not currently implemented.]
4721 * Optional attributes:
4725 * The return value is a disposition.
4727 enum sctp_disposition
sctp_sf_do_prm_asoc(struct net
*net
,
4728 const struct sctp_endpoint
*ep
,
4729 const struct sctp_association
*asoc
,
4730 const union sctp_subtype type
,
4732 struct sctp_cmd_seq
*commands
)
4734 struct sctp_association
*my_asoc
;
4735 struct sctp_chunk
*repl
;
4737 /* The comment below says that we enter COOKIE-WAIT AFTER
4738 * sending the INIT, but that doesn't actually work in our
4741 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4742 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
4744 /* RFC 2960 5.1 Normal Establishment of an Association
4746 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
4747 * must provide its Verification Tag (Tag_A) in the Initiate
4748 * Tag field. Tag_A SHOULD be a random number in the range of
4749 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
4752 repl
= sctp_make_init(asoc
, &asoc
->base
.bind_addr
, GFP_ATOMIC
, 0);
4756 /* Choose transport for INIT. */
4757 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
4760 /* Cast away the const modifier, as we want to just
4761 * rerun it through as a sideffect.
4763 my_asoc
= (struct sctp_association
*)asoc
;
4764 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(my_asoc
));
4766 /* After sending the INIT, "A" starts the T1-init timer and
4767 * enters the COOKIE-WAIT state.
4769 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4770 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4771 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
4772 return SCTP_DISPOSITION_CONSUME
;
4775 return SCTP_DISPOSITION_NOMEM
;
4779 * Process the SEND primitive.
4781 * Section: 10.1 ULP-to-SCTP
4784 * Format: SEND(association id, buffer address, byte count [,context]
4785 * [,stream id] [,life time] [,destination transport address]
4786 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
4789 * This is the main method to send user data via SCTP.
4791 * Mandatory attributes:
4793 * o association id - local handle to the SCTP association
4795 * o buffer address - the location where the user message to be
4796 * transmitted is stored;
4798 * o byte count - The size of the user data in number of bytes;
4800 * Optional attributes:
4802 * o context - an optional 32 bit integer that will be carried in the
4803 * sending failure notification to the ULP if the transportation of
4804 * this User Message fails.
4806 * o stream id - to indicate which stream to send the data on. If not
4807 * specified, stream 0 will be used.
4809 * o life time - specifies the life time of the user data. The user data
4810 * will not be sent by SCTP after the life time expires. This
4811 * parameter can be used to avoid efforts to transmit stale
4812 * user messages. SCTP notifies the ULP if the data cannot be
4813 * initiated to transport (i.e. sent to the destination via SCTP's
4814 * send primitive) within the life time variable. However, the
4815 * user data will be transmitted if SCTP has attempted to transmit a
4816 * chunk before the life time expired.
4818 * o destination transport address - specified as one of the destination
4819 * transport addresses of the peer endpoint to which this packet
4820 * should be sent. Whenever possible, SCTP should use this destination
4821 * transport address for sending the packets, instead of the current
4824 * o unorder flag - this flag, if present, indicates that the user
4825 * would like the data delivered in an unordered fashion to the peer
4826 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
4829 * o no-bundle flag - instructs SCTP not to bundle this user data with
4830 * other outbound DATA chunks. SCTP MAY still bundle even when
4831 * this flag is present, when faced with network congestion.
4833 * o payload protocol-id - A 32 bit unsigned integer that is to be
4834 * passed to the peer indicating the type of payload protocol data
4835 * being transmitted. This value is passed as opaque data by SCTP.
4837 * The return value is the disposition.
4839 enum sctp_disposition
sctp_sf_do_prm_send(struct net
*net
,
4840 const struct sctp_endpoint
*ep
,
4841 const struct sctp_association
*asoc
,
4842 const union sctp_subtype type
,
4844 struct sctp_cmd_seq
*commands
)
4846 struct sctp_datamsg
*msg
= arg
;
4848 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_MSG
, SCTP_DATAMSG(msg
));
4849 return SCTP_DISPOSITION_CONSUME
;
4853 * Process the SHUTDOWN primitive.
4858 * Format: SHUTDOWN(association id)
4861 * Gracefully closes an association. Any locally queued user data
4862 * will be delivered to the peer. The association will be terminated only
4863 * after the peer acknowledges all the SCTP packets sent. A success code
4864 * will be returned on successful termination of the association. If
4865 * attempting to terminate the association results in a failure, an error
4866 * code shall be returned.
4868 * Mandatory attributes:
4870 * o association id - local handle to the SCTP association
4872 * Optional attributes:
4876 * The return value is the disposition.
4878 enum sctp_disposition
sctp_sf_do_9_2_prm_shutdown(
4880 const struct sctp_endpoint
*ep
,
4881 const struct sctp_association
*asoc
,
4882 const union sctp_subtype type
,
4884 struct sctp_cmd_seq
*commands
)
4886 enum sctp_disposition disposition
;
4888 /* From 9.2 Shutdown of an Association
4889 * Upon receipt of the SHUTDOWN primitive from its upper
4890 * layer, the endpoint enters SHUTDOWN-PENDING state and
4891 * remains there until all outstanding data has been
4892 * acknowledged by its peer. The endpoint accepts no new data
4893 * from its upper layer, but retransmits data to the far end
4894 * if necessary to fill gaps.
4896 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4897 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
4899 disposition
= SCTP_DISPOSITION_CONSUME
;
4900 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
4901 disposition
= sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
, type
,
4909 * Process the ABORT primitive.
4914 * Format: Abort(association id [, cause code])
4917 * Ungracefully closes an association. Any locally queued user data
4918 * will be discarded and an ABORT chunk is sent to the peer. A success code
4919 * will be returned on successful abortion of the association. If
4920 * attempting to abort the association results in a failure, an error
4921 * code shall be returned.
4923 * Mandatory attributes:
4925 * o association id - local handle to the SCTP association
4927 * Optional attributes:
4929 * o cause code - reason of the abort to be passed to the peer
4933 * The return value is the disposition.
4935 enum sctp_disposition
sctp_sf_do_9_1_prm_abort(
4937 const struct sctp_endpoint
*ep
,
4938 const struct sctp_association
*asoc
,
4939 const union sctp_subtype type
,
4941 struct sctp_cmd_seq
*commands
)
4943 /* From 9.1 Abort of an Association
4944 * Upon receipt of the ABORT primitive from its upper
4945 * layer, the endpoint enters CLOSED state and
4946 * discard all outstanding data has been
4947 * acknowledged by its peer. The endpoint accepts no new data
4948 * from its upper layer, but retransmits data to the far end
4949 * if necessary to fill gaps.
4951 struct sctp_chunk
*abort
= arg
;
4954 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4956 /* Even if we can't send the ABORT due to low memory delete the
4957 * TCB. This is a departure from our typical NOMEM handling.
4960 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4961 SCTP_ERROR(ECONNABORTED
));
4962 /* Delete the established association. */
4963 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4964 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4966 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4967 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4969 return SCTP_DISPOSITION_ABORT
;
4972 /* We tried an illegal operation on an association which is closed. */
4973 enum sctp_disposition
sctp_sf_error_closed(struct net
*net
,
4974 const struct sctp_endpoint
*ep
,
4975 const struct sctp_association
*asoc
,
4976 const union sctp_subtype type
,
4978 struct sctp_cmd_seq
*commands
)
4980 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
, SCTP_ERROR(-EINVAL
));
4981 return SCTP_DISPOSITION_CONSUME
;
4984 /* We tried an illegal operation on an association which is shutting
4987 enum sctp_disposition
sctp_sf_error_shutdown(
4989 const struct sctp_endpoint
*ep
,
4990 const struct sctp_association
*asoc
,
4991 const union sctp_subtype type
,
4993 struct sctp_cmd_seq
*commands
)
4995 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
,
4996 SCTP_ERROR(-ESHUTDOWN
));
4997 return SCTP_DISPOSITION_CONSUME
;
5001 * sctp_cookie_wait_prm_shutdown
5003 * Section: 4 Note: 2
5008 * The RFC does not explicitly address this issue, but is the route through the
5009 * state table when someone issues a shutdown while in COOKIE_WAIT state.
5014 enum sctp_disposition
sctp_sf_cookie_wait_prm_shutdown(
5016 const struct sctp_endpoint
*ep
,
5017 const struct sctp_association
*asoc
,
5018 const union sctp_subtype type
,
5020 struct sctp_cmd_seq
*commands
)
5022 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5023 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5025 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5026 SCTP_STATE(SCTP_STATE_CLOSED
));
5028 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
5030 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
5032 return SCTP_DISPOSITION_DELETE_TCB
;
5036 * sctp_cookie_echoed_prm_shutdown
5038 * Section: 4 Note: 2
5043 * The RFC does not explcitly address this issue, but is the route through the
5044 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
5049 enum sctp_disposition
sctp_sf_cookie_echoed_prm_shutdown(
5051 const struct sctp_endpoint
*ep
,
5052 const struct sctp_association
*asoc
,
5053 const union sctp_subtype type
,
5055 struct sctp_cmd_seq
*commands
)
5057 /* There is a single T1 timer, so we should be able to use
5058 * common function with the COOKIE-WAIT state.
5060 return sctp_sf_cookie_wait_prm_shutdown(net
, ep
, asoc
, type
, arg
, commands
);
5064 * sctp_sf_cookie_wait_prm_abort
5066 * Section: 4 Note: 2
5071 * The RFC does not explicitly address this issue, but is the route through the
5072 * state table when someone issues an abort while in COOKIE_WAIT state.
5077 enum sctp_disposition
sctp_sf_cookie_wait_prm_abort(
5079 const struct sctp_endpoint
*ep
,
5080 const struct sctp_association
*asoc
,
5081 const union sctp_subtype type
,
5083 struct sctp_cmd_seq
*commands
)
5085 struct sctp_chunk
*abort
= arg
;
5087 /* Stop T1-init timer */
5088 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5089 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5092 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
5094 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5095 SCTP_STATE(SCTP_STATE_CLOSED
));
5097 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5099 /* Even if we can't send the ABORT due to low memory delete the
5100 * TCB. This is a departure from our typical NOMEM handling.
5103 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5104 SCTP_ERROR(ECONNREFUSED
));
5105 /* Delete the established association. */
5106 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5107 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
5109 return SCTP_DISPOSITION_ABORT
;
5113 * sctp_sf_cookie_echoed_prm_abort
5115 * Section: 4 Note: 3
5120 * The RFC does not explcitly address this issue, but is the route through the
5121 * state table when someone issues an abort while in COOKIE_ECHOED state.
5126 enum sctp_disposition
sctp_sf_cookie_echoed_prm_abort(
5128 const struct sctp_endpoint
*ep
,
5129 const struct sctp_association
*asoc
,
5130 const union sctp_subtype type
,
5132 struct sctp_cmd_seq
*commands
)
5134 /* There is a single T1 timer, so we should be able to use
5135 * common function with the COOKIE-WAIT state.
5137 return sctp_sf_cookie_wait_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5141 * sctp_sf_shutdown_pending_prm_abort
5146 * The RFC does not explicitly address this issue, but is the route through the
5147 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
5152 enum sctp_disposition
sctp_sf_shutdown_pending_prm_abort(
5154 const struct sctp_endpoint
*ep
,
5155 const struct sctp_association
*asoc
,
5156 const union sctp_subtype type
,
5158 struct sctp_cmd_seq
*commands
)
5160 /* Stop the T5-shutdown guard timer. */
5161 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5162 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5164 return sctp_sf_do_9_1_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5168 * sctp_sf_shutdown_sent_prm_abort
5173 * The RFC does not explicitly address this issue, but is the route through the
5174 * state table when someone issues an abort while in SHUTDOWN-SENT state.
5179 enum sctp_disposition
sctp_sf_shutdown_sent_prm_abort(
5181 const struct sctp_endpoint
*ep
,
5182 const struct sctp_association
*asoc
,
5183 const union sctp_subtype type
,
5185 struct sctp_cmd_seq
*commands
)
5187 /* Stop the T2-shutdown timer. */
5188 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5189 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5191 /* Stop the T5-shutdown guard timer. */
5192 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5193 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5195 return sctp_sf_do_9_1_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5199 * sctp_sf_cookie_echoed_prm_abort
5204 * The RFC does not explcitly address this issue, but is the route through the
5205 * state table when someone issues an abort while in COOKIE_ECHOED state.
5210 enum sctp_disposition
sctp_sf_shutdown_ack_sent_prm_abort(
5212 const struct sctp_endpoint
*ep
,
5213 const struct sctp_association
*asoc
,
5214 const union sctp_subtype type
,
5216 struct sctp_cmd_seq
*commands
)
5218 /* The same T2 timer, so we should be able to use
5219 * common function with the SHUTDOWN-SENT state.
5221 return sctp_sf_shutdown_sent_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5225 * Process the REQUESTHEARTBEAT primitive
5228 * J) Request Heartbeat
5230 * Format: REQUESTHEARTBEAT(association id, destination transport address)
5234 * Instructs the local endpoint to perform a HeartBeat on the specified
5235 * destination transport address of the given association. The returned
5236 * result should indicate whether the transmission of the HEARTBEAT
5237 * chunk to the destination address is successful.
5239 * Mandatory attributes:
5241 * o association id - local handle to the SCTP association
5243 * o destination transport address - the transport address of the
5244 * association on which a heartbeat should be issued.
5246 enum sctp_disposition
sctp_sf_do_prm_requestheartbeat(
5248 const struct sctp_endpoint
*ep
,
5249 const struct sctp_association
*asoc
,
5250 const union sctp_subtype type
,
5252 struct sctp_cmd_seq
*commands
)
5254 if (SCTP_DISPOSITION_NOMEM
== sctp_sf_heartbeat(ep
, asoc
, type
,
5255 (struct sctp_transport
*)arg
, commands
))
5256 return SCTP_DISPOSITION_NOMEM
;
5259 * RFC 2960 (bis), section 8.3
5261 * D) Request an on-demand HEARTBEAT on a specific destination
5262 * transport address of a given association.
5264 * The endpoint should increment the respective error counter of
5265 * the destination transport address each time a HEARTBEAT is sent
5266 * to that address and not acknowledged within one RTO.
5269 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
5270 SCTP_TRANSPORT(arg
));
5271 return SCTP_DISPOSITION_CONSUME
;
5275 * ADDIP Section 4.1 ASCONF Chunk Procedures
5276 * When an endpoint has an ASCONF signaled change to be sent to the
5277 * remote endpoint it should do A1 to A9
5279 enum sctp_disposition
sctp_sf_do_prm_asconf(struct net
*net
,
5280 const struct sctp_endpoint
*ep
,
5281 const struct sctp_association
*asoc
,
5282 const union sctp_subtype type
,
5284 struct sctp_cmd_seq
*commands
)
5286 struct sctp_chunk
*chunk
= arg
;
5288 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5289 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5290 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5291 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
5292 return SCTP_DISPOSITION_CONSUME
;
5295 /* RE-CONFIG Section 5.1 RECONF Chunk Procedures */
5296 enum sctp_disposition
sctp_sf_do_prm_reconf(struct net
*net
,
5297 const struct sctp_endpoint
*ep
,
5298 const struct sctp_association
*asoc
,
5299 const union sctp_subtype type
,
5301 struct sctp_cmd_seq
*commands
)
5303 struct sctp_chunk
*chunk
= arg
;
5305 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
5306 return SCTP_DISPOSITION_CONSUME
;
5310 * Ignore the primitive event
5312 * The return value is the disposition of the primitive.
5314 enum sctp_disposition
sctp_sf_ignore_primitive(
5316 const struct sctp_endpoint
*ep
,
5317 const struct sctp_association
*asoc
,
5318 const union sctp_subtype type
,
5320 struct sctp_cmd_seq
*commands
)
5322 pr_debug("%s: primitive type:%d is ignored\n", __func__
,
5325 return SCTP_DISPOSITION_DISCARD
;
5328 /***************************************************************************
5329 * These are the state functions for the OTHER events.
5330 ***************************************************************************/
5333 * When the SCTP stack has no more user data to send or retransmit, this
5334 * notification is given to the user. Also, at the time when a user app
5335 * subscribes to this event, if there is no data to be sent or
5336 * retransmit, the stack will immediately send up this notification.
5338 enum sctp_disposition
sctp_sf_do_no_pending_tsn(
5340 const struct sctp_endpoint
*ep
,
5341 const struct sctp_association
*asoc
,
5342 const union sctp_subtype type
,
5344 struct sctp_cmd_seq
*commands
)
5346 struct sctp_ulpevent
*event
;
5348 event
= sctp_ulpevent_make_sender_dry_event(asoc
, GFP_ATOMIC
);
5350 return SCTP_DISPOSITION_NOMEM
;
5352 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(event
));
5354 return SCTP_DISPOSITION_CONSUME
;
5358 * Start the shutdown negotiation.
5361 * Once all its outstanding data has been acknowledged, the endpoint
5362 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
5363 * TSN Ack field the last sequential TSN it has received from the peer.
5364 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
5365 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
5366 * with the updated last sequential TSN received from its peer.
5368 * The return value is the disposition.
5370 enum sctp_disposition
sctp_sf_do_9_2_start_shutdown(
5372 const struct sctp_endpoint
*ep
,
5373 const struct sctp_association
*asoc
,
5374 const union sctp_subtype type
,
5376 struct sctp_cmd_seq
*commands
)
5378 struct sctp_chunk
*reply
;
5380 /* Once all its outstanding data has been acknowledged, the
5381 * endpoint shall send a SHUTDOWN chunk to its peer including
5382 * in the Cumulative TSN Ack field the last sequential TSN it
5383 * has received from the peer.
5385 reply
= sctp_make_shutdown(asoc
, NULL
);
5389 /* Set the transport for the SHUTDOWN chunk and the timeout for the
5390 * T2-shutdown timer.
5392 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5394 /* It shall then start the T2-shutdown timer */
5395 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5396 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5398 /* RFC 4960 Section 9.2
5399 * The sender of the SHUTDOWN MAY also start an overall guard timer
5400 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5402 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5403 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5405 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
5406 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5407 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5409 /* and enter the SHUTDOWN-SENT state. */
5410 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5411 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT
));
5413 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5415 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5418 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5420 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5422 return SCTP_DISPOSITION_CONSUME
;
5425 return SCTP_DISPOSITION_NOMEM
;
5429 * Generate a SHUTDOWN ACK now that everything is SACK'd.
5433 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5434 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
5435 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
5436 * endpoint must re-send the SHUTDOWN ACK.
5438 * The return value is the disposition.
5440 enum sctp_disposition
sctp_sf_do_9_2_shutdown_ack(
5442 const struct sctp_endpoint
*ep
,
5443 const struct sctp_association
*asoc
,
5444 const union sctp_subtype type
,
5446 struct sctp_cmd_seq
*commands
)
5448 struct sctp_chunk
*chunk
= arg
;
5449 struct sctp_chunk
*reply
;
5451 /* There are 2 ways of getting here:
5452 * 1) called in response to a SHUTDOWN chunk
5453 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
5455 * For the case (2), the arg parameter is set to NULL. We need
5456 * to check that we have a chunk before accessing it's fields.
5459 if (!sctp_vtag_verify(chunk
, asoc
))
5460 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
,
5463 /* Make sure that the SHUTDOWN chunk has a valid length. */
5464 if (!sctp_chunk_length_valid(
5465 chunk
, sizeof(struct sctp_shutdown_chunk
)))
5466 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
,
5470 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5471 * shall send a SHUTDOWN ACK ...
5473 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
5477 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
5478 * the T2-shutdown timer.
5480 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5482 /* and start/restart a T2-shutdown timer of its own, */
5483 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5484 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5486 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
5487 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5488 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5490 /* Enter the SHUTDOWN-ACK-SENT state. */
5491 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5492 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT
));
5494 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5496 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5499 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5501 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5503 return SCTP_DISPOSITION_CONSUME
;
5506 return SCTP_DISPOSITION_NOMEM
;
5510 * Ignore the event defined as other
5512 * The return value is the disposition of the event.
5514 enum sctp_disposition
sctp_sf_ignore_other(struct net
*net
,
5515 const struct sctp_endpoint
*ep
,
5516 const struct sctp_association
*asoc
,
5517 const union sctp_subtype type
,
5519 struct sctp_cmd_seq
*commands
)
5521 pr_debug("%s: the event other type:%d is ignored\n",
5522 __func__
, type
.other
);
5524 return SCTP_DISPOSITION_DISCARD
;
5527 /************************************************************
5528 * These are the state functions for handling timeout events.
5529 ************************************************************/
5534 * Section: 6.3.3 Handle T3-rtx Expiration
5536 * Whenever the retransmission timer T3-rtx expires for a destination
5537 * address, do the following:
5540 * The return value is the disposition of the chunk.
5542 enum sctp_disposition
sctp_sf_do_6_3_3_rtx(struct net
*net
,
5543 const struct sctp_endpoint
*ep
,
5544 const struct sctp_association
*asoc
,
5545 const union sctp_subtype type
,
5547 struct sctp_cmd_seq
*commands
)
5549 struct sctp_transport
*transport
= arg
;
5551 SCTP_INC_STATS(net
, SCTP_MIB_T3_RTX_EXPIREDS
);
5553 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5554 if (asoc
->peer
.zero_window_announced
&&
5555 asoc
->state
== SCTP_STATE_SHUTDOWN_PENDING
) {
5557 * We are here likely because the receiver had its rwnd
5558 * closed for a while and we have not been able to
5559 * transmit the locally queued data within the maximum
5560 * retransmission attempts limit. Start the T5
5561 * shutdown guard timer to give the receiver one last
5562 * chance and some additional time to recover before
5565 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START_ONCE
,
5566 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5568 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5569 SCTP_ERROR(ETIMEDOUT
));
5570 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5571 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5572 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5573 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5574 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5575 return SCTP_DISPOSITION_DELETE_TCB
;
5579 /* E1) For the destination address for which the timer
5580 * expires, adjust its ssthresh with rules defined in Section
5581 * 7.2.3 and set the cwnd <- MTU.
5584 /* E2) For the destination address for which the timer
5585 * expires, set RTO <- RTO * 2 ("back off the timer"). The
5586 * maximum value discussed in rule C7 above (RTO.max) may be
5587 * used to provide an upper bound to this doubling operation.
5590 /* E3) Determine how many of the earliest (i.e., lowest TSN)
5591 * outstanding DATA chunks for the address for which the
5592 * T3-rtx has expired will fit into a single packet, subject
5593 * to the MTU constraint for the path corresponding to the
5594 * destination transport address to which the retransmission
5595 * is being sent (this may be different from the address for
5596 * which the timer expires [see Section 6.4]). Call this
5597 * value K. Bundle and retransmit those K DATA chunks in a
5598 * single packet to the destination endpoint.
5600 * Note: Any DATA chunks that were sent to the address for
5601 * which the T3-rtx timer expired but did not fit in one MTU
5602 * (rule E3 above), should be marked for retransmission and
5603 * sent as soon as cwnd allows (normally when a SACK arrives).
5606 /* Do some failure management (Section 8.2). */
5607 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
5609 /* NB: Rules E4 and F1 are implicit in R1. */
5610 sctp_add_cmd_sf(commands
, SCTP_CMD_RETRAN
, SCTP_TRANSPORT(transport
));
5612 return SCTP_DISPOSITION_CONSUME
;
5616 * Generate delayed SACK on timeout
5618 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
5620 * The guidelines on delayed acknowledgement algorithm specified in
5621 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
5622 * acknowledgement SHOULD be generated for at least every second packet
5623 * (not every second DATA chunk) received, and SHOULD be generated
5624 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
5625 * some situations it may be beneficial for an SCTP transmitter to be
5626 * more conservative than the algorithms detailed in this document
5627 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
5628 * the following algorithms allow.
5630 enum sctp_disposition
sctp_sf_do_6_2_sack(struct net
*net
,
5631 const struct sctp_endpoint
*ep
,
5632 const struct sctp_association
*asoc
,
5633 const union sctp_subtype type
,
5635 struct sctp_cmd_seq
*commands
)
5637 SCTP_INC_STATS(net
, SCTP_MIB_DELAY_SACK_EXPIREDS
);
5638 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
5639 return SCTP_DISPOSITION_CONSUME
;
5643 * sctp_sf_t1_init_timer_expire
5645 * Section: 4 Note: 2
5650 * RFC 2960 Section 4 Notes
5651 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
5652 * and re-start the T1-init timer without changing state. This MUST
5653 * be repeated up to 'Max.Init.Retransmits' times. After that, the
5654 * endpoint MUST abort the initialization process and report the
5655 * error to SCTP user.
5661 enum sctp_disposition
sctp_sf_t1_init_timer_expire(
5663 const struct sctp_endpoint
*ep
,
5664 const struct sctp_association
*asoc
,
5665 const union sctp_subtype type
,
5667 struct sctp_cmd_seq
*commands
)
5669 int attempts
= asoc
->init_err_counter
+ 1;
5670 struct sctp_chunk
*repl
= NULL
;
5671 struct sctp_bind_addr
*bp
;
5673 pr_debug("%s: timer T1 expired (INIT)\n", __func__
);
5675 SCTP_INC_STATS(net
, SCTP_MIB_T1_INIT_EXPIREDS
);
5677 if (attempts
<= asoc
->max_init_attempts
) {
5678 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
5679 repl
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, 0);
5681 return SCTP_DISPOSITION_NOMEM
;
5683 /* Choose transport for INIT. */
5684 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5687 /* Issue a sideeffect to do the needed accounting. */
5688 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_RESTART
,
5689 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5691 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5693 pr_debug("%s: giving up on INIT, attempts:%d "
5694 "max_init_attempts:%d\n", __func__
, attempts
,
5695 asoc
->max_init_attempts
);
5697 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5698 SCTP_ERROR(ETIMEDOUT
));
5699 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5700 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5701 return SCTP_DISPOSITION_DELETE_TCB
;
5704 return SCTP_DISPOSITION_CONSUME
;
5708 * sctp_sf_t1_cookie_timer_expire
5710 * Section: 4 Note: 2
5715 * RFC 2960 Section 4 Notes
5716 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
5717 * COOKIE ECHO and re-start the T1-cookie timer without changing
5718 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
5719 * After that, the endpoint MUST abort the initialization process and
5720 * report the error to SCTP user.
5726 enum sctp_disposition
sctp_sf_t1_cookie_timer_expire(
5728 const struct sctp_endpoint
*ep
,
5729 const struct sctp_association
*asoc
,
5730 const union sctp_subtype type
,
5732 struct sctp_cmd_seq
*commands
)
5734 int attempts
= asoc
->init_err_counter
+ 1;
5735 struct sctp_chunk
*repl
= NULL
;
5737 pr_debug("%s: timer T1 expired (COOKIE-ECHO)\n", __func__
);
5739 SCTP_INC_STATS(net
, SCTP_MIB_T1_COOKIE_EXPIREDS
);
5741 if (attempts
<= asoc
->max_init_attempts
) {
5742 repl
= sctp_make_cookie_echo(asoc
, NULL
);
5744 return SCTP_DISPOSITION_NOMEM
;
5746 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5748 /* Issue a sideeffect to do the needed accounting. */
5749 sctp_add_cmd_sf(commands
, SCTP_CMD_COOKIEECHO_RESTART
,
5750 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
5752 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5754 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5755 SCTP_ERROR(ETIMEDOUT
));
5756 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5757 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5758 return SCTP_DISPOSITION_DELETE_TCB
;
5761 return SCTP_DISPOSITION_CONSUME
;
5764 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
5765 * with the updated last sequential TSN received from its peer.
5767 * An endpoint should limit the number of retransmissions of the
5768 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
5769 * If this threshold is exceeded the endpoint should destroy the TCB and
5770 * MUST report the peer endpoint unreachable to the upper layer (and
5771 * thus the association enters the CLOSED state). The reception of any
5772 * packet from its peer (i.e. as the peer sends all of its queued DATA
5773 * chunks) should clear the endpoint's retransmission count and restart
5774 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
5775 * all of its queued DATA chunks that have not yet been sent.
5777 enum sctp_disposition
sctp_sf_t2_timer_expire(
5779 const struct sctp_endpoint
*ep
,
5780 const struct sctp_association
*asoc
,
5781 const union sctp_subtype type
,
5783 struct sctp_cmd_seq
*commands
)
5785 struct sctp_chunk
*reply
= NULL
;
5787 pr_debug("%s: timer T2 expired\n", __func__
);
5789 SCTP_INC_STATS(net
, SCTP_MIB_T2_SHUTDOWN_EXPIREDS
);
5791 ((struct sctp_association
*)asoc
)->shutdown_retries
++;
5793 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5794 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5795 SCTP_ERROR(ETIMEDOUT
));
5796 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5797 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5798 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5799 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5800 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5801 return SCTP_DISPOSITION_DELETE_TCB
;
5804 switch (asoc
->state
) {
5805 case SCTP_STATE_SHUTDOWN_SENT
:
5806 reply
= sctp_make_shutdown(asoc
, NULL
);
5809 case SCTP_STATE_SHUTDOWN_ACK_SENT
:
5810 reply
= sctp_make_shutdown_ack(asoc
, NULL
);
5821 /* Do some failure management (Section 8.2).
5822 * If we remove the transport an SHUTDOWN was last sent to, don't
5823 * do failure management.
5825 if (asoc
->shutdown_last_sent_to
)
5826 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5827 SCTP_TRANSPORT(asoc
->shutdown_last_sent_to
));
5829 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
5830 * the T2-shutdown timer.
5832 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5834 /* Restart the T2-shutdown timer. */
5835 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5836 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5837 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5838 return SCTP_DISPOSITION_CONSUME
;
5841 return SCTP_DISPOSITION_NOMEM
;
5845 * ADDIP Section 4.1 ASCONF CHunk Procedures
5846 * If the T4 RTO timer expires the endpoint should do B1 to B5
5848 enum sctp_disposition
sctp_sf_t4_timer_expire(
5850 const struct sctp_endpoint
*ep
,
5851 const struct sctp_association
*asoc
,
5852 const union sctp_subtype type
,
5854 struct sctp_cmd_seq
*commands
)
5856 struct sctp_chunk
*chunk
= asoc
->addip_last_asconf
;
5857 struct sctp_transport
*transport
= chunk
->transport
;
5859 SCTP_INC_STATS(net
, SCTP_MIB_T4_RTO_EXPIREDS
);
5861 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
5862 * detection on the appropriate destination address as defined in
5863 * RFC2960 [5] section 8.1 and 8.2.
5866 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5867 SCTP_TRANSPORT(transport
));
5869 /* Reconfig T4 timer and transport. */
5870 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5872 /* ADDIP 4.1 B2) Increment the association error counters and perform
5873 * endpoint failure detection on the association as defined in
5874 * RFC2960 [5] section 8.1 and 8.2.
5875 * association error counter is incremented in SCTP_CMD_STRIKE.
5877 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5878 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5879 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5880 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5881 SCTP_ERROR(ETIMEDOUT
));
5882 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5883 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5884 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5885 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5886 return SCTP_DISPOSITION_ABORT
;
5889 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
5890 * the ASCONF chunk was sent by doubling the RTO timer value.
5891 * This is done in SCTP_CMD_STRIKE.
5894 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
5895 * choose an alternate destination address (please refer to RFC2960
5896 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
5897 * chunk, it MUST be the same (including its serial number) as the last
5900 sctp_chunk_hold(asoc
->addip_last_asconf
);
5901 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5902 SCTP_CHUNK(asoc
->addip_last_asconf
));
5904 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
5905 * destination is selected, then the RTO used will be that of the new
5906 * destination address.
5908 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5909 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5911 return SCTP_DISPOSITION_CONSUME
;
5914 /* sctpimpguide-05 Section 2.12.2
5915 * The sender of the SHUTDOWN MAY also start an overall guard timer
5916 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5917 * At the expiration of this timer the sender SHOULD abort the association
5918 * by sending an ABORT chunk.
5920 enum sctp_disposition
sctp_sf_t5_timer_expire(
5922 const struct sctp_endpoint
*ep
,
5923 const struct sctp_association
*asoc
,
5924 const union sctp_subtype type
,
5926 struct sctp_cmd_seq
*commands
)
5928 struct sctp_chunk
*reply
= NULL
;
5930 pr_debug("%s: timer T5 expired\n", __func__
);
5932 SCTP_INC_STATS(net
, SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS
);
5934 reply
= sctp_make_abort(asoc
, NULL
, 0);
5938 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5939 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5940 SCTP_ERROR(ETIMEDOUT
));
5941 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5942 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5944 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5945 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5947 return SCTP_DISPOSITION_DELETE_TCB
;
5949 return SCTP_DISPOSITION_NOMEM
;
5952 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
5953 * the association is automatically closed by starting the shutdown process.
5954 * The work that needs to be done is same as when SHUTDOWN is initiated by
5955 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
5957 enum sctp_disposition
sctp_sf_autoclose_timer_expire(
5959 const struct sctp_endpoint
*ep
,
5960 const struct sctp_association
*asoc
,
5961 const union sctp_subtype type
,
5963 struct sctp_cmd_seq
*commands
)
5965 enum sctp_disposition disposition
;
5967 SCTP_INC_STATS(net
, SCTP_MIB_AUTOCLOSE_EXPIREDS
);
5969 /* From 9.2 Shutdown of an Association
5970 * Upon receipt of the SHUTDOWN primitive from its upper
5971 * layer, the endpoint enters SHUTDOWN-PENDING state and
5972 * remains there until all outstanding data has been
5973 * acknowledged by its peer. The endpoint accepts no new data
5974 * from its upper layer, but retransmits data to the far end
5975 * if necessary to fill gaps.
5977 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5978 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
5980 disposition
= SCTP_DISPOSITION_CONSUME
;
5981 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
5982 disposition
= sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
, type
,
5989 /*****************************************************************************
5990 * These are sa state functions which could apply to all types of events.
5991 ****************************************************************************/
5994 * This table entry is not implemented.
5997 * (endpoint, asoc, chunk)
5999 * The return value is the disposition of the chunk.
6001 enum sctp_disposition
sctp_sf_not_impl(struct net
*net
,
6002 const struct sctp_endpoint
*ep
,
6003 const struct sctp_association
*asoc
,
6004 const union sctp_subtype type
,
6005 void *arg
, struct sctp_cmd_seq
*commands
)
6007 return SCTP_DISPOSITION_NOT_IMPL
;
6011 * This table entry represents a bug.
6014 * (endpoint, asoc, chunk)
6016 * The return value is the disposition of the chunk.
6018 enum sctp_disposition
sctp_sf_bug(struct net
*net
,
6019 const struct sctp_endpoint
*ep
,
6020 const struct sctp_association
*asoc
,
6021 const union sctp_subtype type
,
6022 void *arg
, struct sctp_cmd_seq
*commands
)
6024 return SCTP_DISPOSITION_BUG
;
6028 * This table entry represents the firing of a timer in the wrong state.
6029 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
6030 * when the association is in the wrong state. This event should
6031 * be ignored, so as to prevent any rearming of the timer.
6034 * (endpoint, asoc, chunk)
6036 * The return value is the disposition of the chunk.
6038 enum sctp_disposition
sctp_sf_timer_ignore(struct net
*net
,
6039 const struct sctp_endpoint
*ep
,
6040 const struct sctp_association
*asoc
,
6041 const union sctp_subtype type
,
6043 struct sctp_cmd_seq
*commands
)
6045 pr_debug("%s: timer %d ignored\n", __func__
, type
.chunk
);
6047 return SCTP_DISPOSITION_CONSUME
;
6050 /********************************************************************
6051 * 2nd Level Abstractions
6052 ********************************************************************/
6054 /* Pull the SACK chunk based on the SACK header. */
6055 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
)
6057 struct sctp_sackhdr
*sack
;
6062 /* Protect ourselves from reading too far into
6063 * the skb from a bogus sender.
6065 sack
= (struct sctp_sackhdr
*) chunk
->skb
->data
;
6067 num_blocks
= ntohs(sack
->num_gap_ack_blocks
);
6068 num_dup_tsns
= ntohs(sack
->num_dup_tsns
);
6069 len
= sizeof(struct sctp_sackhdr
);
6070 len
+= (num_blocks
+ num_dup_tsns
) * sizeof(__u32
);
6071 if (len
> chunk
->skb
->len
)
6074 skb_pull(chunk
->skb
, len
);
6079 /* Create an ABORT packet to be sent as a response, with the specified
6082 static struct sctp_packet
*sctp_abort_pkt_new(
6084 const struct sctp_endpoint
*ep
,
6085 const struct sctp_association
*asoc
,
6086 struct sctp_chunk
*chunk
,
6087 const void *payload
, size_t paylen
)
6089 struct sctp_packet
*packet
;
6090 struct sctp_chunk
*abort
;
6092 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
6096 * The T bit will be set if the asoc is NULL.
6098 abort
= sctp_make_abort(asoc
, chunk
, paylen
);
6100 sctp_ootb_pkt_free(packet
);
6104 /* Reflect vtag if T-Bit is set */
6105 if (sctp_test_T_bit(abort
))
6106 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
6108 /* Add specified error causes, i.e., payload, to the
6111 sctp_addto_chunk(abort
, paylen
, payload
);
6113 /* Set the skb to the belonging sock for accounting. */
6114 abort
->skb
->sk
= ep
->base
.sk
;
6116 sctp_packet_append_chunk(packet
, abort
);
6123 /* Allocate a packet for responding in the OOTB conditions. */
6124 static struct sctp_packet
*sctp_ootb_pkt_new(
6126 const struct sctp_association
*asoc
,
6127 const struct sctp_chunk
*chunk
)
6129 struct sctp_transport
*transport
;
6130 struct sctp_packet
*packet
;
6134 /* Get the source and destination port from the inbound packet. */
6135 sport
= ntohs(chunk
->sctp_hdr
->dest
);
6136 dport
= ntohs(chunk
->sctp_hdr
->source
);
6138 /* The V-tag is going to be the same as the inbound packet if no
6139 * association exists, otherwise, use the peer's vtag.
6142 /* Special case the INIT-ACK as there is no peer's vtag
6145 switch (chunk
->chunk_hdr
->type
) {
6146 case SCTP_CID_INIT_ACK
:
6148 struct sctp_initack_chunk
*initack
;
6150 initack
= (struct sctp_initack_chunk
*)chunk
->chunk_hdr
;
6151 vtag
= ntohl(initack
->init_hdr
.init_tag
);
6155 vtag
= asoc
->peer
.i
.init_tag
;
6159 /* Special case the INIT and stale COOKIE_ECHO as there is no
6162 switch (chunk
->chunk_hdr
->type
) {
6165 struct sctp_init_chunk
*init
;
6167 init
= (struct sctp_init_chunk
*)chunk
->chunk_hdr
;
6168 vtag
= ntohl(init
->init_hdr
.init_tag
);
6172 vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
6177 /* Make a transport for the bucket, Eliza... */
6178 transport
= sctp_transport_new(net
, sctp_source(chunk
), GFP_ATOMIC
);
6182 /* Cache a route for the transport with the chunk's destination as
6183 * the source address.
6185 sctp_transport_route(transport
, (union sctp_addr
*)&chunk
->dest
,
6186 sctp_sk(net
->sctp
.ctl_sock
));
6188 packet
= &transport
->packet
;
6189 sctp_packet_init(packet
, transport
, sport
, dport
);
6190 sctp_packet_config(packet
, vtag
, 0);
6198 /* Free the packet allocated earlier for responding in the OOTB condition. */
6199 void sctp_ootb_pkt_free(struct sctp_packet
*packet
)
6201 sctp_transport_free(packet
->transport
);
6204 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
6205 static void sctp_send_stale_cookie_err(struct net
*net
,
6206 const struct sctp_endpoint
*ep
,
6207 const struct sctp_association
*asoc
,
6208 const struct sctp_chunk
*chunk
,
6209 struct sctp_cmd_seq
*commands
,
6210 struct sctp_chunk
*err_chunk
)
6212 struct sctp_packet
*packet
;
6215 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
6217 struct sctp_signed_cookie
*cookie
;
6219 /* Override the OOTB vtag from the cookie. */
6220 cookie
= chunk
->subh
.cookie_hdr
;
6221 packet
->vtag
= cookie
->c
.peer_vtag
;
6223 /* Set the skb to the belonging sock for accounting. */
6224 err_chunk
->skb
->sk
= ep
->base
.sk
;
6225 sctp_packet_append_chunk(packet
, err_chunk
);
6226 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
6227 SCTP_PACKET(packet
));
6228 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
6230 sctp_chunk_free (err_chunk
);
6235 /* Process a data chunk */
6236 static int sctp_eat_data(const struct sctp_association
*asoc
,
6237 struct sctp_chunk
*chunk
,
6238 struct sctp_cmd_seq
*commands
)
6240 struct sctp_tsnmap
*map
= (struct sctp_tsnmap
*)&asoc
->peer
.tsn_map
;
6241 struct sock
*sk
= asoc
->base
.sk
;
6242 struct net
*net
= sock_net(sk
);
6243 struct sctp_datahdr
*data_hdr
;
6244 struct sctp_chunk
*err
;
6245 enum sctp_verb deliver
;
6252 data_hdr
= (struct sctp_datahdr
*)chunk
->skb
->data
;
6253 chunk
->subh
.data_hdr
= data_hdr
;
6254 skb_pull(chunk
->skb
, sizeof(*data_hdr
));
6256 tsn
= ntohl(data_hdr
->tsn
);
6257 pr_debug("%s: TSN 0x%x\n", __func__
, tsn
);
6259 /* ASSERT: Now skb->data is really the user data. */
6261 /* Process ECN based congestion.
6263 * Since the chunk structure is reused for all chunks within
6264 * a packet, we use ecn_ce_done to track if we've already
6265 * done CE processing for this packet.
6267 * We need to do ECN processing even if we plan to discard the
6271 if (asoc
->peer
.ecn_capable
&& !chunk
->ecn_ce_done
) {
6272 struct sctp_af
*af
= SCTP_INPUT_CB(chunk
->skb
)->af
;
6273 chunk
->ecn_ce_done
= 1;
6275 if (af
->is_ce(sctp_gso_headskb(chunk
->skb
))) {
6276 /* Do real work as sideffect. */
6277 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_CE
,
6282 tmp
= sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
);
6284 /* The TSN is too high--silently discard the chunk and
6285 * count on it getting retransmitted later.
6288 chunk
->asoc
->stats
.outofseqtsns
++;
6289 return SCTP_IERROR_HIGH_TSN
;
6290 } else if (tmp
> 0) {
6291 /* This is a duplicate. Record it. */
6292 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_DUP
, SCTP_U32(tsn
));
6293 return SCTP_IERROR_DUP_TSN
;
6296 /* This is a new TSN. */
6298 /* Discard if there is no room in the receive window.
6299 * Actually, allow a little bit of overflow (up to a MTU).
6301 datalen
= ntohs(chunk
->chunk_hdr
->length
);
6302 datalen
-= sizeof(struct sctp_data_chunk
);
6304 deliver
= SCTP_CMD_CHUNK_ULP
;
6306 /* Think about partial delivery. */
6307 if ((datalen
>= asoc
->rwnd
) && (!asoc
->ulpq
.pd_mode
)) {
6309 /* Even if we don't accept this chunk there is
6312 sctp_add_cmd_sf(commands
, SCTP_CMD_PART_DELIVER
, SCTP_NULL());
6315 /* Spill over rwnd a little bit. Note: While allowed, this spill over
6316 * seems a bit troublesome in that frag_point varies based on
6317 * PMTU. In cases, such as loopback, this might be a rather
6320 if ((!chunk
->data_accepted
) && (!asoc
->rwnd
|| asoc
->rwnd_over
||
6321 (datalen
> asoc
->rwnd
+ asoc
->frag_point
))) {
6323 /* If this is the next TSN, consider reneging to make
6324 * room. Note: Playing nice with a confused sender. A
6325 * malicious sender can still eat up all our buffer
6326 * space and in the future we may want to detect and
6327 * do more drastic reneging.
6329 if (sctp_tsnmap_has_gap(map
) &&
6330 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
6331 pr_debug("%s: reneging for tsn:%u\n", __func__
, tsn
);
6332 deliver
= SCTP_CMD_RENEGE
;
6334 pr_debug("%s: discard tsn:%u len:%zu, rwnd:%d\n",
6335 __func__
, tsn
, datalen
, asoc
->rwnd
);
6337 return SCTP_IERROR_IGNORE_TSN
;
6342 * Also try to renege to limit our memory usage in the event that
6343 * we are under memory pressure
6344 * If we can't renege, don't worry about it, the sk_rmem_schedule
6345 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
6346 * memory usage too much
6348 if (*sk
->sk_prot_creator
->memory_pressure
) {
6349 if (sctp_tsnmap_has_gap(map
) &&
6350 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
6351 pr_debug("%s: under pressure, reneging for tsn:%u\n",
6353 deliver
= SCTP_CMD_RENEGE
;
6358 * Section 3.3.10.9 No User Data (9)
6362 * No User Data: This error cause is returned to the originator of a
6363 * DATA chunk if a received DATA chunk has no user data.
6365 if (unlikely(0 == datalen
)) {
6366 err
= sctp_make_abort_no_data(asoc
, chunk
, tsn
);
6368 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6371 /* We are going to ABORT, so we might as well stop
6372 * processing the rest of the chunks in the packet.
6374 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
6375 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
6376 SCTP_ERROR(ECONNABORTED
));
6377 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
6378 SCTP_PERR(SCTP_ERROR_NO_DATA
));
6379 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
6380 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
6381 return SCTP_IERROR_NO_DATA
;
6384 chunk
->data_accepted
= 1;
6386 /* Note: Some chunks may get overcounted (if we drop) or overcounted
6387 * if we renege and the chunk arrives again.
6389 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_UNORDERED
) {
6390 SCTP_INC_STATS(net
, SCTP_MIB_INUNORDERCHUNKS
);
6392 chunk
->asoc
->stats
.iuodchunks
++;
6394 SCTP_INC_STATS(net
, SCTP_MIB_INORDERCHUNKS
);
6396 chunk
->asoc
->stats
.iodchunks
++;
6400 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
6402 * If an endpoint receive a DATA chunk with an invalid stream
6403 * identifier, it shall acknowledge the reception of the DATA chunk
6404 * following the normal procedure, immediately send an ERROR chunk
6405 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
6406 * and discard the DATA chunk.
6408 sid
= ntohs(data_hdr
->stream
);
6409 if (sid
>= asoc
->stream
.incnt
) {
6410 /* Mark tsn as received even though we drop it */
6411 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_TSN
, SCTP_U32(tsn
));
6413 err
= sctp_make_op_error(asoc
, chunk
, SCTP_ERROR_INV_STRM
,
6415 sizeof(data_hdr
->stream
),
6418 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6420 return SCTP_IERROR_BAD_STREAM
;
6423 /* Check to see if the SSN is possible for this TSN.
6424 * The biggest gap we can record is 4K wide. Since SSNs wrap
6425 * at an unsigned short, there is no way that an SSN can
6426 * wrap and for a valid TSN. We can simply check if the current
6427 * SSN is smaller then the next expected one. If it is, it wrapped
6430 ssn
= ntohs(data_hdr
->ssn
);
6431 if (ordered
&& SSN_lt(ssn
, sctp_ssn_peek(&asoc
->stream
, in
, sid
)))
6432 return SCTP_IERROR_PROTO_VIOLATION
;
6434 /* Send the data up to the user. Note: Schedule the
6435 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
6436 * chunk needs the updated rwnd.
6438 sctp_add_cmd_sf(commands
, deliver
, SCTP_CHUNK(chunk
));
6440 return SCTP_IERROR_NO_ERROR
;