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 #define CREATE_TRACE_POINTS
63 #include <trace/events/sctp.h>
65 static struct sctp_packet
*sctp_abort_pkt_new(
67 const struct sctp_endpoint
*ep
,
68 const struct sctp_association
*asoc
,
69 struct sctp_chunk
*chunk
,
70 const void *payload
, size_t paylen
);
71 static int sctp_eat_data(const struct sctp_association
*asoc
,
72 struct sctp_chunk
*chunk
,
73 struct sctp_cmd_seq
*commands
);
74 static struct sctp_packet
*sctp_ootb_pkt_new(
76 const struct sctp_association
*asoc
,
77 const struct sctp_chunk
*chunk
);
78 static void sctp_send_stale_cookie_err(struct net
*net
,
79 const struct sctp_endpoint
*ep
,
80 const struct sctp_association
*asoc
,
81 const struct sctp_chunk
*chunk
,
82 struct sctp_cmd_seq
*commands
,
83 struct sctp_chunk
*err_chunk
);
84 static enum sctp_disposition
sctp_sf_do_5_2_6_stale(
86 const struct sctp_endpoint
*ep
,
87 const struct sctp_association
*asoc
,
88 const union sctp_subtype type
,
90 struct sctp_cmd_seq
*commands
);
91 static enum sctp_disposition
sctp_sf_shut_8_4_5(
93 const struct sctp_endpoint
*ep
,
94 const struct sctp_association
*asoc
,
95 const union sctp_subtype type
,
97 struct sctp_cmd_seq
*commands
);
98 static enum sctp_disposition
sctp_sf_tabort_8_4_8(
100 const struct sctp_endpoint
*ep
,
101 const struct sctp_association
*asoc
,
102 const union sctp_subtype type
,
104 struct sctp_cmd_seq
*commands
);
105 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
);
107 static enum sctp_disposition
sctp_stop_t1_and_abort(
109 struct sctp_cmd_seq
*commands
,
110 __be16 error
, int sk_err
,
111 const struct sctp_association
*asoc
,
112 struct sctp_transport
*transport
);
114 static enum sctp_disposition
sctp_sf_abort_violation(
116 const struct sctp_endpoint
*ep
,
117 const struct sctp_association
*asoc
,
119 struct sctp_cmd_seq
*commands
,
121 const size_t paylen
);
123 static enum sctp_disposition
sctp_sf_violation_chunklen(
125 const struct sctp_endpoint
*ep
,
126 const struct sctp_association
*asoc
,
127 const union sctp_subtype type
,
129 struct sctp_cmd_seq
*commands
);
131 static enum sctp_disposition
sctp_sf_violation_paramlen(
133 const struct sctp_endpoint
*ep
,
134 const struct sctp_association
*asoc
,
135 const union sctp_subtype type
,
136 void *arg
, void *ext
,
137 struct sctp_cmd_seq
*commands
);
139 static enum sctp_disposition
sctp_sf_violation_ctsn(
141 const struct sctp_endpoint
*ep
,
142 const struct sctp_association
*asoc
,
143 const union sctp_subtype type
,
145 struct sctp_cmd_seq
*commands
);
147 static enum sctp_disposition
sctp_sf_violation_chunk(
149 const struct sctp_endpoint
*ep
,
150 const struct sctp_association
*asoc
,
151 const union sctp_subtype type
,
153 struct sctp_cmd_seq
*commands
);
155 static enum sctp_ierror
sctp_sf_authenticate(
157 const struct sctp_endpoint
*ep
,
158 const struct sctp_association
*asoc
,
159 const union sctp_subtype type
,
160 struct sctp_chunk
*chunk
);
162 static enum sctp_disposition
__sctp_sf_do_9_1_abort(
164 const struct sctp_endpoint
*ep
,
165 const struct sctp_association
*asoc
,
166 const union sctp_subtype type
,
168 struct sctp_cmd_seq
*commands
);
170 /* Small helper function that checks if the chunk length
171 * is of the appropriate length. The 'required_length' argument
172 * is set to be the size of a specific chunk we are testing.
173 * Return Values: true = Valid length
174 * false = Invalid length
177 static inline bool sctp_chunk_length_valid(struct sctp_chunk
*chunk
,
178 __u16 required_length
)
180 __u16 chunk_length
= ntohs(chunk
->chunk_hdr
->length
);
182 /* Previously already marked? */
183 if (unlikely(chunk
->pdiscard
))
185 if (unlikely(chunk_length
< required_length
))
191 /**********************************************************
192 * These are the state functions for handling chunk events.
193 **********************************************************/
196 * Process the final SHUTDOWN COMPLETE.
198 * Section: 4 (C) (diagram), 9.2
199 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
200 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
201 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
202 * should stop the T2-shutdown timer and remove all knowledge of the
203 * association (and thus the association enters the CLOSED state).
205 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
206 * C) Rules for packet carrying SHUTDOWN COMPLETE:
208 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
209 * if the Verification Tag field of the packet matches its own tag and
210 * the T bit is not set
212 * it is set to its peer's tag and the T bit is set in the Chunk
214 * Otherwise, the receiver MUST silently discard the packet
215 * and take no further action. An endpoint MUST ignore the
216 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
219 * (endpoint, asoc, chunk)
222 * (asoc, reply_msg, msg_up, timers, counters)
224 * The return value is the disposition of the chunk.
226 enum sctp_disposition
sctp_sf_do_4_C(struct net
*net
,
227 const struct sctp_endpoint
*ep
,
228 const struct sctp_association
*asoc
,
229 const union sctp_subtype type
,
230 void *arg
, struct sctp_cmd_seq
*commands
)
232 struct sctp_chunk
*chunk
= arg
;
233 struct sctp_ulpevent
*ev
;
235 if (!sctp_vtag_verify_either(chunk
, asoc
))
236 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
238 /* RFC 2960 6.10 Bundling
240 * An endpoint MUST NOT bundle INIT, INIT ACK or
241 * SHUTDOWN COMPLETE with any other chunks.
243 if (!chunk
->singleton
)
244 return sctp_sf_violation_chunk(net
, ep
, asoc
, type
, arg
, commands
);
246 /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */
247 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
248 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
251 /* RFC 2960 10.2 SCTP-to-ULP
253 * H) SHUTDOWN COMPLETE notification
255 * When SCTP completes the shutdown procedures (section 9.2) this
256 * notification is passed to the upper layer.
258 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
259 0, 0, 0, NULL
, GFP_ATOMIC
);
261 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
264 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
265 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
266 * not the chunk should be discarded. If the endpoint is in
267 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
268 * T2-shutdown timer and remove all knowledge of the
269 * association (and thus the association enters the CLOSED
272 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
273 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
275 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
276 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
278 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
279 SCTP_STATE(SCTP_STATE_CLOSED
));
281 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
282 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
284 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
286 return SCTP_DISPOSITION_DELETE_TCB
;
290 * Respond to a normal INIT chunk.
291 * We are the side that is being asked for an association.
293 * Section: 5.1 Normal Establishment of an Association, B
294 * B) "Z" shall respond immediately with an INIT ACK chunk. The
295 * destination IP address of the INIT ACK MUST be set to the source
296 * IP address of the INIT to which this INIT ACK is responding. In
297 * the response, besides filling in other parameters, "Z" must set the
298 * Verification Tag field to Tag_A, and also provide its own
299 * Verification Tag (Tag_Z) in the Initiate Tag field.
301 * Verification Tag: Must be 0.
304 * (endpoint, asoc, chunk)
307 * (asoc, reply_msg, msg_up, timers, counters)
309 * The return value is the disposition of the chunk.
311 enum sctp_disposition
sctp_sf_do_5_1B_init(struct net
*net
,
312 const struct sctp_endpoint
*ep
,
313 const struct sctp_association
*asoc
,
314 const union sctp_subtype type
,
316 struct sctp_cmd_seq
*commands
)
318 struct sctp_chunk
*chunk
= arg
, *repl
, *err_chunk
;
319 struct sctp_unrecognized_param
*unk_param
;
320 struct sctp_association
*new_asoc
;
321 struct sctp_packet
*packet
;
325 * An endpoint MUST NOT bundle INIT, INIT ACK or
326 * SHUTDOWN COMPLETE with any other chunks.
329 * Furthermore, we require that the receiver of an INIT chunk MUST
330 * enforce these rules by silently discarding an arriving packet
331 * with an INIT chunk that is bundled with other chunks.
333 if (!chunk
->singleton
)
334 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
336 /* If the packet is an OOTB packet which is temporarily on the
337 * control endpoint, respond with an ABORT.
339 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
) {
340 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
341 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
344 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
347 if (chunk
->sctp_hdr
->vtag
!= 0)
348 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
350 /* Make sure that the INIT chunk has a valid length.
351 * Normally, this would cause an ABORT with a Protocol Violation
352 * error, but since we don't have an association, we'll
353 * just discard the packet.
355 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_init_chunk
)))
356 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
358 /* If the INIT is coming toward a closing socket, we'll send back
359 * and ABORT. Essentially, this catches the race of INIT being
360 * backloged to the socket at the same time as the user isses close().
361 * Since the socket and all its associations are going away, we
362 * can treat this OOTB
364 if (sctp_sstate(ep
->base
.sk
, CLOSING
))
365 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
367 /* Verify the INIT chunk before processing it. */
369 if (!sctp_verify_init(net
, ep
, asoc
, chunk
->chunk_hdr
->type
,
370 (struct sctp_init_chunk
*)chunk
->chunk_hdr
, chunk
,
372 /* This chunk contains fatal error. It is to be discarded.
373 * Send an ABORT, with causes if there is any.
376 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
377 (__u8
*)(err_chunk
->chunk_hdr
) +
378 sizeof(struct sctp_chunkhdr
),
379 ntohs(err_chunk
->chunk_hdr
->length
) -
380 sizeof(struct sctp_chunkhdr
));
382 sctp_chunk_free(err_chunk
);
385 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
386 SCTP_PACKET(packet
));
387 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
388 return SCTP_DISPOSITION_CONSUME
;
390 return SCTP_DISPOSITION_NOMEM
;
393 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
,
398 /* Grab the INIT header. */
399 chunk
->subh
.init_hdr
= (struct sctp_inithdr
*)chunk
->skb
->data
;
401 /* Tag the variable length parameters. */
402 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(struct sctp_inithdr
));
404 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
408 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
,
409 sctp_scope(sctp_source(chunk
)),
413 /* The call, sctp_process_init(), can fail on memory allocation. */
414 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
),
415 (struct sctp_init_chunk
*)chunk
->chunk_hdr
,
419 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
421 /* If there are errors need to be reported for unknown parameters,
422 * make sure to reserve enough room in the INIT ACK for them.
426 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
427 sizeof(struct sctp_chunkhdr
);
429 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
433 /* If there are errors need to be reported for unknown parameters,
434 * include them in the outgoing INIT ACK as "Unrecognized parameter"
438 /* Get the "Unrecognized parameter" parameter(s) out of the
439 * ERROR chunk generated by sctp_verify_init(). Since the
440 * error cause code for "unknown parameter" and the
441 * "Unrecognized parameter" type is the same, we can
442 * construct the parameters in INIT ACK by copying the
445 unk_param
= (struct sctp_unrecognized_param
*)
446 ((__u8
*)(err_chunk
->chunk_hdr
) +
447 sizeof(struct sctp_chunkhdr
));
448 /* Replace the cause code with the "Unrecognized parameter"
451 sctp_addto_chunk(repl
, len
, unk_param
);
452 sctp_chunk_free(err_chunk
);
455 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
457 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
460 * Note: After sending out INIT ACK with the State Cookie parameter,
461 * "Z" MUST NOT allocate any resources, nor keep any states for the
462 * new association. Otherwise, "Z" will be vulnerable to resource
465 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
467 return SCTP_DISPOSITION_DELETE_TCB
;
470 sctp_association_free(new_asoc
);
473 sctp_chunk_free(err_chunk
);
474 return SCTP_DISPOSITION_NOMEM
;
478 * Respond to a normal INIT ACK chunk.
479 * We are the side that is initiating the association.
481 * Section: 5.1 Normal Establishment of an Association, C
482 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
483 * timer and leave COOKIE-WAIT state. "A" shall then send the State
484 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
485 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
487 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
488 * DATA chunks, but it MUST be the first chunk in the packet and
489 * until the COOKIE ACK is returned the sender MUST NOT send any
490 * other packets to the peer.
492 * Verification Tag: 3.3.3
493 * If the value of the Initiate Tag in a received INIT ACK chunk is
494 * found to be 0, the receiver MUST treat it as an error and close the
495 * association by transmitting an ABORT.
498 * (endpoint, asoc, chunk)
501 * (asoc, reply_msg, msg_up, timers, counters)
503 * The return value is the disposition of the chunk.
505 enum sctp_disposition
sctp_sf_do_5_1C_ack(struct net
*net
,
506 const struct sctp_endpoint
*ep
,
507 const struct sctp_association
*asoc
,
508 const union sctp_subtype type
,
510 struct sctp_cmd_seq
*commands
)
512 struct sctp_init_chunk
*initchunk
;
513 struct sctp_chunk
*chunk
= arg
;
514 struct sctp_chunk
*err_chunk
;
515 struct sctp_packet
*packet
;
517 if (!sctp_vtag_verify(chunk
, asoc
))
518 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
521 * An endpoint MUST NOT bundle INIT, INIT ACK or
522 * SHUTDOWN COMPLETE with any other chunks.
524 if (!chunk
->singleton
)
525 return sctp_sf_violation_chunk(net
, ep
, asoc
, type
, arg
, commands
);
527 /* Make sure that the INIT-ACK chunk has a valid length */
528 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_initack_chunk
)))
529 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
531 /* Grab the INIT header. */
532 chunk
->subh
.init_hdr
= (struct sctp_inithdr
*)chunk
->skb
->data
;
534 /* Verify the INIT chunk before processing it. */
536 if (!sctp_verify_init(net
, ep
, asoc
, chunk
->chunk_hdr
->type
,
537 (struct sctp_init_chunk
*)chunk
->chunk_hdr
, chunk
,
540 enum sctp_error error
= SCTP_ERROR_NO_RESOURCE
;
542 /* This chunk contains fatal error. It is to be discarded.
543 * Send an ABORT, with causes. If there are no causes,
544 * then there wasn't enough memory. Just terminate
548 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
549 (__u8
*)(err_chunk
->chunk_hdr
) +
550 sizeof(struct sctp_chunkhdr
),
551 ntohs(err_chunk
->chunk_hdr
->length
) -
552 sizeof(struct sctp_chunkhdr
));
554 sctp_chunk_free(err_chunk
);
557 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
558 SCTP_PACKET(packet
));
559 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
560 error
= SCTP_ERROR_INV_PARAM
;
564 /* SCTP-AUTH, Section 6.3:
565 * It should be noted that if the receiver wants to tear
566 * down an association in an authenticated way only, the
567 * handling of malformed packets should not result in
568 * tearing down the association.
570 * This means that if we only want to abort associations
571 * in an authenticated way (i.e AUTH+ABORT), then we
572 * can't destroy this association just because the packet
575 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
576 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
578 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
579 return sctp_stop_t1_and_abort(net
, commands
, error
, ECONNREFUSED
,
580 asoc
, chunk
->transport
);
583 /* Tag the variable length parameters. Note that we never
584 * convert the parameters in an INIT chunk.
586 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(struct sctp_inithdr
));
588 initchunk
= (struct sctp_init_chunk
*)chunk
->chunk_hdr
;
590 sctp_add_cmd_sf(commands
, SCTP_CMD_PEER_INIT
,
591 SCTP_PEER_INIT(initchunk
));
593 /* Reset init error count upon receipt of INIT-ACK. */
594 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
596 /* 5.1 C) "A" shall stop the T1-init timer and leave
597 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
598 * timer, and enter the COOKIE-ECHOED state.
600 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
601 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
602 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
603 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
604 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
605 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED
));
607 /* SCTP-AUTH: genereate the assocition shared keys so that
608 * we can potentially signe the COOKIE-ECHO.
610 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_SHKEY
, SCTP_NULL());
612 /* 5.1 C) "A" shall then send the State Cookie received in the
613 * INIT ACK chunk in a COOKIE ECHO chunk, ...
615 /* If there is any errors to report, send the ERROR chunk generated
616 * for unknown parameters as well.
618 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_COOKIE_ECHO
,
619 SCTP_CHUNK(err_chunk
));
621 return SCTP_DISPOSITION_CONSUME
;
625 * Respond to a normal COOKIE ECHO chunk.
626 * We are the side that is being asked for an association.
628 * Section: 5.1 Normal Establishment of an Association, D
629 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
630 * with a COOKIE ACK chunk after building a TCB and moving to
631 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
632 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
633 * chunk MUST be the first chunk in the packet.
635 * IMPLEMENTATION NOTE: An implementation may choose to send the
636 * Communication Up notification to the SCTP user upon reception
637 * of a valid COOKIE ECHO chunk.
639 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
640 * D) Rules for packet carrying a COOKIE ECHO
642 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
643 * Initial Tag received in the INIT ACK.
645 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
648 * (endpoint, asoc, chunk)
651 * (asoc, reply_msg, msg_up, timers, counters)
653 * The return value is the disposition of the chunk.
655 enum sctp_disposition
sctp_sf_do_5_1D_ce(struct net
*net
,
656 const struct sctp_endpoint
*ep
,
657 const struct sctp_association
*asoc
,
658 const union sctp_subtype type
,
660 struct sctp_cmd_seq
*commands
)
662 struct sctp_ulpevent
*ev
, *ai_ev
= NULL
;
663 struct sctp_association
*new_asoc
;
664 struct sctp_init_chunk
*peer_init
;
665 struct sctp_chunk
*chunk
= arg
;
666 struct sctp_chunk
*err_chk_p
;
667 struct sctp_chunk
*repl
;
671 /* If the packet is an OOTB packet which is temporarily on the
672 * control endpoint, respond with an ABORT.
674 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
) {
675 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
676 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
679 /* Make sure that the COOKIE_ECHO chunk has a valid length.
680 * In this case, we check that we have enough for at least a
681 * chunk header. More detailed verification is done
682 * in sctp_unpack_cookie().
684 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
685 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
687 /* If the endpoint is not listening or if the number of associations
688 * on the TCP-style socket exceed the max backlog, respond with an
692 if (!sctp_sstate(sk
, LISTENING
) ||
693 (sctp_style(sk
, TCP
) && sk_acceptq_is_full(sk
)))
694 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
696 /* "Decode" the chunk. We have no optional parameters so we
699 chunk
->subh
.cookie_hdr
=
700 (struct sctp_signed_cookie
*)chunk
->skb
->data
;
701 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
702 sizeof(struct sctp_chunkhdr
)))
705 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
706 * "Z" will reply with a COOKIE ACK chunk after building a TCB
707 * and moving to the ESTABLISHED state.
709 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
713 * If the re-build failed, what is the proper error path
716 * [We should abort the association. --piggy]
719 /* FIXME: Several errors are possible. A bad cookie should
720 * be silently discarded, but think about logging it too.
723 case -SCTP_IERROR_NOMEM
:
726 case -SCTP_IERROR_STALE_COOKIE
:
727 sctp_send_stale_cookie_err(net
, ep
, asoc
, chunk
, commands
,
729 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
731 case -SCTP_IERROR_BAD_SIG
:
733 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
738 /* Delay state machine commands until later.
740 * Re-build the bind address for the association is done in
741 * the sctp_unpack_cookie() already.
743 /* This is a brand-new association, so these are not yet side
744 * effects--it is safe to run them here.
746 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
748 if (!sctp_process_init(new_asoc
, chunk
,
749 &chunk
->subh
.cookie_hdr
->c
.peer_addr
,
750 peer_init
, GFP_ATOMIC
))
753 /* SCTP-AUTH: Now that we've populate required fields in
754 * sctp_process_init, set up the assocaition shared keys as
755 * necessary so that we can potentially authenticate the ACK
757 error
= sctp_auth_asoc_init_active_key(new_asoc
, GFP_ATOMIC
);
761 /* SCTP-AUTH: auth_chunk pointer is only set when the cookie-echo
762 * is supposed to be authenticated and we have to do delayed
763 * authentication. We've just recreated the association using
764 * the information in the cookie and now it's much easier to
765 * do the authentication.
767 if (chunk
->auth_chunk
) {
768 struct sctp_chunk auth
;
769 enum sctp_ierror ret
;
771 /* Make sure that we and the peer are AUTH capable */
772 if (!net
->sctp
.auth_enable
|| !new_asoc
->peer
.auth_capable
) {
773 sctp_association_free(new_asoc
);
774 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
777 /* set-up our fake chunk so that we can process it */
778 auth
.skb
= chunk
->auth_chunk
;
779 auth
.asoc
= chunk
->asoc
;
780 auth
.sctp_hdr
= chunk
->sctp_hdr
;
781 auth
.chunk_hdr
= (struct sctp_chunkhdr
*)
782 skb_push(chunk
->auth_chunk
,
783 sizeof(struct sctp_chunkhdr
));
784 skb_pull(chunk
->auth_chunk
, sizeof(struct sctp_chunkhdr
));
785 auth
.transport
= chunk
->transport
;
787 ret
= sctp_sf_authenticate(net
, ep
, new_asoc
, type
, &auth
);
788 if (ret
!= SCTP_IERROR_NO_ERROR
) {
789 sctp_association_free(new_asoc
);
790 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
794 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
798 /* RFC 2960 5.1 Normal Establishment of an Association
800 * D) IMPLEMENTATION NOTE: An implementation may choose to
801 * send the Communication Up notification to the SCTP user
802 * upon reception of a valid COOKIE ECHO chunk.
804 ev
= sctp_ulpevent_make_assoc_change(new_asoc
, 0, SCTP_COMM_UP
, 0,
805 new_asoc
->c
.sinit_num_ostreams
,
806 new_asoc
->c
.sinit_max_instreams
,
811 /* Sockets API Draft Section 5.3.1.6
812 * When a peer sends a Adaptation Layer Indication parameter , SCTP
813 * delivers this notification to inform the application that of the
814 * peers requested adaptation layer.
816 if (new_asoc
->peer
.adaptation_ind
) {
817 ai_ev
= sctp_ulpevent_make_adaptation_indication(new_asoc
,
823 /* Add all the state machine commands now since we've created
824 * everything. This way we don't introduce memory corruptions
825 * during side-effect processing and correclty count established
828 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
829 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
830 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
831 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
832 SCTP_INC_STATS(net
, SCTP_MIB_PASSIVEESTABS
);
833 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
835 if (new_asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
836 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
837 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
839 /* This will send the COOKIE ACK */
840 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
842 /* Queue the ASSOC_CHANGE event */
843 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
845 /* Send up the Adaptation Layer Indication event */
847 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
848 SCTP_ULPEVENT(ai_ev
));
850 return SCTP_DISPOSITION_CONSUME
;
853 sctp_ulpevent_free(ev
);
855 sctp_chunk_free(repl
);
857 sctp_association_free(new_asoc
);
859 return SCTP_DISPOSITION_NOMEM
;
863 * Respond to a normal COOKIE ACK chunk.
864 * We are the side that is asking for an association.
866 * RFC 2960 5.1 Normal Establishment of an Association
868 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
869 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
870 * timer. It may also notify its ULP about the successful
871 * establishment of the association with a Communication Up
872 * notification (see Section 10).
876 * (endpoint, asoc, chunk)
879 * (asoc, reply_msg, msg_up, timers, counters)
881 * The return value is the disposition of the chunk.
883 enum sctp_disposition
sctp_sf_do_5_1E_ca(struct net
*net
,
884 const struct sctp_endpoint
*ep
,
885 const struct sctp_association
*asoc
,
886 const union sctp_subtype type
,
888 struct sctp_cmd_seq
*commands
)
890 struct sctp_chunk
*chunk
= arg
;
891 struct sctp_ulpevent
*ev
;
893 if (!sctp_vtag_verify(chunk
, asoc
))
894 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
896 /* Verify that the chunk length for the COOKIE-ACK is OK.
897 * If we don't do this, any bundled chunks may be junked.
899 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
900 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
903 /* Reset init error count upon receipt of COOKIE-ACK,
904 * to avoid problems with the managemement of this
905 * counter in stale cookie situations when a transition back
906 * from the COOKIE-ECHOED state to the COOKIE-WAIT
907 * state is performed.
909 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
911 /* RFC 2960 5.1 Normal Establishment of an Association
913 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
914 * from the COOKIE-ECHOED state to the ESTABLISHED state,
915 * stopping the T1-cookie timer.
917 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
918 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
919 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
920 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
921 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
922 SCTP_INC_STATS(net
, SCTP_MIB_ACTIVEESTABS
);
923 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
924 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
925 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
926 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
928 /* It may also notify its ULP about the successful
929 * establishment of the association with a Communication Up
930 * notification (see Section 10).
932 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_COMM_UP
,
933 0, asoc
->c
.sinit_num_ostreams
,
934 asoc
->c
.sinit_max_instreams
,
940 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
942 /* Sockets API Draft Section 5.3.1.6
943 * When a peer sends a Adaptation Layer Indication parameter , SCTP
944 * delivers this notification to inform the application that of the
945 * peers requested adaptation layer.
947 if (asoc
->peer
.adaptation_ind
) {
948 ev
= sctp_ulpevent_make_adaptation_indication(asoc
, GFP_ATOMIC
);
952 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
956 return SCTP_DISPOSITION_CONSUME
;
958 return SCTP_DISPOSITION_NOMEM
;
961 /* Generate and sendout a heartbeat packet. */
962 static enum sctp_disposition
sctp_sf_heartbeat(
963 const struct sctp_endpoint
*ep
,
964 const struct sctp_association
*asoc
,
965 const union sctp_subtype type
,
967 struct sctp_cmd_seq
*commands
)
969 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
970 struct sctp_chunk
*reply
;
972 /* Send a heartbeat to our peer. */
973 reply
= sctp_make_heartbeat(asoc
, transport
);
975 return SCTP_DISPOSITION_NOMEM
;
977 /* Set rto_pending indicating that an RTT measurement
978 * is started with this heartbeat chunk.
980 sctp_add_cmd_sf(commands
, SCTP_CMD_RTO_PENDING
,
981 SCTP_TRANSPORT(transport
));
983 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
984 return SCTP_DISPOSITION_CONSUME
;
987 /* Generate a HEARTBEAT packet on the given transport. */
988 enum sctp_disposition
sctp_sf_sendbeat_8_3(struct net
*net
,
989 const struct sctp_endpoint
*ep
,
990 const struct sctp_association
*asoc
,
991 const union sctp_subtype type
,
993 struct sctp_cmd_seq
*commands
)
995 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
997 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
998 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
999 SCTP_ERROR(ETIMEDOUT
));
1000 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
1001 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
1002 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
1003 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
1004 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
1005 return SCTP_DISPOSITION_DELETE_TCB
;
1009 * The Sender-specific Heartbeat Info field should normally include
1010 * information about the sender's current time when this HEARTBEAT
1011 * chunk is sent and the destination transport address to which this
1012 * HEARTBEAT is sent (see Section 8.3).
1015 if (transport
->param_flags
& SPP_HB_ENABLE
) {
1016 if (SCTP_DISPOSITION_NOMEM
==
1017 sctp_sf_heartbeat(ep
, asoc
, type
, arg
,
1019 return SCTP_DISPOSITION_NOMEM
;
1021 /* Set transport error counter and association error counter
1022 * when sending heartbeat.
1024 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
1025 SCTP_TRANSPORT(transport
));
1027 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_IDLE
,
1028 SCTP_TRANSPORT(transport
));
1029 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMER_UPDATE
,
1030 SCTP_TRANSPORT(transport
));
1032 return SCTP_DISPOSITION_CONSUME
;
1035 /* resend asoc strreset_chunk. */
1036 enum sctp_disposition
sctp_sf_send_reconf(struct net
*net
,
1037 const struct sctp_endpoint
*ep
,
1038 const struct sctp_association
*asoc
,
1039 const union sctp_subtype type
,
1041 struct sctp_cmd_seq
*commands
)
1043 struct sctp_transport
*transport
= arg
;
1045 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
1046 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
1047 SCTP_ERROR(ETIMEDOUT
));
1048 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
1049 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
1050 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
1051 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
1052 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
1053 return SCTP_DISPOSITION_DELETE_TCB
;
1056 sctp_chunk_hold(asoc
->strreset_chunk
);
1057 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1058 SCTP_CHUNK(asoc
->strreset_chunk
));
1059 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
1061 return SCTP_DISPOSITION_CONSUME
;
1065 * Process an heartbeat request.
1067 * Section: 8.3 Path Heartbeat
1068 * The receiver of the HEARTBEAT should immediately respond with a
1069 * HEARTBEAT ACK that contains the Heartbeat Information field copied
1070 * from the received HEARTBEAT chunk.
1072 * Verification Tag: 8.5 Verification Tag [Normal verification]
1073 * When receiving an SCTP packet, the endpoint MUST ensure that the
1074 * value in the Verification Tag field of the received SCTP packet
1075 * matches its own Tag. If the received Verification Tag value does not
1076 * match the receiver's own tag value, the receiver shall silently
1077 * discard the packet and shall not process it any further except for
1078 * those cases listed in Section 8.5.1 below.
1081 * (endpoint, asoc, chunk)
1084 * (asoc, reply_msg, msg_up, timers, counters)
1086 * The return value is the disposition of the chunk.
1088 enum sctp_disposition
sctp_sf_beat_8_3(struct net
*net
,
1089 const struct sctp_endpoint
*ep
,
1090 const struct sctp_association
*asoc
,
1091 const union sctp_subtype type
,
1092 void *arg
, struct sctp_cmd_seq
*commands
)
1094 struct sctp_paramhdr
*param_hdr
;
1095 struct sctp_chunk
*chunk
= arg
;
1096 struct sctp_chunk
*reply
;
1099 if (!sctp_vtag_verify(chunk
, asoc
))
1100 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1102 /* Make sure that the HEARTBEAT chunk has a valid length. */
1103 if (!sctp_chunk_length_valid(chunk
,
1104 sizeof(struct sctp_heartbeat_chunk
)))
1105 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1108 /* 8.3 The receiver of the HEARTBEAT should immediately
1109 * respond with a HEARTBEAT ACK that contains the Heartbeat
1110 * Information field copied from the received HEARTBEAT chunk.
1112 chunk
->subh
.hb_hdr
= (struct sctp_heartbeathdr
*)chunk
->skb
->data
;
1113 param_hdr
= (struct sctp_paramhdr
*)chunk
->subh
.hb_hdr
;
1114 paylen
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(struct sctp_chunkhdr
);
1116 if (ntohs(param_hdr
->length
) > paylen
)
1117 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
1118 param_hdr
, commands
);
1120 if (!pskb_pull(chunk
->skb
, paylen
))
1123 reply
= sctp_make_heartbeat_ack(asoc
, chunk
, param_hdr
, paylen
);
1127 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
1128 return SCTP_DISPOSITION_CONSUME
;
1131 return SCTP_DISPOSITION_NOMEM
;
1135 * Process the returning HEARTBEAT ACK.
1137 * Section: 8.3 Path Heartbeat
1138 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
1139 * should clear the error counter of the destination transport
1140 * address to which the HEARTBEAT was sent, and mark the destination
1141 * transport address as active if it is not so marked. The endpoint may
1142 * optionally report to the upper layer when an inactive destination
1143 * address is marked as active due to the reception of the latest
1144 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
1145 * clear the association overall error count as well (as defined
1148 * The receiver of the HEARTBEAT ACK should also perform an RTT
1149 * measurement for that destination transport address using the time
1150 * value carried in the HEARTBEAT ACK chunk.
1152 * Verification Tag: 8.5 Verification Tag [Normal verification]
1155 * (endpoint, asoc, chunk)
1158 * (asoc, reply_msg, msg_up, timers, counters)
1160 * The return value is the disposition of the chunk.
1162 enum sctp_disposition
sctp_sf_backbeat_8_3(struct net
*net
,
1163 const struct sctp_endpoint
*ep
,
1164 const struct sctp_association
*asoc
,
1165 const union sctp_subtype type
,
1167 struct sctp_cmd_seq
*commands
)
1169 struct sctp_sender_hb_info
*hbinfo
;
1170 struct sctp_chunk
*chunk
= arg
;
1171 struct sctp_transport
*link
;
1172 unsigned long max_interval
;
1173 union sctp_addr from_addr
;
1175 if (!sctp_vtag_verify(chunk
, asoc
))
1176 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1178 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1179 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
) +
1181 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1184 hbinfo
= (struct sctp_sender_hb_info
*)chunk
->skb
->data
;
1185 /* Make sure that the length of the parameter is what we expect */
1186 if (ntohs(hbinfo
->param_hdr
.length
) != sizeof(*hbinfo
))
1187 return SCTP_DISPOSITION_DISCARD
;
1189 from_addr
= hbinfo
->daddr
;
1190 link
= sctp_assoc_lookup_paddr(asoc
, &from_addr
);
1192 /* This should never happen, but lets log it if so. */
1193 if (unlikely(!link
)) {
1194 if (from_addr
.sa
.sa_family
== AF_INET6
) {
1195 net_warn_ratelimited("%s association %p could not find address %pI6\n",
1198 &from_addr
.v6
.sin6_addr
);
1200 net_warn_ratelimited("%s association %p could not find address %pI4\n",
1203 &from_addr
.v4
.sin_addr
.s_addr
);
1205 return SCTP_DISPOSITION_DISCARD
;
1208 /* Validate the 64-bit random nonce. */
1209 if (hbinfo
->hb_nonce
!= link
->hb_nonce
)
1210 return SCTP_DISPOSITION_DISCARD
;
1212 max_interval
= link
->hbinterval
+ link
->rto
;
1214 /* Check if the timestamp looks valid. */
1215 if (time_after(hbinfo
->sent_at
, jiffies
) ||
1216 time_after(jiffies
, hbinfo
->sent_at
+ max_interval
)) {
1217 pr_debug("%s: HEARTBEAT ACK with invalid timestamp received "
1218 "for transport:%p\n", __func__
, link
);
1220 return SCTP_DISPOSITION_DISCARD
;
1223 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1224 * the HEARTBEAT should clear the error counter of the
1225 * destination transport address to which the HEARTBEAT was
1226 * sent and mark the destination transport address as active if
1227 * it is not so marked.
1229 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_ON
, SCTP_TRANSPORT(link
));
1231 return SCTP_DISPOSITION_CONSUME
;
1234 /* Helper function to send out an abort for the restart
1237 static int sctp_sf_send_restart_abort(struct net
*net
, union sctp_addr
*ssa
,
1238 struct sctp_chunk
*init
,
1239 struct sctp_cmd_seq
*commands
)
1241 struct sctp_af
*af
= sctp_get_af_specific(ssa
->v4
.sin_family
);
1242 union sctp_addr_param
*addrparm
;
1243 struct sctp_errhdr
*errhdr
;
1244 char buffer
[sizeof(*errhdr
) + sizeof(*addrparm
)];
1245 struct sctp_endpoint
*ep
;
1246 struct sctp_packet
*pkt
;
1249 /* Build the error on the stack. We are way to malloc crazy
1250 * throughout the code today.
1252 errhdr
= (struct sctp_errhdr
*)buffer
;
1253 addrparm
= (union sctp_addr_param
*)errhdr
->variable
;
1255 /* Copy into a parm format. */
1256 len
= af
->to_addr_param(ssa
, addrparm
);
1257 len
+= sizeof(*errhdr
);
1259 errhdr
->cause
= SCTP_ERROR_RESTART
;
1260 errhdr
->length
= htons(len
);
1262 /* Assign to the control socket. */
1263 ep
= sctp_sk(net
->sctp
.ctl_sock
)->ep
;
1265 /* Association is NULL since this may be a restart attack and we
1266 * want to send back the attacker's vtag.
1268 pkt
= sctp_abort_pkt_new(net
, ep
, NULL
, init
, errhdr
, len
);
1272 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
, SCTP_PACKET(pkt
));
1274 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
1276 /* Discard the rest of the inbound packet. */
1277 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
1280 /* Even if there is no memory, treat as a failure so
1281 * the packet will get dropped.
1286 static bool list_has_sctp_addr(const struct list_head
*list
,
1287 union sctp_addr
*ipaddr
)
1289 struct sctp_transport
*addr
;
1291 list_for_each_entry(addr
, list
, transports
) {
1292 if (sctp_cmp_addr_exact(ipaddr
, &addr
->ipaddr
))
1298 /* A restart is occurring, check to make sure no new addresses
1299 * are being added as we may be under a takeover attack.
1301 static int sctp_sf_check_restart_addrs(const struct sctp_association
*new_asoc
,
1302 const struct sctp_association
*asoc
,
1303 struct sctp_chunk
*init
,
1304 struct sctp_cmd_seq
*commands
)
1306 struct net
*net
= sock_net(new_asoc
->base
.sk
);
1307 struct sctp_transport
*new_addr
;
1310 /* Implementor's Guide - Section 5.2.2
1312 * Before responding the endpoint MUST check to see if the
1313 * unexpected INIT adds new addresses to the association. If new
1314 * addresses are added to the association, the endpoint MUST respond
1318 /* Search through all current addresses and make sure
1319 * we aren't adding any new ones.
1321 list_for_each_entry(new_addr
, &new_asoc
->peer
.transport_addr_list
,
1323 if (!list_has_sctp_addr(&asoc
->peer
.transport_addr_list
,
1324 &new_addr
->ipaddr
)) {
1325 sctp_sf_send_restart_abort(net
, &new_addr
->ipaddr
, init
,
1332 /* Return success if all addresses were found. */
1336 /* Populate the verification/tie tags based on overlapping INIT
1339 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1341 static void sctp_tietags_populate(struct sctp_association
*new_asoc
,
1342 const struct sctp_association
*asoc
)
1344 switch (asoc
->state
) {
1346 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1348 case SCTP_STATE_COOKIE_WAIT
:
1349 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1350 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1351 new_asoc
->c
.peer_ttag
= 0;
1354 case SCTP_STATE_COOKIE_ECHOED
:
1355 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1356 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1357 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1360 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1361 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1364 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1365 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1369 /* Other parameters for the endpoint SHOULD be copied from the
1370 * existing parameters of the association (e.g. number of
1371 * outbound streams) into the INIT ACK and cookie.
1373 new_asoc
->rwnd
= asoc
->rwnd
;
1374 new_asoc
->c
.sinit_num_ostreams
= asoc
->c
.sinit_num_ostreams
;
1375 new_asoc
->c
.sinit_max_instreams
= asoc
->c
.sinit_max_instreams
;
1376 new_asoc
->c
.initial_tsn
= asoc
->c
.initial_tsn
;
1380 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1383 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1385 * Returns value representing action to be taken. These action values
1386 * correspond to Action/Description values in RFC 2960, Table 2.
1388 static char sctp_tietags_compare(struct sctp_association
*new_asoc
,
1389 const struct sctp_association
*asoc
)
1391 /* In this case, the peer may have restarted. */
1392 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1393 (asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) &&
1394 (asoc
->c
.my_vtag
== new_asoc
->c
.my_ttag
) &&
1395 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_ttag
))
1398 /* Collision case B. */
1399 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1400 ((asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) ||
1401 (0 == asoc
->c
.peer_vtag
))) {
1405 /* Collision case D. */
1406 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1407 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
))
1410 /* Collision case C. */
1411 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1412 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
) &&
1413 (0 == new_asoc
->c
.my_ttag
) &&
1414 (0 == new_asoc
->c
.peer_ttag
))
1417 /* No match to any of the special cases; discard this packet. */
1421 /* Common helper routine for both duplicate and simulataneous INIT
1424 static enum sctp_disposition
sctp_sf_do_unexpected_init(
1426 const struct sctp_endpoint
*ep
,
1427 const struct sctp_association
*asoc
,
1428 const union sctp_subtype type
,
1430 struct sctp_cmd_seq
*commands
)
1432 struct sctp_chunk
*chunk
= arg
, *repl
, *err_chunk
;
1433 struct sctp_unrecognized_param
*unk_param
;
1434 struct sctp_association
*new_asoc
;
1435 enum sctp_disposition retval
;
1436 struct sctp_packet
*packet
;
1440 * An endpoint MUST NOT bundle INIT, INIT ACK or
1441 * SHUTDOWN COMPLETE with any other chunks.
1444 * Furthermore, we require that the receiver of an INIT chunk MUST
1445 * enforce these rules by silently discarding an arriving packet
1446 * with an INIT chunk that is bundled with other chunks.
1448 if (!chunk
->singleton
)
1449 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1451 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1454 if (chunk
->sctp_hdr
->vtag
!= 0)
1455 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
1457 /* Make sure that the INIT chunk has a valid length.
1458 * In this case, we generate a protocol violation since we have
1459 * an association established.
1461 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_init_chunk
)))
1462 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1464 /* Grab the INIT header. */
1465 chunk
->subh
.init_hdr
= (struct sctp_inithdr
*)chunk
->skb
->data
;
1467 /* Tag the variable length parameters. */
1468 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(struct sctp_inithdr
));
1470 /* Verify the INIT chunk before processing it. */
1472 if (!sctp_verify_init(net
, ep
, asoc
, chunk
->chunk_hdr
->type
,
1473 (struct sctp_init_chunk
*)chunk
->chunk_hdr
, chunk
,
1475 /* This chunk contains fatal error. It is to be discarded.
1476 * Send an ABORT, with causes if there is any.
1479 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
1480 (__u8
*)(err_chunk
->chunk_hdr
) +
1481 sizeof(struct sctp_chunkhdr
),
1482 ntohs(err_chunk
->chunk_hdr
->length
) -
1483 sizeof(struct sctp_chunkhdr
));
1486 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
1487 SCTP_PACKET(packet
));
1488 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
1489 retval
= SCTP_DISPOSITION_CONSUME
;
1491 retval
= SCTP_DISPOSITION_NOMEM
;
1495 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
,
1501 * Other parameters for the endpoint SHOULD be copied from the
1502 * existing parameters of the association (e.g. number of
1503 * outbound streams) into the INIT ACK and cookie.
1504 * FIXME: We are copying parameters from the endpoint not the
1507 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
1511 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
,
1512 sctp_scope(sctp_source(chunk
)), GFP_ATOMIC
) < 0)
1515 /* In the outbound INIT ACK the endpoint MUST copy its current
1516 * Verification Tag and Peers Verification tag into a reserved
1517 * place (local tie-tag and per tie-tag) within the state cookie.
1519 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
),
1520 (struct sctp_init_chunk
*)chunk
->chunk_hdr
,
1524 /* Make sure no new addresses are being added during the
1525 * restart. Do not do this check for COOKIE-WAIT state,
1526 * since there are no peer addresses to check against.
1527 * Upon return an ABORT will have been sent if needed.
1529 if (!sctp_state(asoc
, COOKIE_WAIT
)) {
1530 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
,
1532 retval
= SCTP_DISPOSITION_CONSUME
;
1537 sctp_tietags_populate(new_asoc
, asoc
);
1539 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1541 /* If there are errors need to be reported for unknown parameters,
1542 * make sure to reserve enough room in the INIT ACK for them.
1546 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
1547 sizeof(struct sctp_chunkhdr
);
1550 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
1554 /* If there are errors need to be reported for unknown parameters,
1555 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1559 /* Get the "Unrecognized parameter" parameter(s) out of the
1560 * ERROR chunk generated by sctp_verify_init(). Since the
1561 * error cause code for "unknown parameter" and the
1562 * "Unrecognized parameter" type is the same, we can
1563 * construct the parameters in INIT ACK by copying the
1564 * ERROR causes over.
1566 unk_param
= (struct sctp_unrecognized_param
*)
1567 ((__u8
*)(err_chunk
->chunk_hdr
) +
1568 sizeof(struct sctp_chunkhdr
));
1569 /* Replace the cause code with the "Unrecognized parameter"
1572 sctp_addto_chunk(repl
, len
, unk_param
);
1575 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
1576 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1579 * Note: After sending out INIT ACK with the State Cookie parameter,
1580 * "Z" MUST NOT allocate any resources for this new association.
1581 * Otherwise, "Z" will be vulnerable to resource attacks.
1583 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
1584 retval
= SCTP_DISPOSITION_CONSUME
;
1589 retval
= SCTP_DISPOSITION_NOMEM
;
1592 sctp_association_free(new_asoc
);
1595 sctp_chunk_free(err_chunk
);
1600 * Handle simultaneous INIT.
1601 * This means we started an INIT and then we got an INIT request from
1604 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1605 * This usually indicates an initialization collision, i.e., each
1606 * endpoint is attempting, at about the same time, to establish an
1607 * association with the other endpoint.
1609 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1610 * endpoint MUST respond with an INIT ACK using the same parameters it
1611 * sent in its original INIT chunk (including its Verification Tag,
1612 * unchanged). These original parameters are combined with those from the
1613 * newly received INIT chunk. The endpoint shall also generate a State
1614 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1615 * INIT to calculate the State Cookie.
1617 * After that, the endpoint MUST NOT change its state, the T1-init
1618 * timer shall be left running and the corresponding TCB MUST NOT be
1619 * destroyed. The normal procedures for handling State Cookies when
1620 * a TCB exists will resolve the duplicate INITs to a single association.
1622 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1623 * its Tie-Tags with the Tag information of itself and its peer (see
1624 * section 5.2.2 for a description of the Tie-Tags).
1626 * Verification Tag: Not explicit, but an INIT can not have a valid
1627 * verification tag, so we skip the check.
1630 * (endpoint, asoc, chunk)
1633 * (asoc, reply_msg, msg_up, timers, counters)
1635 * The return value is the disposition of the chunk.
1637 enum sctp_disposition
sctp_sf_do_5_2_1_siminit(
1639 const struct sctp_endpoint
*ep
,
1640 const struct sctp_association
*asoc
,
1641 const union sctp_subtype type
,
1643 struct sctp_cmd_seq
*commands
)
1645 /* Call helper to do the real work for both simulataneous and
1646 * duplicate INIT chunk handling.
1648 return sctp_sf_do_unexpected_init(net
, ep
, asoc
, type
, arg
, commands
);
1652 * Handle duplicated INIT messages. These are usually delayed
1655 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1656 * COOKIE-ECHOED and COOKIE-WAIT
1658 * Unless otherwise stated, upon reception of an unexpected INIT for
1659 * this association, the endpoint shall generate an INIT ACK with a
1660 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1661 * current Verification Tag and peer's Verification Tag into a reserved
1662 * place within the state cookie. We shall refer to these locations as
1663 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1664 * containing this INIT ACK MUST carry a Verification Tag value equal to
1665 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1666 * MUST contain a new Initiation Tag (randomly generated see Section
1667 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1668 * existing parameters of the association (e.g. number of outbound
1669 * streams) into the INIT ACK and cookie.
1671 * After sending out the INIT ACK, the endpoint shall take no further
1672 * actions, i.e., the existing association, including its current state,
1673 * and the corresponding TCB MUST NOT be changed.
1675 * Note: Only when a TCB exists and the association is not in a COOKIE-
1676 * WAIT state are the Tie-Tags populated. For a normal association INIT
1677 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1678 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1679 * State Cookie are populated as specified in section 5.2.1.
1681 * Verification Tag: Not specified, but an INIT has no way of knowing
1682 * what the verification tag could be, so we ignore it.
1685 * (endpoint, asoc, chunk)
1688 * (asoc, reply_msg, msg_up, timers, counters)
1690 * The return value is the disposition of the chunk.
1692 enum sctp_disposition
sctp_sf_do_5_2_2_dupinit(
1694 const struct sctp_endpoint
*ep
,
1695 const struct sctp_association
*asoc
,
1696 const union sctp_subtype type
,
1698 struct sctp_cmd_seq
*commands
)
1700 /* Call helper to do the real work for both simulataneous and
1701 * duplicate INIT chunk handling.
1703 return sctp_sf_do_unexpected_init(net
, ep
, asoc
, type
, arg
, commands
);
1708 * Unexpected INIT-ACK handler.
1711 * If an INIT ACK received by an endpoint in any state other than the
1712 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1713 * An unexpected INIT ACK usually indicates the processing of an old or
1714 * duplicated INIT chunk.
1716 enum sctp_disposition
sctp_sf_do_5_2_3_initack(
1718 const struct sctp_endpoint
*ep
,
1719 const struct sctp_association
*asoc
,
1720 const union sctp_subtype type
,
1722 struct sctp_cmd_seq
*commands
)
1724 /* Per the above section, we'll discard the chunk if we have an
1725 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1727 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
)
1728 return sctp_sf_ootb(net
, ep
, asoc
, type
, arg
, commands
);
1730 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
1733 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1736 * A) In this case, the peer may have restarted.
1738 static enum sctp_disposition
sctp_sf_do_dupcook_a(
1740 const struct sctp_endpoint
*ep
,
1741 const struct sctp_association
*asoc
,
1742 struct sctp_chunk
*chunk
,
1743 struct sctp_cmd_seq
*commands
,
1744 struct sctp_association
*new_asoc
)
1746 struct sctp_init_chunk
*peer_init
;
1747 enum sctp_disposition disposition
;
1748 struct sctp_ulpevent
*ev
;
1749 struct sctp_chunk
*repl
;
1750 struct sctp_chunk
*err
;
1752 /* new_asoc is a brand-new association, so these are not yet
1753 * side effects--it is safe to run them here.
1755 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1757 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
), peer_init
,
1761 /* Make sure no new addresses are being added during the
1762 * restart. Though this is a pretty complicated attack
1763 * since you'd have to get inside the cookie.
1765 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
, commands
)) {
1766 return SCTP_DISPOSITION_CONSUME
;
1769 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1770 * the peer has restarted (Action A), it MUST NOT setup a new
1771 * association but instead resend the SHUTDOWN ACK and send an ERROR
1772 * chunk with a "Cookie Received while Shutting Down" error cause to
1775 if (sctp_state(asoc
, SHUTDOWN_ACK_SENT
)) {
1776 disposition
= sctp_sf_do_9_2_reshutack(net
, ep
, asoc
,
1777 SCTP_ST_CHUNK(chunk
->chunk_hdr
->type
),
1779 if (SCTP_DISPOSITION_NOMEM
== disposition
)
1782 err
= sctp_make_op_error(asoc
, chunk
,
1783 SCTP_ERROR_COOKIE_IN_SHUTDOWN
,
1786 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1789 return SCTP_DISPOSITION_CONSUME
;
1792 /* For now, stop pending T3-rtx and SACK timers, fail any unsent/unacked
1793 * data. Consider the optional choice of resending of this data.
1795 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
1796 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1797 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK
));
1798 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_OUTQUEUE
, SCTP_NULL());
1800 /* Stop pending T4-rto timer, teardown ASCONF queue, ASCONF-ACK queue
1801 * and ASCONF-ACK cache.
1803 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1804 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
1805 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_ASCONF_QUEUE
, SCTP_NULL());
1807 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1811 /* Report association restart to upper layer. */
1812 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_RESTART
, 0,
1813 new_asoc
->c
.sinit_num_ostreams
,
1814 new_asoc
->c
.sinit_max_instreams
,
1819 /* Update the content of current association. */
1820 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1821 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
1822 if (sctp_state(asoc
, SHUTDOWN_PENDING
) &&
1823 (sctp_sstate(asoc
->base
.sk
, CLOSING
) ||
1824 sock_flag(asoc
->base
.sk
, SOCK_DEAD
))) {
1825 /* if were currently in SHUTDOWN_PENDING, but the socket
1826 * has been closed by user, don't transition to ESTABLISHED.
1827 * Instead trigger SHUTDOWN bundled with COOKIE_ACK.
1829 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1830 return sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
,
1831 SCTP_ST_CHUNK(0), NULL
,
1834 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1835 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1836 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1838 return SCTP_DISPOSITION_CONSUME
;
1841 sctp_chunk_free(repl
);
1843 return SCTP_DISPOSITION_NOMEM
;
1846 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1849 * B) In this case, both sides may be attempting to start an association
1850 * at about the same time but the peer endpoint started its INIT
1851 * after responding to the local endpoint's INIT
1853 /* This case represents an initialization collision. */
1854 static enum sctp_disposition
sctp_sf_do_dupcook_b(
1856 const struct sctp_endpoint
*ep
,
1857 const struct sctp_association
*asoc
,
1858 struct sctp_chunk
*chunk
,
1859 struct sctp_cmd_seq
*commands
,
1860 struct sctp_association
*new_asoc
)
1862 struct sctp_init_chunk
*peer_init
;
1863 struct sctp_chunk
*repl
;
1865 /* new_asoc is a brand-new association, so these are not yet
1866 * side effects--it is safe to run them here.
1868 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1869 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
), peer_init
,
1873 /* Update the content of current association. */
1874 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1875 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1876 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1877 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
1878 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
1880 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1884 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1886 /* RFC 2960 5.1 Normal Establishment of an Association
1888 * D) IMPLEMENTATION NOTE: An implementation may choose to
1889 * send the Communication Up notification to the SCTP user
1890 * upon reception of a valid COOKIE ECHO chunk.
1892 * Sadly, this needs to be implemented as a side-effect, because
1893 * we are not guaranteed to have set the association id of the real
1894 * association and so these notifications need to be delayed until
1895 * the association id is allocated.
1898 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_CHANGE
, SCTP_U8(SCTP_COMM_UP
));
1900 /* Sockets API Draft Section 5.3.1.6
1901 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1902 * delivers this notification to inform the application that of the
1903 * peers requested adaptation layer.
1905 * This also needs to be done as a side effect for the same reason as
1908 if (asoc
->peer
.adaptation_ind
)
1909 sctp_add_cmd_sf(commands
, SCTP_CMD_ADAPTATION_IND
, SCTP_NULL());
1911 return SCTP_DISPOSITION_CONSUME
;
1914 return SCTP_DISPOSITION_NOMEM
;
1917 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1920 * C) In this case, the local endpoint's cookie has arrived late.
1921 * Before it arrived, the local endpoint sent an INIT and received an
1922 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1923 * but a new tag of its own.
1925 /* This case represents an initialization collision. */
1926 static enum sctp_disposition
sctp_sf_do_dupcook_c(
1928 const struct sctp_endpoint
*ep
,
1929 const struct sctp_association
*asoc
,
1930 struct sctp_chunk
*chunk
,
1931 struct sctp_cmd_seq
*commands
,
1932 struct sctp_association
*new_asoc
)
1934 /* The cookie should be silently discarded.
1935 * The endpoint SHOULD NOT change states and should leave
1936 * any timers running.
1938 return SCTP_DISPOSITION_DISCARD
;
1941 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1945 * D) When both local and remote tags match the endpoint should always
1946 * enter the ESTABLISHED state, if it has not already done so.
1948 /* This case represents an initialization collision. */
1949 static enum sctp_disposition
sctp_sf_do_dupcook_d(
1951 const struct sctp_endpoint
*ep
,
1952 const struct sctp_association
*asoc
,
1953 struct sctp_chunk
*chunk
,
1954 struct sctp_cmd_seq
*commands
,
1955 struct sctp_association
*new_asoc
)
1957 struct sctp_ulpevent
*ev
= NULL
, *ai_ev
= NULL
;
1958 struct sctp_chunk
*repl
;
1960 /* Clarification from Implementor's Guide:
1961 * D) When both local and remote tags match the endpoint should
1962 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1963 * It should stop any cookie timer that may be running and send
1967 /* Don't accidentally move back into established state. */
1968 if (asoc
->state
< SCTP_STATE_ESTABLISHED
) {
1969 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1970 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
1971 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1972 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1973 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
1974 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
,
1977 /* RFC 2960 5.1 Normal Establishment of an Association
1979 * D) IMPLEMENTATION NOTE: An implementation may choose
1980 * to send the Communication Up notification to the
1981 * SCTP user upon reception of a valid COOKIE
1984 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0,
1986 asoc
->c
.sinit_num_ostreams
,
1987 asoc
->c
.sinit_max_instreams
,
1992 /* Sockets API Draft Section 5.3.1.6
1993 * When a peer sends a Adaptation Layer Indication parameter,
1994 * SCTP delivers this notification to inform the application
1995 * that of the peers requested adaptation layer.
1997 if (asoc
->peer
.adaptation_ind
) {
1998 ai_ev
= sctp_ulpevent_make_adaptation_indication(asoc
,
2006 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
2010 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
2013 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
2016 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
2017 SCTP_ULPEVENT(ai_ev
));
2019 return SCTP_DISPOSITION_CONSUME
;
2023 sctp_ulpevent_free(ai_ev
);
2025 sctp_ulpevent_free(ev
);
2026 return SCTP_DISPOSITION_NOMEM
;
2030 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
2031 * chunk was retransmitted and then delayed in the network.
2033 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
2035 * Verification Tag: None. Do cookie validation.
2038 * (endpoint, asoc, chunk)
2041 * (asoc, reply_msg, msg_up, timers, counters)
2043 * The return value is the disposition of the chunk.
2045 enum sctp_disposition
sctp_sf_do_5_2_4_dupcook(
2047 const struct sctp_endpoint
*ep
,
2048 const struct sctp_association
*asoc
,
2049 const union sctp_subtype type
,
2051 struct sctp_cmd_seq
*commands
)
2053 struct sctp_association
*new_asoc
;
2054 struct sctp_chunk
*chunk
= arg
;
2055 enum sctp_disposition retval
;
2056 struct sctp_chunk
*err_chk_p
;
2060 /* Make sure that the chunk has a valid length from the protocol
2061 * perspective. In this case check to make sure we have at least
2062 * enough for the chunk header. Cookie length verification is
2065 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
2066 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2069 /* "Decode" the chunk. We have no optional parameters so we
2070 * are in good shape.
2072 chunk
->subh
.cookie_hdr
= (struct sctp_signed_cookie
*)chunk
->skb
->data
;
2073 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
2074 sizeof(struct sctp_chunkhdr
)))
2077 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
2078 * of a duplicate COOKIE ECHO match the Verification Tags of the
2079 * current association, consider the State Cookie valid even if
2080 * the lifespan is exceeded.
2082 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
2086 * If the re-build failed, what is the proper error path
2089 * [We should abort the association. --piggy]
2092 /* FIXME: Several errors are possible. A bad cookie should
2093 * be silently discarded, but think about logging it too.
2096 case -SCTP_IERROR_NOMEM
:
2099 case -SCTP_IERROR_STALE_COOKIE
:
2100 sctp_send_stale_cookie_err(net
, ep
, asoc
, chunk
, commands
,
2102 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2103 case -SCTP_IERROR_BAD_SIG
:
2105 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2109 /* Set temp so that it won't be added into hashtable */
2112 /* Compare the tie_tag in cookie with the verification tag of
2113 * current association.
2115 action
= sctp_tietags_compare(new_asoc
, asoc
);
2118 case 'A': /* Association restart. */
2119 retval
= sctp_sf_do_dupcook_a(net
, ep
, asoc
, chunk
, commands
,
2123 case 'B': /* Collision case B. */
2124 retval
= sctp_sf_do_dupcook_b(net
, ep
, asoc
, chunk
, commands
,
2128 case 'C': /* Collision case C. */
2129 retval
= sctp_sf_do_dupcook_c(net
, ep
, asoc
, chunk
, commands
,
2133 case 'D': /* Collision case D. */
2134 retval
= sctp_sf_do_dupcook_d(net
, ep
, asoc
, chunk
, commands
,
2138 default: /* Discard packet for all others. */
2139 retval
= sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2143 /* Delete the tempory new association. */
2144 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_ASOC
, SCTP_ASOC(new_asoc
));
2145 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
2147 /* Restore association pointer to provide SCTP command interpeter
2148 * with a valid context in case it needs to manipulate
2150 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_ASOC
,
2151 SCTP_ASOC((struct sctp_association
*)asoc
));
2156 return SCTP_DISPOSITION_NOMEM
;
2160 * Process an ABORT. (SHUTDOWN-PENDING state)
2162 * See sctp_sf_do_9_1_abort().
2164 enum sctp_disposition
sctp_sf_shutdown_pending_abort(
2166 const struct sctp_endpoint
*ep
,
2167 const struct sctp_association
*asoc
,
2168 const union sctp_subtype type
,
2170 struct sctp_cmd_seq
*commands
)
2172 struct sctp_chunk
*chunk
= arg
;
2174 if (!sctp_vtag_verify_either(chunk
, asoc
))
2175 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2177 /* Make sure that the ABORT chunk has a valid length.
2178 * Since this is an ABORT chunk, we have to discard it
2179 * because of the following text:
2180 * RFC 2960, Section 3.3.7
2181 * If an endpoint receives an ABORT with a format error or for an
2182 * association that doesn't exist, it MUST silently discard it.
2183 * Because the length is "invalid", we can't really discard just
2184 * as we do not know its true length. So, to be safe, discard the
2187 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_abort_chunk
)))
2188 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2190 /* ADD-IP: Special case for ABORT chunks
2191 * F4) One special consideration is that ABORT Chunks arriving
2192 * destined to the IP address being deleted MUST be
2193 * ignored (see Section 5.3.1 for further details).
2195 if (SCTP_ADDR_DEL
==
2196 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2197 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2199 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2203 * Process an ABORT. (SHUTDOWN-SENT state)
2205 * See sctp_sf_do_9_1_abort().
2207 enum sctp_disposition
sctp_sf_shutdown_sent_abort(
2209 const struct sctp_endpoint
*ep
,
2210 const struct sctp_association
*asoc
,
2211 const union sctp_subtype type
,
2213 struct sctp_cmd_seq
*commands
)
2215 struct sctp_chunk
*chunk
= arg
;
2217 if (!sctp_vtag_verify_either(chunk
, asoc
))
2218 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2220 /* Make sure that the ABORT chunk has a valid length.
2221 * Since this is an ABORT chunk, we have to discard it
2222 * because of the following text:
2223 * RFC 2960, Section 3.3.7
2224 * If an endpoint receives an ABORT with a format error or for an
2225 * association that doesn't exist, it MUST silently discard it.
2226 * Because the length is "invalid", we can't really discard just
2227 * as we do not know its true length. So, to be safe, discard the
2230 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_abort_chunk
)))
2231 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2233 /* ADD-IP: Special case for ABORT chunks
2234 * F4) One special consideration is that ABORT Chunks arriving
2235 * destined to the IP address being deleted MUST be
2236 * ignored (see Section 5.3.1 for further details).
2238 if (SCTP_ADDR_DEL
==
2239 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2240 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2242 /* Stop the T2-shutdown timer. */
2243 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2244 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2246 /* Stop the T5-shutdown guard timer. */
2247 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2248 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
2250 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2254 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2256 * See sctp_sf_do_9_1_abort().
2258 enum sctp_disposition
sctp_sf_shutdown_ack_sent_abort(
2260 const struct sctp_endpoint
*ep
,
2261 const struct sctp_association
*asoc
,
2262 const union sctp_subtype type
,
2264 struct sctp_cmd_seq
*commands
)
2266 /* The same T2 timer, so we should be able to use
2267 * common function with the SHUTDOWN-SENT state.
2269 return sctp_sf_shutdown_sent_abort(net
, ep
, asoc
, type
, arg
, commands
);
2273 * Handle an Error received in COOKIE_ECHOED state.
2275 * Only handle the error type of stale COOKIE Error, the other errors will
2279 * (endpoint, asoc, chunk)
2282 * (asoc, reply_msg, msg_up, timers, counters)
2284 * The return value is the disposition of the chunk.
2286 enum sctp_disposition
sctp_sf_cookie_echoed_err(
2288 const struct sctp_endpoint
*ep
,
2289 const struct sctp_association
*asoc
,
2290 const union sctp_subtype type
,
2292 struct sctp_cmd_seq
*commands
)
2294 struct sctp_chunk
*chunk
= arg
;
2295 struct sctp_errhdr
*err
;
2297 if (!sctp_vtag_verify(chunk
, asoc
))
2298 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2300 /* Make sure that the ERROR chunk has a valid length.
2301 * The parameter walking depends on this as well.
2303 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_operr_chunk
)))
2304 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2307 /* Process the error here */
2308 /* FUTURE FIXME: When PR-SCTP related and other optional
2309 * parms are emitted, this will have to change to handle multiple
2312 sctp_walk_errors(err
, chunk
->chunk_hdr
) {
2313 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
)
2314 return sctp_sf_do_5_2_6_stale(net
, ep
, asoc
, type
,
2318 /* It is possible to have malformed error causes, and that
2319 * will cause us to end the walk early. However, since
2320 * we are discarding the packet, there should be no adverse
2323 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2327 * Handle a Stale COOKIE Error
2329 * Section: 5.2.6 Handle Stale COOKIE Error
2330 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2331 * one of the following three alternatives.
2333 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2334 * Preservative parameter requesting an extension to the lifetime of
2335 * the State Cookie. When calculating the time extension, an
2336 * implementation SHOULD use the RTT information measured based on the
2337 * previous COOKIE ECHO / ERROR exchange, and should add no more
2338 * than 1 second beyond the measured RTT, due to long State Cookie
2339 * lifetimes making the endpoint more subject to a replay attack.
2341 * Verification Tag: Not explicit, but safe to ignore.
2344 * (endpoint, asoc, chunk)
2347 * (asoc, reply_msg, msg_up, timers, counters)
2349 * The return value is the disposition of the chunk.
2351 static enum sctp_disposition
sctp_sf_do_5_2_6_stale(
2353 const struct sctp_endpoint
*ep
,
2354 const struct sctp_association
*asoc
,
2355 const union sctp_subtype type
,
2357 struct sctp_cmd_seq
*commands
)
2359 int attempts
= asoc
->init_err_counter
+ 1;
2360 struct sctp_chunk
*chunk
= arg
, *reply
;
2361 struct sctp_cookie_preserve_param bht
;
2362 struct sctp_bind_addr
*bp
;
2363 struct sctp_errhdr
*err
;
2366 if (attempts
> asoc
->max_init_attempts
) {
2367 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
2368 SCTP_ERROR(ETIMEDOUT
));
2369 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2370 SCTP_PERR(SCTP_ERROR_STALE_COOKIE
));
2371 return SCTP_DISPOSITION_DELETE_TCB
;
2374 err
= (struct sctp_errhdr
*)(chunk
->skb
->data
);
2376 /* When calculating the time extension, an implementation
2377 * SHOULD use the RTT information measured based on the
2378 * previous COOKIE ECHO / ERROR exchange, and should add no
2379 * more than 1 second beyond the measured RTT, due to long
2380 * State Cookie lifetimes making the endpoint more subject to
2382 * Measure of Staleness's unit is usec. (1/1000000 sec)
2383 * Suggested Cookie Life-span Increment's unit is msec.
2385 * In general, if you use the suggested cookie life, the value
2386 * found in the field of measure of staleness should be doubled
2387 * to give ample time to retransmit the new cookie and thus
2388 * yield a higher probability of success on the reattempt.
2390 stale
= ntohl(*(__be32
*)((u8
*)err
+ sizeof(*err
)));
2391 stale
= (stale
* 2) / 1000;
2393 bht
.param_hdr
.type
= SCTP_PARAM_COOKIE_PRESERVATIVE
;
2394 bht
.param_hdr
.length
= htons(sizeof(bht
));
2395 bht
.lifespan_increment
= htonl(stale
);
2397 /* Build that new INIT chunk. */
2398 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
2399 reply
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, sizeof(bht
));
2403 sctp_addto_chunk(reply
, sizeof(bht
), &bht
);
2405 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2406 sctp_add_cmd_sf(commands
, SCTP_CMD_CLEAR_INIT_TAG
, SCTP_NULL());
2408 /* Stop pending T3-rtx and heartbeat timers */
2409 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
2410 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
2412 /* Delete non-primary peer ip addresses since we are transitioning
2413 * back to the COOKIE-WAIT state
2415 sctp_add_cmd_sf(commands
, SCTP_CMD_DEL_NON_PRIMARY
, SCTP_NULL());
2417 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2420 sctp_add_cmd_sf(commands
, SCTP_CMD_T1_RETRAN
,
2421 SCTP_TRANSPORT(asoc
->peer
.primary_path
));
2423 /* Cast away the const modifier, as we want to just
2424 * rerun it through as a sideffect.
2426 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_INC
, SCTP_NULL());
2428 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2429 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
2430 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2431 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
2432 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
2433 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2435 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2437 return SCTP_DISPOSITION_CONSUME
;
2440 return SCTP_DISPOSITION_NOMEM
;
2447 * After checking the Verification Tag, the receiving endpoint shall
2448 * remove the association from its record, and shall report the
2449 * termination to its upper layer.
2451 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2452 * B) Rules for packet carrying ABORT:
2454 * - The endpoint shall always fill in the Verification Tag field of the
2455 * outbound packet with the destination endpoint's tag value if it
2458 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2459 * MUST follow the procedure described in Section 8.4.
2461 * - The receiver MUST accept the packet if the Verification Tag
2462 * matches either its own tag, OR the tag of its peer. Otherwise, the
2463 * receiver MUST silently discard the packet and take no further
2467 * (endpoint, asoc, chunk)
2470 * (asoc, reply_msg, msg_up, timers, counters)
2472 * The return value is the disposition of the chunk.
2474 enum sctp_disposition
sctp_sf_do_9_1_abort(
2476 const struct sctp_endpoint
*ep
,
2477 const struct sctp_association
*asoc
,
2478 const union sctp_subtype type
,
2480 struct sctp_cmd_seq
*commands
)
2482 struct sctp_chunk
*chunk
= arg
;
2484 if (!sctp_vtag_verify_either(chunk
, asoc
))
2485 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2487 /* Make sure that the ABORT chunk has a valid length.
2488 * Since this is an ABORT chunk, we have to discard it
2489 * because of the following text:
2490 * RFC 2960, Section 3.3.7
2491 * If an endpoint receives an ABORT with a format error or for an
2492 * association that doesn't exist, it MUST silently discard it.
2493 * Because the length is "invalid", we can't really discard just
2494 * as we do not know its true length. So, to be safe, discard the
2497 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_abort_chunk
)))
2498 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2500 /* ADD-IP: Special case for ABORT chunks
2501 * F4) One special consideration is that ABORT Chunks arriving
2502 * destined to the IP address being deleted MUST be
2503 * ignored (see Section 5.3.1 for further details).
2505 if (SCTP_ADDR_DEL
==
2506 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2507 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2509 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2512 static enum sctp_disposition
__sctp_sf_do_9_1_abort(
2514 const struct sctp_endpoint
*ep
,
2515 const struct sctp_association
*asoc
,
2516 const union sctp_subtype type
,
2518 struct sctp_cmd_seq
*commands
)
2520 __be16 error
= SCTP_ERROR_NO_ERROR
;
2521 struct sctp_chunk
*chunk
= arg
;
2524 /* See if we have an error cause code in the chunk. */
2525 len
= ntohs(chunk
->chunk_hdr
->length
);
2526 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
)) {
2527 struct sctp_errhdr
*err
;
2529 sctp_walk_errors(err
, chunk
->chunk_hdr
);
2530 if ((void *)err
!= (void *)chunk
->chunk_end
)
2531 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
,
2534 error
= ((struct sctp_errhdr
*)chunk
->skb
->data
)->cause
;
2537 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(ECONNRESET
));
2538 /* ASSOC_FAILED will DELETE_TCB. */
2539 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
, SCTP_PERR(error
));
2540 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
2541 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
2543 return SCTP_DISPOSITION_ABORT
;
2547 * Process an ABORT. (COOKIE-WAIT state)
2549 * See sctp_sf_do_9_1_abort() above.
2551 enum sctp_disposition
sctp_sf_cookie_wait_abort(
2553 const struct sctp_endpoint
*ep
,
2554 const struct sctp_association
*asoc
,
2555 const union sctp_subtype type
,
2557 struct sctp_cmd_seq
*commands
)
2559 __be16 error
= SCTP_ERROR_NO_ERROR
;
2560 struct sctp_chunk
*chunk
= arg
;
2563 if (!sctp_vtag_verify_either(chunk
, asoc
))
2564 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2566 /* Make sure that the ABORT chunk has a valid length.
2567 * Since this is an ABORT chunk, we have to discard it
2568 * because of the following text:
2569 * RFC 2960, Section 3.3.7
2570 * If an endpoint receives an ABORT with a format error or for an
2571 * association that doesn't exist, it MUST silently discard it.
2572 * Because the length is "invalid", we can't really discard just
2573 * as we do not know its true length. So, to be safe, discard the
2576 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_abort_chunk
)))
2577 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2579 /* See if we have an error cause code in the chunk. */
2580 len
= ntohs(chunk
->chunk_hdr
->length
);
2581 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2582 error
= ((struct sctp_errhdr
*)chunk
->skb
->data
)->cause
;
2584 return sctp_stop_t1_and_abort(net
, commands
, error
, ECONNREFUSED
, asoc
,
2589 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2591 enum sctp_disposition
sctp_sf_cookie_wait_icmp_abort(
2593 const struct sctp_endpoint
*ep
,
2594 const struct sctp_association
*asoc
,
2595 const union sctp_subtype type
,
2597 struct sctp_cmd_seq
*commands
)
2599 return sctp_stop_t1_and_abort(net
, commands
, SCTP_ERROR_NO_ERROR
,
2601 (struct sctp_transport
*)arg
);
2605 * Process an ABORT. (COOKIE-ECHOED state)
2607 enum sctp_disposition
sctp_sf_cookie_echoed_abort(
2609 const struct sctp_endpoint
*ep
,
2610 const struct sctp_association
*asoc
,
2611 const union sctp_subtype type
,
2613 struct sctp_cmd_seq
*commands
)
2615 /* There is a single T1 timer, so we should be able to use
2616 * common function with the COOKIE-WAIT state.
2618 return sctp_sf_cookie_wait_abort(net
, ep
, asoc
, type
, arg
, commands
);
2622 * Stop T1 timer and abort association with "INIT failed".
2624 * This is common code called by several sctp_sf_*_abort() functions above.
2626 static enum sctp_disposition
sctp_stop_t1_and_abort(
2628 struct sctp_cmd_seq
*commands
,
2629 __be16 error
, int sk_err
,
2630 const struct sctp_association
*asoc
,
2631 struct sctp_transport
*transport
)
2633 pr_debug("%s: ABORT received (INIT)\n", __func__
);
2635 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2636 SCTP_STATE(SCTP_STATE_CLOSED
));
2637 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
2638 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2639 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2640 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(sk_err
));
2641 /* CMD_INIT_FAILED will DELETE_TCB. */
2642 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2645 return SCTP_DISPOSITION_ABORT
;
2649 * sctp_sf_do_9_2_shut
2652 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2653 * - enter the SHUTDOWN-RECEIVED state,
2655 * - stop accepting new data from its SCTP user
2657 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2658 * that all its outstanding DATA chunks have been received by the
2661 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2662 * send a SHUTDOWN in response to a ULP request. And should discard
2663 * subsequent SHUTDOWN chunks.
2665 * If there are still outstanding DATA chunks left, the SHUTDOWN
2666 * receiver shall continue to follow normal data transmission
2667 * procedures defined in Section 6 until all outstanding DATA chunks
2668 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2669 * new data from its SCTP user.
2671 * Verification Tag: 8.5 Verification Tag [Normal verification]
2674 * (endpoint, asoc, chunk)
2677 * (asoc, reply_msg, msg_up, timers, counters)
2679 * The return value is the disposition of the chunk.
2681 enum sctp_disposition
sctp_sf_do_9_2_shutdown(
2683 const struct sctp_endpoint
*ep
,
2684 const struct sctp_association
*asoc
,
2685 const union sctp_subtype type
,
2687 struct sctp_cmd_seq
*commands
)
2689 enum sctp_disposition disposition
;
2690 struct sctp_chunk
*chunk
= arg
;
2691 struct sctp_shutdownhdr
*sdh
;
2692 struct sctp_ulpevent
*ev
;
2695 if (!sctp_vtag_verify(chunk
, asoc
))
2696 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2698 /* Make sure that the SHUTDOWN chunk has a valid length. */
2699 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_shutdown_chunk
)))
2700 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2703 /* Convert the elaborate header. */
2704 sdh
= (struct sctp_shutdownhdr
*)chunk
->skb
->data
;
2705 skb_pull(chunk
->skb
, sizeof(*sdh
));
2706 chunk
->subh
.shutdown_hdr
= sdh
;
2707 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2709 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2710 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__
, ctsn
,
2711 asoc
->ctsn_ack_point
);
2713 return SCTP_DISPOSITION_DISCARD
;
2716 /* If Cumulative TSN Ack beyond the max tsn currently
2717 * send, terminating the association and respond to the
2718 * sender with an ABORT.
2720 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2721 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
2723 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2724 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2725 * inform the application that it should cease sending data.
2727 ev
= sctp_ulpevent_make_shutdown_event(asoc
, 0, GFP_ATOMIC
);
2729 disposition
= SCTP_DISPOSITION_NOMEM
;
2732 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
2734 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2735 * - enter the SHUTDOWN-RECEIVED state,
2736 * - stop accepting new data from its SCTP user
2738 * [This is implicit in the new state.]
2740 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2741 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED
));
2742 disposition
= SCTP_DISPOSITION_CONSUME
;
2744 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
2745 disposition
= sctp_sf_do_9_2_shutdown_ack(net
, ep
, asoc
, type
,
2749 if (SCTP_DISPOSITION_NOMEM
== disposition
)
2752 /* - verify, by checking the Cumulative TSN Ack field of the
2753 * chunk, that all its outstanding DATA chunks have been
2754 * received by the SHUTDOWN sender.
2756 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2757 SCTP_BE32(chunk
->subh
.shutdown_hdr
->cum_tsn_ack
));
2764 * sctp_sf_do_9_2_shut_ctsn
2766 * Once an endpoint has reached the SHUTDOWN-RECEIVED state,
2767 * it MUST NOT send a SHUTDOWN in response to a ULP request.
2768 * The Cumulative TSN Ack of the received SHUTDOWN chunk
2769 * MUST be processed.
2771 enum sctp_disposition
sctp_sf_do_9_2_shut_ctsn(
2773 const struct sctp_endpoint
*ep
,
2774 const struct sctp_association
*asoc
,
2775 const union sctp_subtype type
,
2777 struct sctp_cmd_seq
*commands
)
2779 struct sctp_chunk
*chunk
= arg
;
2780 struct sctp_shutdownhdr
*sdh
;
2783 if (!sctp_vtag_verify(chunk
, asoc
))
2784 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2786 /* Make sure that the SHUTDOWN chunk has a valid length. */
2787 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_shutdown_chunk
)))
2788 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2791 sdh
= (struct sctp_shutdownhdr
*)chunk
->skb
->data
;
2792 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2794 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2795 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__
, ctsn
,
2796 asoc
->ctsn_ack_point
);
2798 return SCTP_DISPOSITION_DISCARD
;
2801 /* If Cumulative TSN Ack beyond the max tsn currently
2802 * send, terminating the association and respond to the
2803 * sender with an ABORT.
2805 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2806 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
2808 /* verify, by checking the Cumulative TSN Ack field of the
2809 * chunk, that all its outstanding DATA chunks have been
2810 * received by the SHUTDOWN sender.
2812 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2813 SCTP_BE32(sdh
->cum_tsn_ack
));
2815 return SCTP_DISPOSITION_CONSUME
;
2819 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2820 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2821 * transport addresses (either in the IP addresses or in the INIT chunk)
2822 * that belong to this association, it should discard the INIT chunk and
2823 * retransmit the SHUTDOWN ACK chunk.
2825 enum sctp_disposition
sctp_sf_do_9_2_reshutack(
2827 const struct sctp_endpoint
*ep
,
2828 const struct sctp_association
*asoc
,
2829 const union sctp_subtype type
,
2831 struct sctp_cmd_seq
*commands
)
2833 struct sctp_chunk
*chunk
= arg
;
2834 struct sctp_chunk
*reply
;
2836 /* Make sure that the chunk has a valid length */
2837 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
2838 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2841 /* Since we are not going to really process this INIT, there
2842 * is no point in verifying chunk boundries. Just generate
2845 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
2849 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2850 * the T2-SHUTDOWN timer.
2852 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
2854 /* and restart the T2-shutdown timer. */
2855 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2856 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2858 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2860 return SCTP_DISPOSITION_CONSUME
;
2862 return SCTP_DISPOSITION_NOMEM
;
2866 * sctp_sf_do_ecn_cwr
2868 * Section: Appendix A: Explicit Congestion Notification
2872 * RFC 2481 details a specific bit for a sender to send in the header of
2873 * its next outbound TCP segment to indicate to its peer that it has
2874 * reduced its congestion window. This is termed the CWR bit. For
2875 * SCTP the same indication is made by including the CWR chunk.
2876 * This chunk contains one data element, i.e. the TSN number that
2877 * was sent in the ECNE chunk. This element represents the lowest
2878 * TSN number in the datagram that was originally marked with the
2881 * Verification Tag: 8.5 Verification Tag [Normal verification]
2883 * (endpoint, asoc, chunk)
2886 * (asoc, reply_msg, msg_up, timers, counters)
2888 * The return value is the disposition of the chunk.
2890 enum sctp_disposition
sctp_sf_do_ecn_cwr(struct net
*net
,
2891 const struct sctp_endpoint
*ep
,
2892 const struct sctp_association
*asoc
,
2893 const union sctp_subtype type
,
2895 struct sctp_cmd_seq
*commands
)
2897 struct sctp_chunk
*chunk
= arg
;
2898 struct sctp_cwrhdr
*cwr
;
2901 if (!sctp_vtag_verify(chunk
, asoc
))
2902 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2904 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_ecne_chunk
)))
2905 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2908 cwr
= (struct sctp_cwrhdr
*)chunk
->skb
->data
;
2909 skb_pull(chunk
->skb
, sizeof(*cwr
));
2911 lowest_tsn
= ntohl(cwr
->lowest_tsn
);
2913 /* Does this CWR ack the last sent congestion notification? */
2914 if (TSN_lte(asoc
->last_ecne_tsn
, lowest_tsn
)) {
2915 /* Stop sending ECNE. */
2916 sctp_add_cmd_sf(commands
,
2918 SCTP_U32(lowest_tsn
));
2920 return SCTP_DISPOSITION_CONSUME
;
2926 * Section: Appendix A: Explicit Congestion Notification
2930 * RFC 2481 details a specific bit for a receiver to send back in its
2931 * TCP acknowledgements to notify the sender of the Congestion
2932 * Experienced (CE) bit having arrived from the network. For SCTP this
2933 * same indication is made by including the ECNE chunk. This chunk
2934 * contains one data element, i.e. the lowest TSN associated with the IP
2935 * datagram marked with the CE bit.....
2937 * Verification Tag: 8.5 Verification Tag [Normal verification]
2939 * (endpoint, asoc, chunk)
2942 * (asoc, reply_msg, msg_up, timers, counters)
2944 * The return value is the disposition of the chunk.
2946 enum sctp_disposition
sctp_sf_do_ecne(struct net
*net
,
2947 const struct sctp_endpoint
*ep
,
2948 const struct sctp_association
*asoc
,
2949 const union sctp_subtype type
,
2950 void *arg
, struct sctp_cmd_seq
*commands
)
2952 struct sctp_chunk
*chunk
= arg
;
2953 struct sctp_ecnehdr
*ecne
;
2955 if (!sctp_vtag_verify(chunk
, asoc
))
2956 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2958 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_ecne_chunk
)))
2959 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2962 ecne
= (struct sctp_ecnehdr
*)chunk
->skb
->data
;
2963 skb_pull(chunk
->skb
, sizeof(*ecne
));
2965 /* If this is a newer ECNE than the last CWR packet we sent out */
2966 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_ECNE
,
2967 SCTP_U32(ntohl(ecne
->lowest_tsn
)));
2969 return SCTP_DISPOSITION_CONSUME
;
2973 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2975 * The SCTP endpoint MUST always acknowledge the reception of each valid
2978 * The guidelines on delayed acknowledgement algorithm specified in
2979 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2980 * acknowledgement SHOULD be generated for at least every second packet
2981 * (not every second DATA chunk) received, and SHOULD be generated within
2982 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2983 * situations it may be beneficial for an SCTP transmitter to be more
2984 * conservative than the algorithms detailed in this document allow.
2985 * However, an SCTP transmitter MUST NOT be more aggressive than the
2986 * following algorithms allow.
2988 * A SCTP receiver MUST NOT generate more than one SACK for every
2989 * incoming packet, other than to update the offered window as the
2990 * receiving application consumes new data.
2992 * Verification Tag: 8.5 Verification Tag [Normal verification]
2995 * (endpoint, asoc, chunk)
2998 * (asoc, reply_msg, msg_up, timers, counters)
3000 * The return value is the disposition of the chunk.
3002 enum sctp_disposition
sctp_sf_eat_data_6_2(struct net
*net
,
3003 const struct sctp_endpoint
*ep
,
3004 const struct sctp_association
*asoc
,
3005 const union sctp_subtype type
,
3007 struct sctp_cmd_seq
*commands
)
3009 union sctp_arg force
= SCTP_NOFORCE();
3010 struct sctp_chunk
*chunk
= arg
;
3013 if (!sctp_vtag_verify(chunk
, asoc
)) {
3014 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3016 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3019 if (!sctp_chunk_length_valid(chunk
, sctp_datachk_len(&asoc
->stream
)))
3020 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3023 error
= sctp_eat_data(asoc
, chunk
, commands
);
3025 case SCTP_IERROR_NO_ERROR
:
3027 case SCTP_IERROR_HIGH_TSN
:
3028 case SCTP_IERROR_BAD_STREAM
:
3029 SCTP_INC_STATS(net
, SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
3030 goto discard_noforce
;
3031 case SCTP_IERROR_DUP_TSN
:
3032 case SCTP_IERROR_IGNORE_TSN
:
3033 SCTP_INC_STATS(net
, SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
3035 case SCTP_IERROR_NO_DATA
:
3036 return SCTP_DISPOSITION_ABORT
;
3037 case SCTP_IERROR_PROTO_VIOLATION
:
3038 return sctp_sf_abort_violation(net
, ep
, asoc
, chunk
, commands
,
3039 (u8
*)chunk
->subh
.data_hdr
,
3040 sctp_datahdr_len(&asoc
->stream
));
3045 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_SACK_IMM
)
3046 force
= SCTP_FORCE();
3048 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
]) {
3049 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3050 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
3053 /* If this is the last chunk in a packet, we need to count it
3054 * toward sack generation. Note that we need to SACK every
3055 * OTHER packet containing data chunks, EVEN IF WE DISCARD
3056 * THEM. We elect to NOT generate SACK's if the chunk fails
3057 * the verification tag test.
3059 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
3061 * The SCTP endpoint MUST always acknowledge the reception of
3062 * each valid DATA chunk.
3064 * The guidelines on delayed acknowledgement algorithm
3065 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
3066 * Specifically, an acknowledgement SHOULD be generated for at
3067 * least every second packet (not every second DATA chunk)
3068 * received, and SHOULD be generated within 200 ms of the
3069 * arrival of any unacknowledged DATA chunk. In some
3070 * situations it may be beneficial for an SCTP transmitter to
3071 * be more conservative than the algorithms detailed in this
3072 * document allow. However, an SCTP transmitter MUST NOT be
3073 * more aggressive than the following algorithms allow.
3075 if (chunk
->end_of_packet
)
3076 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, force
);
3078 return SCTP_DISPOSITION_CONSUME
;
3081 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
3083 * When a packet arrives with duplicate DATA chunk(s) and with
3084 * no new DATA chunk(s), the endpoint MUST immediately send a
3085 * SACK with no delay. If a packet arrives with duplicate
3086 * DATA chunk(s) bundled with new DATA chunks, the endpoint
3087 * MAY immediately send a SACK. Normally receipt of duplicate
3088 * DATA chunks will occur when the original SACK chunk was lost
3089 * and the peer's RTO has expired. The duplicate TSN number(s)
3090 * SHOULD be reported in the SACK as duplicate.
3092 /* In our case, we split the MAY SACK advice up whether or not
3093 * the last chunk is a duplicate.'
3095 if (chunk
->end_of_packet
)
3096 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3097 return SCTP_DISPOSITION_DISCARD
;
3100 if (chunk
->end_of_packet
)
3101 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, force
);
3103 return SCTP_DISPOSITION_DISCARD
;
3107 * sctp_sf_eat_data_fast_4_4
3110 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
3111 * DATA chunks without delay.
3113 * Verification Tag: 8.5 Verification Tag [Normal verification]
3115 * (endpoint, asoc, chunk)
3118 * (asoc, reply_msg, msg_up, timers, counters)
3120 * The return value is the disposition of the chunk.
3122 enum sctp_disposition
sctp_sf_eat_data_fast_4_4(
3124 const struct sctp_endpoint
*ep
,
3125 const struct sctp_association
*asoc
,
3126 const union sctp_subtype type
,
3128 struct sctp_cmd_seq
*commands
)
3130 struct sctp_chunk
*chunk
= arg
;
3133 if (!sctp_vtag_verify(chunk
, asoc
)) {
3134 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3136 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3139 if (!sctp_chunk_length_valid(chunk
, sctp_datachk_len(&asoc
->stream
)))
3140 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3143 error
= sctp_eat_data(asoc
, chunk
, commands
);
3145 case SCTP_IERROR_NO_ERROR
:
3146 case SCTP_IERROR_HIGH_TSN
:
3147 case SCTP_IERROR_DUP_TSN
:
3148 case SCTP_IERROR_IGNORE_TSN
:
3149 case SCTP_IERROR_BAD_STREAM
:
3151 case SCTP_IERROR_NO_DATA
:
3152 return SCTP_DISPOSITION_ABORT
;
3153 case SCTP_IERROR_PROTO_VIOLATION
:
3154 return sctp_sf_abort_violation(net
, ep
, asoc
, chunk
, commands
,
3155 (u8
*)chunk
->subh
.data_hdr
,
3156 sctp_datahdr_len(&asoc
->stream
));
3161 /* Go a head and force a SACK, since we are shutting down. */
3163 /* Implementor's Guide.
3165 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3166 * respond to each received packet containing one or more DATA chunk(s)
3167 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3169 if (chunk
->end_of_packet
) {
3170 /* We must delay the chunk creation since the cumulative
3171 * TSN has not been updated yet.
3173 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3174 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3175 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3176 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3179 return SCTP_DISPOSITION_CONSUME
;
3183 * Section: 6.2 Processing a Received SACK
3184 * D) Any time a SACK arrives, the endpoint performs the following:
3186 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
3187 * then drop the SACK. Since Cumulative TSN Ack is monotonically
3188 * increasing, a SACK whose Cumulative TSN Ack is less than the
3189 * Cumulative TSN Ack Point indicates an out-of-order SACK.
3191 * ii) Set rwnd equal to the newly received a_rwnd minus the number
3192 * of bytes still outstanding after processing the Cumulative TSN Ack
3193 * and the Gap Ack Blocks.
3195 * iii) If the SACK is missing a TSN that was previously
3196 * acknowledged via a Gap Ack Block (e.g., the data receiver
3197 * reneged on the data), then mark the corresponding DATA chunk
3198 * as available for retransmit: Mark it as missing for fast
3199 * retransmit as described in Section 7.2.4 and if no retransmit
3200 * timer is running for the destination address to which the DATA
3201 * chunk was originally transmitted, then T3-rtx is started for
3202 * that destination address.
3204 * Verification Tag: 8.5 Verification Tag [Normal verification]
3207 * (endpoint, asoc, chunk)
3210 * (asoc, reply_msg, msg_up, timers, counters)
3212 * The return value is the disposition of the chunk.
3214 enum sctp_disposition
sctp_sf_eat_sack_6_2(struct net
*net
,
3215 const struct sctp_endpoint
*ep
,
3216 const struct sctp_association
*asoc
,
3217 const union sctp_subtype type
,
3219 struct sctp_cmd_seq
*commands
)
3221 struct sctp_chunk
*chunk
= arg
;
3222 struct sctp_sackhdr
*sackh
;
3225 trace_sctp_probe(ep
, asoc
, chunk
);
3227 if (!sctp_vtag_verify(chunk
, asoc
))
3228 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3230 /* Make sure that the SACK chunk has a valid length. */
3231 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_sack_chunk
)))
3232 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3235 /* Pull the SACK chunk from the data buffer */
3236 sackh
= sctp_sm_pull_sack(chunk
);
3237 /* Was this a bogus SACK? */
3239 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3240 chunk
->subh
.sack_hdr
= sackh
;
3241 ctsn
= ntohl(sackh
->cum_tsn_ack
);
3243 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
3244 * Ack Point, then drop the SACK. Since Cumulative TSN
3245 * Ack is monotonically increasing, a SACK whose
3246 * Cumulative TSN Ack is less than the Cumulative TSN Ack
3247 * Point indicates an out-of-order SACK.
3249 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
3250 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__
, ctsn
,
3251 asoc
->ctsn_ack_point
);
3253 return SCTP_DISPOSITION_DISCARD
;
3256 /* If Cumulative TSN Ack beyond the max tsn currently
3257 * send, terminating the association and respond to the
3258 * sender with an ABORT.
3260 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
3261 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
3263 /* Return this SACK for further processing. */
3264 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_SACK
, SCTP_CHUNK(chunk
));
3266 /* Note: We do the rest of the work on the PROCESS_SACK
3269 return SCTP_DISPOSITION_CONSUME
;
3273 * Generate an ABORT in response to a packet.
3275 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
3277 * 8) The receiver should respond to the sender of the OOTB packet with
3278 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3279 * MUST fill in the Verification Tag field of the outbound packet
3280 * with the value found in the Verification Tag field of the OOTB
3281 * packet and set the T-bit in the Chunk Flags to indicate that the
3282 * Verification Tag is reflected. After sending this ABORT, the
3283 * receiver of the OOTB packet shall discard the OOTB packet and take
3284 * no further action.
3288 * The return value is the disposition of the chunk.
3290 static enum sctp_disposition
sctp_sf_tabort_8_4_8(
3292 const struct sctp_endpoint
*ep
,
3293 const struct sctp_association
*asoc
,
3294 const union sctp_subtype type
,
3296 struct sctp_cmd_seq
*commands
)
3298 struct sctp_packet
*packet
= NULL
;
3299 struct sctp_chunk
*chunk
= arg
;
3300 struct sctp_chunk
*abort
;
3302 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
3304 return SCTP_DISPOSITION_NOMEM
;
3306 /* Make an ABORT. The T bit will be set if the asoc
3309 abort
= sctp_make_abort(asoc
, chunk
, 0);
3311 sctp_ootb_pkt_free(packet
);
3312 return SCTP_DISPOSITION_NOMEM
;
3315 /* Reflect vtag if T-Bit is set */
3316 if (sctp_test_T_bit(abort
))
3317 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3319 /* Set the skb to the belonging sock for accounting. */
3320 abort
->skb
->sk
= ep
->base
.sk
;
3322 sctp_packet_append_chunk(packet
, abort
);
3324 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3325 SCTP_PACKET(packet
));
3327 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
3329 sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3330 return SCTP_DISPOSITION_CONSUME
;
3334 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
3335 * event as ULP notification for each cause included in the chunk.
3337 * API 5.3.1.3 - SCTP_REMOTE_ERROR
3339 * The return value is the disposition of the chunk.
3341 enum sctp_disposition
sctp_sf_operr_notify(struct net
*net
,
3342 const struct sctp_endpoint
*ep
,
3343 const struct sctp_association
*asoc
,
3344 const union sctp_subtype type
,
3346 struct sctp_cmd_seq
*commands
)
3348 struct sctp_chunk
*chunk
= arg
;
3349 struct sctp_errhdr
*err
;
3351 if (!sctp_vtag_verify(chunk
, asoc
))
3352 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3354 /* Make sure that the ERROR chunk has a valid length. */
3355 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_operr_chunk
)))
3356 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3358 sctp_walk_errors(err
, chunk
->chunk_hdr
);
3359 if ((void *)err
!= (void *)chunk
->chunk_end
)
3360 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3361 (void *)err
, commands
);
3363 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_OPERR
,
3366 return SCTP_DISPOSITION_CONSUME
;
3370 * Process an inbound SHUTDOWN ACK.
3373 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3374 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3375 * peer, and remove all record of the association.
3377 * The return value is the disposition.
3379 enum sctp_disposition
sctp_sf_do_9_2_final(struct net
*net
,
3380 const struct sctp_endpoint
*ep
,
3381 const struct sctp_association
*asoc
,
3382 const union sctp_subtype type
,
3384 struct sctp_cmd_seq
*commands
)
3386 struct sctp_chunk
*chunk
= arg
;
3387 struct sctp_chunk
*reply
;
3388 struct sctp_ulpevent
*ev
;
3390 if (!sctp_vtag_verify(chunk
, asoc
))
3391 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3393 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3394 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
3395 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3397 /* 10.2 H) SHUTDOWN COMPLETE notification
3399 * When SCTP completes the shutdown procedures (section 9.2) this
3400 * notification is passed to the upper layer.
3402 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
3403 0, 0, 0, NULL
, GFP_ATOMIC
);
3407 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3408 reply
= sctp_make_shutdown_complete(asoc
, chunk
);
3412 /* Do all the commands now (after allocation), so that we
3413 * have consistent state if memory allocation failes
3415 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
3417 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3418 * stop the T2-shutdown timer,
3420 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3421 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3423 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3424 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
3426 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
3427 SCTP_STATE(SCTP_STATE_CLOSED
));
3428 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
3429 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3430 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
3432 /* ...and remove all record of the association. */
3433 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
3434 return SCTP_DISPOSITION_DELETE_TCB
;
3437 sctp_ulpevent_free(ev
);
3439 return SCTP_DISPOSITION_NOMEM
;
3443 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3445 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3446 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3447 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3448 * packet must fill in the Verification Tag field of the outbound
3449 * packet with the Verification Tag received in the SHUTDOWN ACK and
3450 * set the T-bit in the Chunk Flags to indicate that the Verification
3453 * 8) The receiver should respond to the sender of the OOTB packet with
3454 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3455 * MUST fill in the Verification Tag field of the outbound packet
3456 * with the value found in the Verification Tag field of the OOTB
3457 * packet and set the T-bit in the Chunk Flags to indicate that the
3458 * Verification Tag is reflected. After sending this ABORT, the
3459 * receiver of the OOTB packet shall discard the OOTB packet and take
3460 * no further action.
3462 enum sctp_disposition
sctp_sf_ootb(struct net
*net
,
3463 const struct sctp_endpoint
*ep
,
3464 const struct sctp_association
*asoc
,
3465 const union sctp_subtype type
,
3466 void *arg
, struct sctp_cmd_seq
*commands
)
3468 struct sctp_chunk
*chunk
= arg
;
3469 struct sk_buff
*skb
= chunk
->skb
;
3470 struct sctp_chunkhdr
*ch
;
3471 struct sctp_errhdr
*err
;
3472 int ootb_cookie_ack
= 0;
3473 int ootb_shut_ack
= 0;
3476 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
3478 ch
= (struct sctp_chunkhdr
*)chunk
->chunk_hdr
;
3480 /* Report violation if the chunk is less then minimal */
3481 if (ntohs(ch
->length
) < sizeof(*ch
))
3482 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3485 /* Report violation if chunk len overflows */
3486 ch_end
= ((__u8
*)ch
) + SCTP_PAD4(ntohs(ch
->length
));
3487 if (ch_end
> skb_tail_pointer(skb
))
3488 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3491 /* Now that we know we at least have a chunk header,
3492 * do things that are type appropriate.
3494 if (SCTP_CID_SHUTDOWN_ACK
== ch
->type
)
3497 /* RFC 2960, Section 3.3.7
3498 * Moreover, under any circumstances, an endpoint that
3499 * receives an ABORT MUST NOT respond to that ABORT by
3500 * sending an ABORT of its own.
3502 if (SCTP_CID_ABORT
== ch
->type
)
3503 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3505 /* RFC 8.4, 7) If the packet contains a "Stale cookie" ERROR
3506 * or a COOKIE ACK the SCTP Packet should be silently
3510 if (SCTP_CID_COOKIE_ACK
== ch
->type
)
3511 ootb_cookie_ack
= 1;
3513 if (SCTP_CID_ERROR
== ch
->type
) {
3514 sctp_walk_errors(err
, ch
) {
3515 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
) {
3516 ootb_cookie_ack
= 1;
3522 ch
= (struct sctp_chunkhdr
*)ch_end
;
3523 } while (ch_end
< skb_tail_pointer(skb
));
3526 return sctp_sf_shut_8_4_5(net
, ep
, asoc
, type
, arg
, commands
);
3527 else if (ootb_cookie_ack
)
3528 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3530 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
3534 * Handle an "Out of the blue" SHUTDOWN ACK.
3536 * Section: 8.4 5, sctpimpguide 2.41.
3538 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3539 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3540 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3541 * packet must fill in the Verification Tag field of the outbound
3542 * packet with the Verification Tag received in the SHUTDOWN ACK and
3543 * set the T-bit in the Chunk Flags to indicate that the Verification
3547 * (endpoint, asoc, type, arg, commands)
3550 * (enum sctp_disposition)
3552 * The return value is the disposition of the chunk.
3554 static enum sctp_disposition
sctp_sf_shut_8_4_5(
3556 const struct sctp_endpoint
*ep
,
3557 const struct sctp_association
*asoc
,
3558 const union sctp_subtype type
,
3560 struct sctp_cmd_seq
*commands
)
3562 struct sctp_packet
*packet
= NULL
;
3563 struct sctp_chunk
*chunk
= arg
;
3564 struct sctp_chunk
*shut
;
3566 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
3568 return SCTP_DISPOSITION_NOMEM
;
3570 /* Make an SHUTDOWN_COMPLETE.
3571 * The T bit will be set if the asoc is NULL.
3573 shut
= sctp_make_shutdown_complete(asoc
, chunk
);
3575 sctp_ootb_pkt_free(packet
);
3576 return SCTP_DISPOSITION_NOMEM
;
3579 /* Reflect vtag if T-Bit is set */
3580 if (sctp_test_T_bit(shut
))
3581 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3583 /* Set the skb to the belonging sock for accounting. */
3584 shut
->skb
->sk
= ep
->base
.sk
;
3586 sctp_packet_append_chunk(packet
, shut
);
3588 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3589 SCTP_PACKET(packet
));
3591 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
3593 /* If the chunk length is invalid, we don't want to process
3594 * the reset of the packet.
3596 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
3597 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3599 /* We need to discard the rest of the packet to prevent
3600 * potential bomming attacks from additional bundled chunks.
3601 * This is documented in SCTP Threats ID.
3603 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3607 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3609 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3610 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3611 * procedures in section 8.4 SHOULD be followed, in other words it
3612 * should be treated as an Out Of The Blue packet.
3613 * [This means that we do NOT check the Verification Tag on these
3617 enum sctp_disposition
sctp_sf_do_8_5_1_E_sa(struct net
*net
,
3618 const struct sctp_endpoint
*ep
,
3619 const struct sctp_association
*asoc
,
3620 const union sctp_subtype type
,
3622 struct sctp_cmd_seq
*commands
)
3624 struct sctp_chunk
*chunk
= arg
;
3626 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3627 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
3628 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3631 /* Although we do have an association in this case, it corresponds
3632 * to a restarted association. So the packet is treated as an OOTB
3633 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3634 * called with a NULL association.
3636 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
3638 return sctp_sf_shut_8_4_5(net
, ep
, NULL
, type
, arg
, commands
);
3641 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3642 enum sctp_disposition
sctp_sf_do_asconf(struct net
*net
,
3643 const struct sctp_endpoint
*ep
,
3644 const struct sctp_association
*asoc
,
3645 const union sctp_subtype type
,
3647 struct sctp_cmd_seq
*commands
)
3649 struct sctp_paramhdr
*err_param
= NULL
;
3650 struct sctp_chunk
*asconf_ack
= NULL
;
3651 struct sctp_chunk
*chunk
= arg
;
3652 struct sctp_addiphdr
*hdr
;
3655 if (!sctp_vtag_verify(chunk
, asoc
)) {
3656 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3658 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3661 /* ADD-IP: Section 4.1.1
3662 * This chunk MUST be sent in an authenticated way by using
3663 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3664 * is received unauthenticated it MUST be silently discarded as
3665 * described in [I-D.ietf-tsvwg-sctp-auth].
3667 if (!net
->sctp
.addip_noauth
&& !chunk
->auth
)
3668 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
,
3671 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3672 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_addip_chunk
)))
3673 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3676 hdr
= (struct sctp_addiphdr
*)chunk
->skb
->data
;
3677 serial
= ntohl(hdr
->serial
);
3679 /* Verify the ASCONF chunk before processing it. */
3680 if (!sctp_verify_asconf(asoc
, chunk
, true, &err_param
))
3681 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3682 (void *)err_param
, commands
);
3684 /* ADDIP 5.2 E1) Compare the value of the serial number to the value
3685 * the endpoint stored in a new association variable
3686 * 'Peer-Serial-Number'.
3688 if (serial
== asoc
->peer
.addip_serial
+ 1) {
3689 /* If this is the first instance of ASCONF in the packet,
3690 * we can clean our old ASCONF-ACKs.
3692 if (!chunk
->has_asconf
)
3693 sctp_assoc_clean_asconf_ack_cache(asoc
);
3695 /* ADDIP 5.2 E4) When the Sequence Number matches the next one
3696 * expected, process the ASCONF as described below and after
3697 * processing the ASCONF Chunk, append an ASCONF-ACK Chunk to
3698 * the response packet and cache a copy of it (in the event it
3699 * later needs to be retransmitted).
3701 * Essentially, do V1-V5.
3703 asconf_ack
= sctp_process_asconf((struct sctp_association
*)
3706 return SCTP_DISPOSITION_NOMEM
;
3707 } else if (serial
< asoc
->peer
.addip_serial
+ 1) {
3709 * If the value found in the Sequence Number is less than the
3710 * ('Peer- Sequence-Number' + 1), simply skip to the next
3711 * ASCONF, and include in the outbound response packet
3712 * any previously cached ASCONF-ACK response that was
3713 * sent and saved that matches the Sequence Number of the
3714 * ASCONF. Note: It is possible that no cached ASCONF-ACK
3715 * Chunk exists. This will occur when an older ASCONF
3716 * arrives out of order. In such a case, the receiver
3717 * should skip the ASCONF Chunk and not include ASCONF-ACK
3718 * Chunk for that chunk.
3720 asconf_ack
= sctp_assoc_lookup_asconf_ack(asoc
, hdr
->serial
);
3722 return SCTP_DISPOSITION_DISCARD
;
3724 /* Reset the transport so that we select the correct one
3725 * this time around. This is to make sure that we don't
3726 * accidentally use a stale transport that's been removed.
3728 asconf_ack
->transport
= NULL
;
3730 /* ADDIP 5.2 E5) Otherwise, the ASCONF Chunk is discarded since
3731 * it must be either a stale packet or from an attacker.
3733 return SCTP_DISPOSITION_DISCARD
;
3736 /* ADDIP 5.2 E6) The destination address of the SCTP packet
3737 * containing the ASCONF-ACK Chunks MUST be the source address of
3738 * the SCTP packet that held the ASCONF Chunks.
3740 * To do this properly, we'll set the destination address of the chunk
3741 * and at the transmit time, will try look up the transport to use.
3742 * Since ASCONFs may be bundled, the correct transport may not be
3743 * created until we process the entire packet, thus this workaround.
3745 asconf_ack
->dest
= chunk
->source
;
3746 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(asconf_ack
));
3747 if (asoc
->new_transport
) {
3748 sctp_sf_heartbeat(ep
, asoc
, type
, asoc
->new_transport
, commands
);
3749 ((struct sctp_association
*)asoc
)->new_transport
= NULL
;
3752 return SCTP_DISPOSITION_CONSUME
;
3756 * ADDIP Section 4.3 General rules for address manipulation
3757 * When building TLV parameters for the ASCONF Chunk that will add or
3758 * delete IP addresses the D0 to D13 rules should be applied:
3760 enum sctp_disposition
sctp_sf_do_asconf_ack(struct net
*net
,
3761 const struct sctp_endpoint
*ep
,
3762 const struct sctp_association
*asoc
,
3763 const union sctp_subtype type
,
3765 struct sctp_cmd_seq
*commands
)
3767 struct sctp_chunk
*last_asconf
= asoc
->addip_last_asconf
;
3768 struct sctp_paramhdr
*err_param
= NULL
;
3769 struct sctp_chunk
*asconf_ack
= arg
;
3770 struct sctp_addiphdr
*addip_hdr
;
3771 __u32 sent_serial
, rcvd_serial
;
3772 struct sctp_chunk
*abort
;
3774 if (!sctp_vtag_verify(asconf_ack
, asoc
)) {
3775 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3777 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3780 /* ADD-IP, Section 4.1.2:
3781 * This chunk MUST be sent in an authenticated way by using
3782 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3783 * is received unauthenticated it MUST be silently discarded as
3784 * described in [I-D.ietf-tsvwg-sctp-auth].
3786 if (!net
->sctp
.addip_noauth
&& !asconf_ack
->auth
)
3787 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
,
3790 /* Make sure that the ADDIP chunk has a valid length. */
3791 if (!sctp_chunk_length_valid(asconf_ack
,
3792 sizeof(struct sctp_addip_chunk
)))
3793 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3796 addip_hdr
= (struct sctp_addiphdr
*)asconf_ack
->skb
->data
;
3797 rcvd_serial
= ntohl(addip_hdr
->serial
);
3799 /* Verify the ASCONF-ACK chunk before processing it. */
3800 if (!sctp_verify_asconf(asoc
, asconf_ack
, false, &err_param
))
3801 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3802 (void *)err_param
, commands
);
3805 addip_hdr
= (struct sctp_addiphdr
*)last_asconf
->subh
.addip_hdr
;
3806 sent_serial
= ntohl(addip_hdr
->serial
);
3808 sent_serial
= asoc
->addip_serial
- 1;
3811 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3812 * equal to the next serial number to be used but no ASCONF chunk is
3813 * outstanding the endpoint MUST ABORT the association. Note that a
3814 * sequence number is greater than if it is no more than 2^^31-1
3815 * larger than the current sequence number (using serial arithmetic).
3817 if (ADDIP_SERIAL_gte(rcvd_serial
, sent_serial
+ 1) &&
3818 !(asoc
->addip_last_asconf
)) {
3819 abort
= sctp_make_abort(asoc
, asconf_ack
,
3820 sizeof(struct sctp_errhdr
));
3822 sctp_init_cause(abort
, SCTP_ERROR_ASCONF_ACK
, 0);
3823 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3826 /* We are going to ABORT, so we might as well stop
3827 * processing the rest of the chunks in the packet.
3829 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3830 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3831 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
3832 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3833 SCTP_ERROR(ECONNABORTED
));
3834 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3835 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3836 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
3837 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3838 return SCTP_DISPOSITION_ABORT
;
3841 if ((rcvd_serial
== sent_serial
) && asoc
->addip_last_asconf
) {
3842 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3843 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3845 if (!sctp_process_asconf_ack((struct sctp_association
*)asoc
,
3847 /* Successfully processed ASCONF_ACK. We can
3848 * release the next asconf if we have one.
3850 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_NEXT_ASCONF
,
3852 return SCTP_DISPOSITION_CONSUME
;
3855 abort
= sctp_make_abort(asoc
, asconf_ack
,
3856 sizeof(struct sctp_errhdr
));
3858 sctp_init_cause(abort
, SCTP_ERROR_RSRC_LOW
, 0);
3859 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3862 /* We are going to ABORT, so we might as well stop
3863 * processing the rest of the chunks in the packet.
3865 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
3866 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3867 SCTP_ERROR(ECONNABORTED
));
3868 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3869 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3870 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
3871 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3872 return SCTP_DISPOSITION_ABORT
;
3875 return SCTP_DISPOSITION_DISCARD
;
3878 /* RE-CONFIG Section 5.2 Upon reception of an RECONF Chunk. */
3879 enum sctp_disposition
sctp_sf_do_reconf(struct net
*net
,
3880 const struct sctp_endpoint
*ep
,
3881 const struct sctp_association
*asoc
,
3882 const union sctp_subtype type
,
3884 struct sctp_cmd_seq
*commands
)
3886 struct sctp_paramhdr
*err_param
= NULL
;
3887 struct sctp_chunk
*chunk
= arg
;
3888 struct sctp_reconf_chunk
*hdr
;
3889 union sctp_params param
;
3891 if (!sctp_vtag_verify(chunk
, asoc
)) {
3892 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3894 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3897 /* Make sure that the RECONF chunk has a valid length. */
3898 if (!sctp_chunk_length_valid(chunk
, sizeof(*hdr
)))
3899 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3902 if (!sctp_verify_reconf(asoc
, chunk
, &err_param
))
3903 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3904 (void *)err_param
, commands
);
3906 hdr
= (struct sctp_reconf_chunk
*)chunk
->chunk_hdr
;
3907 sctp_walk_params(param
, hdr
, params
) {
3908 struct sctp_chunk
*reply
= NULL
;
3909 struct sctp_ulpevent
*ev
= NULL
;
3911 if (param
.p
->type
== SCTP_PARAM_RESET_OUT_REQUEST
)
3912 reply
= sctp_process_strreset_outreq(
3913 (struct sctp_association
*)asoc
, param
, &ev
);
3914 else if (param
.p
->type
== SCTP_PARAM_RESET_IN_REQUEST
)
3915 reply
= sctp_process_strreset_inreq(
3916 (struct sctp_association
*)asoc
, param
, &ev
);
3917 else if (param
.p
->type
== SCTP_PARAM_RESET_TSN_REQUEST
)
3918 reply
= sctp_process_strreset_tsnreq(
3919 (struct sctp_association
*)asoc
, param
, &ev
);
3920 else if (param
.p
->type
== SCTP_PARAM_RESET_ADD_OUT_STREAMS
)
3921 reply
= sctp_process_strreset_addstrm_out(
3922 (struct sctp_association
*)asoc
, param
, &ev
);
3923 else if (param
.p
->type
== SCTP_PARAM_RESET_ADD_IN_STREAMS
)
3924 reply
= sctp_process_strreset_addstrm_in(
3925 (struct sctp_association
*)asoc
, param
, &ev
);
3926 else if (param
.p
->type
== SCTP_PARAM_RESET_RESPONSE
)
3927 reply
= sctp_process_strreset_resp(
3928 (struct sctp_association
*)asoc
, param
, &ev
);
3931 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
3935 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3939 return SCTP_DISPOSITION_CONSUME
;
3943 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3945 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3946 * its cumulative TSN point to the value carried in the FORWARD TSN
3947 * chunk, and then MUST further advance its cumulative TSN point locally
3949 * After the above processing, the data receiver MUST stop reporting any
3950 * missing TSNs earlier than or equal to the new cumulative TSN point.
3952 * Verification Tag: 8.5 Verification Tag [Normal verification]
3954 * The return value is the disposition of the chunk.
3956 enum sctp_disposition
sctp_sf_eat_fwd_tsn(struct net
*net
,
3957 const struct sctp_endpoint
*ep
,
3958 const struct sctp_association
*asoc
,
3959 const union sctp_subtype type
,
3961 struct sctp_cmd_seq
*commands
)
3963 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3964 struct sctp_chunk
*chunk
= arg
;
3968 if (!sctp_vtag_verify(chunk
, asoc
)) {
3969 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3971 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3974 if (!asoc
->peer
.prsctp_capable
)
3975 return sctp_sf_unk_chunk(net
, ep
, asoc
, type
, arg
, commands
);
3977 /* Make sure that the FORWARD_TSN chunk has valid length. */
3978 if (!sctp_chunk_length_valid(chunk
, sctp_ftsnchk_len(&asoc
->stream
)))
3979 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3982 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3983 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3984 len
= ntohs(chunk
->chunk_hdr
->length
);
3985 len
-= sizeof(struct sctp_chunkhdr
);
3986 skb_pull(chunk
->skb
, len
);
3988 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3989 pr_debug("%s: TSN 0x%x\n", __func__
, tsn
);
3991 /* The TSN is too high--silently discard the chunk and count on it
3992 * getting retransmitted later.
3994 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3995 goto discard_noforce
;
3997 if (!asoc
->stream
.si
->validate_ftsn(chunk
))
3998 goto discard_noforce
;
4000 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
4001 if (len
> sctp_ftsnhdr_len(&asoc
->stream
))
4002 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
4005 /* Count this as receiving DATA. */
4006 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
]) {
4007 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
4008 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
4011 /* FIXME: For now send a SACK, but DATA processing may
4014 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
4016 return SCTP_DISPOSITION_CONSUME
;
4019 return SCTP_DISPOSITION_DISCARD
;
4022 enum sctp_disposition
sctp_sf_eat_fwd_tsn_fast(
4024 const struct sctp_endpoint
*ep
,
4025 const struct sctp_association
*asoc
,
4026 const union sctp_subtype type
,
4028 struct sctp_cmd_seq
*commands
)
4030 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
4031 struct sctp_chunk
*chunk
= arg
;
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
, sctp_ftsnchk_len(&asoc
->stream
)))
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 if (!asoc
->stream
.si
->validate_ftsn(chunk
))
4067 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
4068 if (len
> sctp_ftsnhdr_len(&asoc
->stream
))
4069 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
4072 /* Go a head and force a SACK, since we are shutting down. */
4074 /* Implementor's Guide.
4076 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
4077 * respond to each received packet containing one or more DATA chunk(s)
4078 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
4080 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
4081 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
4082 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
4083 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
4085 return SCTP_DISPOSITION_CONSUME
;
4089 * SCTP-AUTH Section 6.3 Receiving authenticated chukns
4091 * The receiver MUST use the HMAC algorithm indicated in the HMAC
4092 * Identifier field. If this algorithm was not specified by the
4093 * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk
4094 * during association setup, the AUTH chunk and all chunks after it MUST
4095 * be discarded and an ERROR chunk SHOULD be sent with the error cause
4096 * defined in Section 4.1.
4098 * If an endpoint with no shared key receives a Shared Key Identifier
4099 * other than 0, it MUST silently discard all authenticated chunks. If
4100 * the endpoint has at least one endpoint pair shared key for the peer,
4101 * it MUST use the key specified by the Shared Key Identifier if a
4102 * key has been configured for that Shared Key Identifier. If no
4103 * endpoint pair shared key has been configured for that Shared Key
4104 * Identifier, all authenticated chunks MUST be silently discarded.
4106 * Verification Tag: 8.5 Verification Tag [Normal verification]
4108 * The return value is the disposition of the chunk.
4110 static enum sctp_ierror
sctp_sf_authenticate(
4112 const struct sctp_endpoint
*ep
,
4113 const struct sctp_association
*asoc
,
4114 const union sctp_subtype type
,
4115 struct sctp_chunk
*chunk
)
4117 struct sctp_authhdr
*auth_hdr
;
4118 __u8
*save_digest
, *digest
;
4119 struct sctp_hmac
*hmac
;
4120 unsigned int sig_len
;
4123 /* Pull in the auth header, so we can do some more verification */
4124 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
4125 chunk
->subh
.auth_hdr
= auth_hdr
;
4126 skb_pull(chunk
->skb
, sizeof(*auth_hdr
));
4128 /* Make sure that we support the HMAC algorithm from the auth
4131 if (!sctp_auth_asoc_verify_hmac_id(asoc
, auth_hdr
->hmac_id
))
4132 return SCTP_IERROR_AUTH_BAD_HMAC
;
4134 /* Make sure that the provided shared key identifier has been
4137 key_id
= ntohs(auth_hdr
->shkey_id
);
4138 if (key_id
!= asoc
->active_key_id
&& !sctp_auth_get_shkey(asoc
, key_id
))
4139 return SCTP_IERROR_AUTH_BAD_KEYID
;
4142 /* Make sure that the length of the signature matches what
4145 sig_len
= ntohs(chunk
->chunk_hdr
->length
) -
4146 sizeof(struct sctp_auth_chunk
);
4147 hmac
= sctp_auth_get_hmac(ntohs(auth_hdr
->hmac_id
));
4148 if (sig_len
!= hmac
->hmac_len
)
4149 return SCTP_IERROR_PROTO_VIOLATION
;
4151 /* Now that we've done validation checks, we can compute and
4152 * verify the hmac. The steps involved are:
4153 * 1. Save the digest from the chunk.
4154 * 2. Zero out the digest in the chunk.
4155 * 3. Compute the new digest
4156 * 4. Compare saved and new digests.
4158 digest
= auth_hdr
->hmac
;
4159 skb_pull(chunk
->skb
, sig_len
);
4161 save_digest
= kmemdup(digest
, sig_len
, GFP_ATOMIC
);
4165 memset(digest
, 0, sig_len
);
4167 sctp_auth_calculate_hmac(asoc
, chunk
->skb
,
4168 (struct sctp_auth_chunk
*)chunk
->chunk_hdr
,
4171 /* Discard the packet if the digests do not match */
4172 if (memcmp(save_digest
, digest
, sig_len
)) {
4174 return SCTP_IERROR_BAD_SIG
;
4180 return SCTP_IERROR_NO_ERROR
;
4182 return SCTP_IERROR_NOMEM
;
4185 enum sctp_disposition
sctp_sf_eat_auth(struct net
*net
,
4186 const struct sctp_endpoint
*ep
,
4187 const struct sctp_association
*asoc
,
4188 const union sctp_subtype type
,
4189 void *arg
, struct sctp_cmd_seq
*commands
)
4191 struct sctp_chunk
*chunk
= arg
;
4192 struct sctp_authhdr
*auth_hdr
;
4193 struct sctp_chunk
*err_chunk
;
4194 enum sctp_ierror error
;
4196 /* Make sure that the peer has AUTH capable */
4197 if (!asoc
->peer
.auth_capable
)
4198 return sctp_sf_unk_chunk(net
, ep
, asoc
, type
, arg
, commands
);
4200 if (!sctp_vtag_verify(chunk
, asoc
)) {
4201 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
4203 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4206 /* Make sure that the AUTH chunk has valid length. */
4207 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_auth_chunk
)))
4208 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4211 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
4212 error
= sctp_sf_authenticate(net
, ep
, asoc
, type
, chunk
);
4214 case SCTP_IERROR_AUTH_BAD_HMAC
:
4215 /* Generate the ERROR chunk and discard the rest
4218 err_chunk
= sctp_make_op_error(asoc
, chunk
,
4219 SCTP_ERROR_UNSUP_HMAC
,
4223 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4224 SCTP_CHUNK(err_chunk
));
4227 case SCTP_IERROR_AUTH_BAD_KEYID
:
4228 case SCTP_IERROR_BAD_SIG
:
4229 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4231 case SCTP_IERROR_PROTO_VIOLATION
:
4232 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4235 case SCTP_IERROR_NOMEM
:
4236 return SCTP_DISPOSITION_NOMEM
;
4238 default: /* Prevent gcc warnings */
4242 if (asoc
->active_key_id
!= ntohs(auth_hdr
->shkey_id
)) {
4243 struct sctp_ulpevent
*ev
;
4245 ev
= sctp_ulpevent_make_authkey(asoc
, ntohs(auth_hdr
->shkey_id
),
4246 SCTP_AUTH_NEWKEY
, GFP_ATOMIC
);
4251 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
4255 return SCTP_DISPOSITION_CONSUME
;
4259 * Process an unknown chunk.
4261 * Section: 3.2. Also, 2.1 in the implementor's guide.
4263 * Chunk Types are encoded such that the highest-order two bits specify
4264 * the action that must be taken if the processing endpoint does not
4265 * recognize the Chunk Type.
4267 * 00 - Stop processing this SCTP packet and discard it, do not process
4268 * any further chunks within it.
4270 * 01 - Stop processing this SCTP packet and discard it, do not process
4271 * any further chunks within it, and report the unrecognized
4272 * chunk in an 'Unrecognized Chunk Type'.
4274 * 10 - Skip this chunk and continue processing.
4276 * 11 - Skip this chunk and continue processing, but report in an ERROR
4277 * Chunk using the 'Unrecognized Chunk Type' cause of error.
4279 * The return value is the disposition of the chunk.
4281 enum sctp_disposition
sctp_sf_unk_chunk(struct net
*net
,
4282 const struct sctp_endpoint
*ep
,
4283 const struct sctp_association
*asoc
,
4284 const union sctp_subtype type
,
4286 struct sctp_cmd_seq
*commands
)
4288 struct sctp_chunk
*unk_chunk
= arg
;
4289 struct sctp_chunk
*err_chunk
;
4290 struct sctp_chunkhdr
*hdr
;
4292 pr_debug("%s: processing unknown chunk id:%d\n", __func__
, type
.chunk
);
4294 if (!sctp_vtag_verify(unk_chunk
, asoc
))
4295 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4297 /* Make sure that the chunk has a valid length.
4298 * Since we don't know the chunk type, we use a general
4299 * chunkhdr structure to make a comparison.
4301 if (!sctp_chunk_length_valid(unk_chunk
, sizeof(*hdr
)))
4302 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4305 switch (type
.chunk
& SCTP_CID_ACTION_MASK
) {
4306 case SCTP_CID_ACTION_DISCARD
:
4307 /* Discard the packet. */
4308 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4309 case SCTP_CID_ACTION_DISCARD_ERR
:
4310 /* Generate an ERROR chunk as response. */
4311 hdr
= unk_chunk
->chunk_hdr
;
4312 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4313 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4314 SCTP_PAD4(ntohs(hdr
->length
)),
4317 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4318 SCTP_CHUNK(err_chunk
));
4321 /* Discard the packet. */
4322 sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4323 return SCTP_DISPOSITION_CONSUME
;
4324 case SCTP_CID_ACTION_SKIP
:
4325 /* Skip the chunk. */
4326 return SCTP_DISPOSITION_DISCARD
;
4327 case SCTP_CID_ACTION_SKIP_ERR
:
4328 /* Generate an ERROR chunk as response. */
4329 hdr
= unk_chunk
->chunk_hdr
;
4330 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4331 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4332 SCTP_PAD4(ntohs(hdr
->length
)),
4335 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4336 SCTP_CHUNK(err_chunk
));
4338 /* Skip the chunk. */
4339 return SCTP_DISPOSITION_CONSUME
;
4344 return SCTP_DISPOSITION_DISCARD
;
4348 * Discard the chunk.
4350 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
4351 * [Too numerous to mention...]
4352 * Verification Tag: No verification needed.
4354 * (endpoint, asoc, chunk)
4357 * (asoc, reply_msg, msg_up, timers, counters)
4359 * The return value is the disposition of the chunk.
4361 enum sctp_disposition
sctp_sf_discard_chunk(struct net
*net
,
4362 const struct sctp_endpoint
*ep
,
4363 const struct sctp_association
*asoc
,
4364 const union sctp_subtype type
,
4366 struct sctp_cmd_seq
*commands
)
4368 struct sctp_chunk
*chunk
= arg
;
4370 /* Make sure that the chunk has a valid length.
4371 * Since we don't know the chunk type, we use a general
4372 * chunkhdr structure to make a comparison.
4374 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
4375 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4378 pr_debug("%s: chunk:%d is discarded\n", __func__
, type
.chunk
);
4380 return SCTP_DISPOSITION_DISCARD
;
4384 * Discard the whole packet.
4388 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
4389 * silently discard the OOTB packet and take no further action.
4391 * Verification Tag: No verification necessary
4394 * (endpoint, asoc, chunk)
4397 * (asoc, reply_msg, msg_up, timers, counters)
4399 * The return value is the disposition of the chunk.
4401 enum sctp_disposition
sctp_sf_pdiscard(struct net
*net
,
4402 const struct sctp_endpoint
*ep
,
4403 const struct sctp_association
*asoc
,
4404 const union sctp_subtype type
,
4405 void *arg
, struct sctp_cmd_seq
*commands
)
4407 SCTP_INC_STATS(net
, SCTP_MIB_IN_PKT_DISCARDS
);
4408 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
4410 return SCTP_DISPOSITION_CONSUME
;
4415 * The other end is violating protocol.
4417 * Section: Not specified
4418 * Verification Tag: Not specified
4420 * (endpoint, asoc, chunk)
4423 * (asoc, reply_msg, msg_up, timers, counters)
4425 * We simply tag the chunk as a violation. The state machine will log
4426 * the violation and continue.
4428 enum sctp_disposition
sctp_sf_violation(struct net
*net
,
4429 const struct sctp_endpoint
*ep
,
4430 const struct sctp_association
*asoc
,
4431 const union sctp_subtype type
,
4433 struct sctp_cmd_seq
*commands
)
4435 struct sctp_chunk
*chunk
= arg
;
4437 /* Make sure that the chunk has a valid length. */
4438 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
4439 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4442 return SCTP_DISPOSITION_VIOLATION
;
4446 * Common function to handle a protocol violation.
4448 static enum sctp_disposition
sctp_sf_abort_violation(
4450 const struct sctp_endpoint
*ep
,
4451 const struct sctp_association
*asoc
,
4453 struct sctp_cmd_seq
*commands
,
4454 const __u8
*payload
,
4455 const size_t paylen
)
4457 struct sctp_packet
*packet
= NULL
;
4458 struct sctp_chunk
*chunk
= arg
;
4459 struct sctp_chunk
*abort
= NULL
;
4461 /* SCTP-AUTH, Section 6.3:
4462 * It should be noted that if the receiver wants to tear
4463 * down an association in an authenticated way only, the
4464 * handling of malformed packets should not result in
4465 * tearing down the association.
4467 * This means that if we only want to abort associations
4468 * in an authenticated way (i.e AUTH+ABORT), then we
4469 * can't destroy this association just because the packet
4472 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4475 /* Make the abort chunk. */
4476 abort
= sctp_make_abort_violation(asoc
, chunk
, payload
, paylen
);
4481 /* Treat INIT-ACK as a special case during COOKIE-WAIT. */
4482 if (chunk
->chunk_hdr
->type
== SCTP_CID_INIT_ACK
&&
4483 !asoc
->peer
.i
.init_tag
) {
4484 struct sctp_initack_chunk
*initack
;
4486 initack
= (struct sctp_initack_chunk
*)chunk
->chunk_hdr
;
4487 if (!sctp_chunk_length_valid(chunk
, sizeof(*initack
)))
4488 abort
->chunk_hdr
->flags
|= SCTP_CHUNK_FLAG_T
;
4490 unsigned int inittag
;
4492 inittag
= ntohl(initack
->init_hdr
.init_tag
);
4493 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_INITTAG
,
4498 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4499 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4501 if (asoc
->state
<= SCTP_STATE_COOKIE_ECHOED
) {
4502 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4503 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4504 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4505 SCTP_ERROR(ECONNREFUSED
));
4506 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4507 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4509 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4510 SCTP_ERROR(ECONNABORTED
));
4511 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4512 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4513 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4516 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
4521 if (sctp_test_T_bit(abort
))
4522 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
4524 abort
->skb
->sk
= ep
->base
.sk
;
4526 sctp_packet_append_chunk(packet
, abort
);
4528 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
4529 SCTP_PACKET(packet
));
4531 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4534 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4537 sctp_sf_pdiscard(net
, ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4538 return SCTP_DISPOSITION_ABORT
;
4541 sctp_chunk_free(abort
);
4543 return SCTP_DISPOSITION_NOMEM
;
4547 * Handle a protocol violation when the chunk length is invalid.
4548 * "Invalid" length is identified as smaller than the minimal length a
4549 * given chunk can be. For example, a SACK chunk has invalid length
4550 * if its length is set to be smaller than the size of struct sctp_sack_chunk.
4552 * We inform the other end by sending an ABORT with a Protocol Violation
4555 * Section: Not specified
4556 * Verification Tag: Nothing to do
4558 * (endpoint, asoc, chunk)
4561 * (reply_msg, msg_up, counters)
4563 * Generate an ABORT chunk and terminate the association.
4565 static enum sctp_disposition
sctp_sf_violation_chunklen(
4567 const struct sctp_endpoint
*ep
,
4568 const struct sctp_association
*asoc
,
4569 const union sctp_subtype type
,
4571 struct sctp_cmd_seq
*commands
)
4573 static const char err_str
[] = "The following chunk had invalid length:";
4575 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4580 * Handle a protocol violation when the parameter length is invalid.
4581 * If the length is smaller than the minimum length of a given parameter,
4582 * or accumulated length in multi parameters exceeds the end of the chunk,
4583 * the length is considered as invalid.
4585 static enum sctp_disposition
sctp_sf_violation_paramlen(
4587 const struct sctp_endpoint
*ep
,
4588 const struct sctp_association
*asoc
,
4589 const union sctp_subtype type
,
4590 void *arg
, void *ext
,
4591 struct sctp_cmd_seq
*commands
)
4593 struct sctp_paramhdr
*param
= ext
;
4594 struct sctp_chunk
*abort
= NULL
;
4595 struct sctp_chunk
*chunk
= arg
;
4597 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4600 /* Make the abort chunk. */
4601 abort
= sctp_make_violation_paramlen(asoc
, chunk
, param
);
4605 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4606 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4608 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4609 SCTP_ERROR(ECONNABORTED
));
4610 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4611 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4612 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4613 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4616 sctp_sf_pdiscard(net
, ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4617 return SCTP_DISPOSITION_ABORT
;
4619 return SCTP_DISPOSITION_NOMEM
;
4622 /* Handle a protocol violation when the peer trying to advance the
4623 * cumulative tsn ack to a point beyond the max tsn currently sent.
4625 * We inform the other end by sending an ABORT with a Protocol Violation
4628 static enum sctp_disposition
sctp_sf_violation_ctsn(
4630 const struct sctp_endpoint
*ep
,
4631 const struct sctp_association
*asoc
,
4632 const union sctp_subtype type
,
4634 struct sctp_cmd_seq
*commands
)
4636 static const char err_str
[] = "The cumulative tsn ack beyond the max tsn currently sent:";
4638 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4642 /* Handle protocol violation of an invalid chunk bundling. For example,
4643 * when we have an association and we receive bundled INIT-ACK, or
4644 * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle"
4645 * statement from the specs. Additionally, there might be an attacker
4646 * on the path and we may not want to continue this communication.
4648 static enum sctp_disposition
sctp_sf_violation_chunk(
4650 const struct sctp_endpoint
*ep
,
4651 const struct sctp_association
*asoc
,
4652 const union sctp_subtype type
,
4654 struct sctp_cmd_seq
*commands
)
4656 static const char err_str
[] = "The following chunk violates protocol:";
4659 return sctp_sf_violation(net
, ep
, asoc
, type
, arg
, commands
);
4661 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4664 /***************************************************************************
4665 * These are the state functions for handling primitive (Section 10) events.
4666 ***************************************************************************/
4668 * sctp_sf_do_prm_asoc
4670 * Section: 10.1 ULP-to-SCTP
4673 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
4674 * outbound stream count)
4675 * -> association id [,destination transport addr list] [,outbound stream
4678 * This primitive allows the upper layer to initiate an association to a
4679 * specific peer endpoint.
4681 * The peer endpoint shall be specified by one of the transport addresses
4682 * which defines the endpoint (see Section 1.4). If the local SCTP
4683 * instance has not been initialized, the ASSOCIATE is considered an
4685 * [This is not relevant for the kernel implementation since we do all
4686 * initialization at boot time. It we hadn't initialized we wouldn't
4687 * get anywhere near this code.]
4689 * An association id, which is a local handle to the SCTP association,
4690 * will be returned on successful establishment of the association. If
4691 * SCTP is not able to open an SCTP association with the peer endpoint,
4692 * an error is returned.
4693 * [In the kernel implementation, the struct sctp_association needs to
4694 * be created BEFORE causing this primitive to run.]
4696 * Other association parameters may be returned, including the
4697 * complete destination transport addresses of the peer as well as the
4698 * outbound stream count of the local endpoint. One of the transport
4699 * address from the returned destination addresses will be selected by
4700 * the local endpoint as default primary path for sending SCTP packets
4701 * to this peer. The returned "destination transport addr list" can
4702 * be used by the ULP to change the default primary path or to force
4703 * sending a packet to a specific transport address. [All of this
4704 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
4707 * Mandatory attributes:
4709 * o local SCTP instance name - obtained from the INITIALIZE operation.
4710 * [This is the argument asoc.]
4711 * o destination transport addr - specified as one of the transport
4712 * addresses of the peer endpoint with which the association is to be
4714 * [This is asoc->peer.active_path.]
4715 * o outbound stream count - the number of outbound streams the ULP
4716 * would like to open towards this peer endpoint.
4717 * [BUG: This is not currently implemented.]
4718 * Optional attributes:
4722 * The return value is a disposition.
4724 enum sctp_disposition
sctp_sf_do_prm_asoc(struct net
*net
,
4725 const struct sctp_endpoint
*ep
,
4726 const struct sctp_association
*asoc
,
4727 const union sctp_subtype type
,
4729 struct sctp_cmd_seq
*commands
)
4731 struct sctp_association
*my_asoc
;
4732 struct sctp_chunk
*repl
;
4734 /* The comment below says that we enter COOKIE-WAIT AFTER
4735 * sending the INIT, but that doesn't actually work in our
4738 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4739 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
4741 /* RFC 2960 5.1 Normal Establishment of an Association
4743 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
4744 * must provide its Verification Tag (Tag_A) in the Initiate
4745 * Tag field. Tag_A SHOULD be a random number in the range of
4746 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
4749 repl
= sctp_make_init(asoc
, &asoc
->base
.bind_addr
, GFP_ATOMIC
, 0);
4753 /* Choose transport for INIT. */
4754 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
4757 /* Cast away the const modifier, as we want to just
4758 * rerun it through as a sideffect.
4760 my_asoc
= (struct sctp_association
*)asoc
;
4761 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(my_asoc
));
4763 /* After sending the INIT, "A" starts the T1-init timer and
4764 * enters the COOKIE-WAIT state.
4766 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4767 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4768 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
4769 return SCTP_DISPOSITION_CONSUME
;
4772 return SCTP_DISPOSITION_NOMEM
;
4776 * Process the SEND primitive.
4778 * Section: 10.1 ULP-to-SCTP
4781 * Format: SEND(association id, buffer address, byte count [,context]
4782 * [,stream id] [,life time] [,destination transport address]
4783 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
4786 * This is the main method to send user data via SCTP.
4788 * Mandatory attributes:
4790 * o association id - local handle to the SCTP association
4792 * o buffer address - the location where the user message to be
4793 * transmitted is stored;
4795 * o byte count - The size of the user data in number of bytes;
4797 * Optional attributes:
4799 * o context - an optional 32 bit integer that will be carried in the
4800 * sending failure notification to the ULP if the transportation of
4801 * this User Message fails.
4803 * o stream id - to indicate which stream to send the data on. If not
4804 * specified, stream 0 will be used.
4806 * o life time - specifies the life time of the user data. The user data
4807 * will not be sent by SCTP after the life time expires. This
4808 * parameter can be used to avoid efforts to transmit stale
4809 * user messages. SCTP notifies the ULP if the data cannot be
4810 * initiated to transport (i.e. sent to the destination via SCTP's
4811 * send primitive) within the life time variable. However, the
4812 * user data will be transmitted if SCTP has attempted to transmit a
4813 * chunk before the life time expired.
4815 * o destination transport address - specified as one of the destination
4816 * transport addresses of the peer endpoint to which this packet
4817 * should be sent. Whenever possible, SCTP should use this destination
4818 * transport address for sending the packets, instead of the current
4821 * o unorder flag - this flag, if present, indicates that the user
4822 * would like the data delivered in an unordered fashion to the peer
4823 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
4826 * o no-bundle flag - instructs SCTP not to bundle this user data with
4827 * other outbound DATA chunks. SCTP MAY still bundle even when
4828 * this flag is present, when faced with network congestion.
4830 * o payload protocol-id - A 32 bit unsigned integer that is to be
4831 * passed to the peer indicating the type of payload protocol data
4832 * being transmitted. This value is passed as opaque data by SCTP.
4834 * The return value is the disposition.
4836 enum sctp_disposition
sctp_sf_do_prm_send(struct net
*net
,
4837 const struct sctp_endpoint
*ep
,
4838 const struct sctp_association
*asoc
,
4839 const union sctp_subtype type
,
4841 struct sctp_cmd_seq
*commands
)
4843 struct sctp_datamsg
*msg
= arg
;
4845 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_MSG
, SCTP_DATAMSG(msg
));
4846 return SCTP_DISPOSITION_CONSUME
;
4850 * Process the SHUTDOWN primitive.
4855 * Format: SHUTDOWN(association id)
4858 * Gracefully closes an association. Any locally queued user data
4859 * will be delivered to the peer. The association will be terminated only
4860 * after the peer acknowledges all the SCTP packets sent. A success code
4861 * will be returned on successful termination of the association. If
4862 * attempting to terminate the association results in a failure, an error
4863 * code shall be returned.
4865 * Mandatory attributes:
4867 * o association id - local handle to the SCTP association
4869 * Optional attributes:
4873 * The return value is the disposition.
4875 enum sctp_disposition
sctp_sf_do_9_2_prm_shutdown(
4877 const struct sctp_endpoint
*ep
,
4878 const struct sctp_association
*asoc
,
4879 const union sctp_subtype type
,
4881 struct sctp_cmd_seq
*commands
)
4883 enum sctp_disposition disposition
;
4885 /* From 9.2 Shutdown of an Association
4886 * Upon receipt of the SHUTDOWN primitive from its upper
4887 * layer, the endpoint enters SHUTDOWN-PENDING state and
4888 * remains there until all outstanding data has been
4889 * acknowledged by its peer. The endpoint accepts no new data
4890 * from its upper layer, but retransmits data to the far end
4891 * if necessary to fill gaps.
4893 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4894 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
4896 disposition
= SCTP_DISPOSITION_CONSUME
;
4897 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
4898 disposition
= sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
, type
,
4906 * Process the ABORT primitive.
4911 * Format: Abort(association id [, cause code])
4914 * Ungracefully closes an association. Any locally queued user data
4915 * will be discarded and an ABORT chunk is sent to the peer. A success code
4916 * will be returned on successful abortion of the association. If
4917 * attempting to abort the association results in a failure, an error
4918 * code shall be returned.
4920 * Mandatory attributes:
4922 * o association id - local handle to the SCTP association
4924 * Optional attributes:
4926 * o cause code - reason of the abort to be passed to the peer
4930 * The return value is the disposition.
4932 enum sctp_disposition
sctp_sf_do_9_1_prm_abort(
4934 const struct sctp_endpoint
*ep
,
4935 const struct sctp_association
*asoc
,
4936 const union sctp_subtype type
,
4938 struct sctp_cmd_seq
*commands
)
4940 /* From 9.1 Abort of an Association
4941 * Upon receipt of the ABORT primitive from its upper
4942 * layer, the endpoint enters CLOSED state and
4943 * discard all outstanding data has been
4944 * acknowledged by its peer. The endpoint accepts no new data
4945 * from its upper layer, but retransmits data to the far end
4946 * if necessary to fill gaps.
4948 struct sctp_chunk
*abort
= arg
;
4951 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4953 /* Even if we can't send the ABORT due to low memory delete the
4954 * TCB. This is a departure from our typical NOMEM handling.
4957 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4958 SCTP_ERROR(ECONNABORTED
));
4959 /* Delete the established association. */
4960 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4961 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4963 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4964 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4966 return SCTP_DISPOSITION_ABORT
;
4969 /* We tried an illegal operation on an association which is closed. */
4970 enum sctp_disposition
sctp_sf_error_closed(struct net
*net
,
4971 const struct sctp_endpoint
*ep
,
4972 const struct sctp_association
*asoc
,
4973 const union sctp_subtype type
,
4975 struct sctp_cmd_seq
*commands
)
4977 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
, SCTP_ERROR(-EINVAL
));
4978 return SCTP_DISPOSITION_CONSUME
;
4981 /* We tried an illegal operation on an association which is shutting
4984 enum sctp_disposition
sctp_sf_error_shutdown(
4986 const struct sctp_endpoint
*ep
,
4987 const struct sctp_association
*asoc
,
4988 const union sctp_subtype type
,
4990 struct sctp_cmd_seq
*commands
)
4992 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
,
4993 SCTP_ERROR(-ESHUTDOWN
));
4994 return SCTP_DISPOSITION_CONSUME
;
4998 * sctp_cookie_wait_prm_shutdown
5000 * Section: 4 Note: 2
5005 * The RFC does not explicitly address this issue, but is the route through the
5006 * state table when someone issues a shutdown while in COOKIE_WAIT state.
5011 enum sctp_disposition
sctp_sf_cookie_wait_prm_shutdown(
5013 const struct sctp_endpoint
*ep
,
5014 const struct sctp_association
*asoc
,
5015 const union sctp_subtype type
,
5017 struct sctp_cmd_seq
*commands
)
5019 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5020 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5022 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5023 SCTP_STATE(SCTP_STATE_CLOSED
));
5025 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
5027 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
5029 return SCTP_DISPOSITION_DELETE_TCB
;
5033 * sctp_cookie_echoed_prm_shutdown
5035 * Section: 4 Note: 2
5040 * The RFC does not explcitly address this issue, but is the route through the
5041 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
5046 enum sctp_disposition
sctp_sf_cookie_echoed_prm_shutdown(
5048 const struct sctp_endpoint
*ep
,
5049 const struct sctp_association
*asoc
,
5050 const union sctp_subtype type
,
5052 struct sctp_cmd_seq
*commands
)
5054 /* There is a single T1 timer, so we should be able to use
5055 * common function with the COOKIE-WAIT state.
5057 return sctp_sf_cookie_wait_prm_shutdown(net
, ep
, asoc
, type
, arg
, commands
);
5061 * sctp_sf_cookie_wait_prm_abort
5063 * Section: 4 Note: 2
5068 * The RFC does not explicitly address this issue, but is the route through the
5069 * state table when someone issues an abort while in COOKIE_WAIT state.
5074 enum sctp_disposition
sctp_sf_cookie_wait_prm_abort(
5076 const struct sctp_endpoint
*ep
,
5077 const struct sctp_association
*asoc
,
5078 const union sctp_subtype type
,
5080 struct sctp_cmd_seq
*commands
)
5082 struct sctp_chunk
*abort
= arg
;
5084 /* Stop T1-init timer */
5085 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5086 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5089 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
5091 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5092 SCTP_STATE(SCTP_STATE_CLOSED
));
5094 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5096 /* Even if we can't send the ABORT due to low memory delete the
5097 * TCB. This is a departure from our typical NOMEM handling.
5100 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5101 SCTP_ERROR(ECONNREFUSED
));
5102 /* Delete the established association. */
5103 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5104 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
5106 return SCTP_DISPOSITION_ABORT
;
5110 * sctp_sf_cookie_echoed_prm_abort
5112 * Section: 4 Note: 3
5117 * The RFC does not explcitly address this issue, but is the route through the
5118 * state table when someone issues an abort while in COOKIE_ECHOED state.
5123 enum sctp_disposition
sctp_sf_cookie_echoed_prm_abort(
5125 const struct sctp_endpoint
*ep
,
5126 const struct sctp_association
*asoc
,
5127 const union sctp_subtype type
,
5129 struct sctp_cmd_seq
*commands
)
5131 /* There is a single T1 timer, so we should be able to use
5132 * common function with the COOKIE-WAIT state.
5134 return sctp_sf_cookie_wait_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5138 * sctp_sf_shutdown_pending_prm_abort
5143 * The RFC does not explicitly address this issue, but is the route through the
5144 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
5149 enum sctp_disposition
sctp_sf_shutdown_pending_prm_abort(
5151 const struct sctp_endpoint
*ep
,
5152 const struct sctp_association
*asoc
,
5153 const union sctp_subtype type
,
5155 struct sctp_cmd_seq
*commands
)
5157 /* Stop the T5-shutdown guard timer. */
5158 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5159 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5161 return sctp_sf_do_9_1_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5165 * sctp_sf_shutdown_sent_prm_abort
5170 * The RFC does not explicitly address this issue, but is the route through the
5171 * state table when someone issues an abort while in SHUTDOWN-SENT state.
5176 enum sctp_disposition
sctp_sf_shutdown_sent_prm_abort(
5178 const struct sctp_endpoint
*ep
,
5179 const struct sctp_association
*asoc
,
5180 const union sctp_subtype type
,
5182 struct sctp_cmd_seq
*commands
)
5184 /* Stop the T2-shutdown timer. */
5185 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5186 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5188 /* Stop the T5-shutdown guard timer. */
5189 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5190 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5192 return sctp_sf_do_9_1_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5196 * sctp_sf_cookie_echoed_prm_abort
5201 * The RFC does not explcitly address this issue, but is the route through the
5202 * state table when someone issues an abort while in COOKIE_ECHOED state.
5207 enum sctp_disposition
sctp_sf_shutdown_ack_sent_prm_abort(
5209 const struct sctp_endpoint
*ep
,
5210 const struct sctp_association
*asoc
,
5211 const union sctp_subtype type
,
5213 struct sctp_cmd_seq
*commands
)
5215 /* The same T2 timer, so we should be able to use
5216 * common function with the SHUTDOWN-SENT state.
5218 return sctp_sf_shutdown_sent_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5222 * Process the REQUESTHEARTBEAT primitive
5225 * J) Request Heartbeat
5227 * Format: REQUESTHEARTBEAT(association id, destination transport address)
5231 * Instructs the local endpoint to perform a HeartBeat on the specified
5232 * destination transport address of the given association. The returned
5233 * result should indicate whether the transmission of the HEARTBEAT
5234 * chunk to the destination address is successful.
5236 * Mandatory attributes:
5238 * o association id - local handle to the SCTP association
5240 * o destination transport address - the transport address of the
5241 * association on which a heartbeat should be issued.
5243 enum sctp_disposition
sctp_sf_do_prm_requestheartbeat(
5245 const struct sctp_endpoint
*ep
,
5246 const struct sctp_association
*asoc
,
5247 const union sctp_subtype type
,
5249 struct sctp_cmd_seq
*commands
)
5251 if (SCTP_DISPOSITION_NOMEM
== sctp_sf_heartbeat(ep
, asoc
, type
,
5252 (struct sctp_transport
*)arg
, commands
))
5253 return SCTP_DISPOSITION_NOMEM
;
5256 * RFC 2960 (bis), section 8.3
5258 * D) Request an on-demand HEARTBEAT on a specific destination
5259 * transport address of a given association.
5261 * The endpoint should increment the respective error counter of
5262 * the destination transport address each time a HEARTBEAT is sent
5263 * to that address and not acknowledged within one RTO.
5266 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
5267 SCTP_TRANSPORT(arg
));
5268 return SCTP_DISPOSITION_CONSUME
;
5272 * ADDIP Section 4.1 ASCONF Chunk Procedures
5273 * When an endpoint has an ASCONF signaled change to be sent to the
5274 * remote endpoint it should do A1 to A9
5276 enum sctp_disposition
sctp_sf_do_prm_asconf(struct net
*net
,
5277 const struct sctp_endpoint
*ep
,
5278 const struct sctp_association
*asoc
,
5279 const union sctp_subtype type
,
5281 struct sctp_cmd_seq
*commands
)
5283 struct sctp_chunk
*chunk
= arg
;
5285 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5286 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5287 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5288 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
5289 return SCTP_DISPOSITION_CONSUME
;
5292 /* RE-CONFIG Section 5.1 RECONF Chunk Procedures */
5293 enum sctp_disposition
sctp_sf_do_prm_reconf(struct net
*net
,
5294 const struct sctp_endpoint
*ep
,
5295 const struct sctp_association
*asoc
,
5296 const union sctp_subtype type
,
5298 struct sctp_cmd_seq
*commands
)
5300 struct sctp_chunk
*chunk
= arg
;
5302 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
5303 return SCTP_DISPOSITION_CONSUME
;
5307 * Ignore the primitive event
5309 * The return value is the disposition of the primitive.
5311 enum sctp_disposition
sctp_sf_ignore_primitive(
5313 const struct sctp_endpoint
*ep
,
5314 const struct sctp_association
*asoc
,
5315 const union sctp_subtype type
,
5317 struct sctp_cmd_seq
*commands
)
5319 pr_debug("%s: primitive type:%d is ignored\n", __func__
,
5322 return SCTP_DISPOSITION_DISCARD
;
5325 /***************************************************************************
5326 * These are the state functions for the OTHER events.
5327 ***************************************************************************/
5330 * When the SCTP stack has no more user data to send or retransmit, this
5331 * notification is given to the user. Also, at the time when a user app
5332 * subscribes to this event, if there is no data to be sent or
5333 * retransmit, the stack will immediately send up this notification.
5335 enum sctp_disposition
sctp_sf_do_no_pending_tsn(
5337 const struct sctp_endpoint
*ep
,
5338 const struct sctp_association
*asoc
,
5339 const union sctp_subtype type
,
5341 struct sctp_cmd_seq
*commands
)
5343 struct sctp_ulpevent
*event
;
5345 event
= sctp_ulpevent_make_sender_dry_event(asoc
, GFP_ATOMIC
);
5347 return SCTP_DISPOSITION_NOMEM
;
5349 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(event
));
5351 return SCTP_DISPOSITION_CONSUME
;
5355 * Start the shutdown negotiation.
5358 * Once all its outstanding data has been acknowledged, the endpoint
5359 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
5360 * TSN Ack field the last sequential TSN it has received from the peer.
5361 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
5362 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
5363 * with the updated last sequential TSN received from its peer.
5365 * The return value is the disposition.
5367 enum sctp_disposition
sctp_sf_do_9_2_start_shutdown(
5369 const struct sctp_endpoint
*ep
,
5370 const struct sctp_association
*asoc
,
5371 const union sctp_subtype type
,
5373 struct sctp_cmd_seq
*commands
)
5375 struct sctp_chunk
*reply
;
5377 /* Once all its outstanding data has been acknowledged, the
5378 * endpoint shall send a SHUTDOWN chunk to its peer including
5379 * in the Cumulative TSN Ack field the last sequential TSN it
5380 * has received from the peer.
5382 reply
= sctp_make_shutdown(asoc
, NULL
);
5386 /* Set the transport for the SHUTDOWN chunk and the timeout for the
5387 * T2-shutdown timer.
5389 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5391 /* It shall then start the T2-shutdown timer */
5392 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5393 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5395 /* RFC 4960 Section 9.2
5396 * The sender of the SHUTDOWN MAY also start an overall guard timer
5397 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5399 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5400 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5402 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
5403 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5404 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5406 /* and enter the SHUTDOWN-SENT state. */
5407 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5408 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT
));
5410 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5412 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5415 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5417 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5419 return SCTP_DISPOSITION_CONSUME
;
5422 return SCTP_DISPOSITION_NOMEM
;
5426 * Generate a SHUTDOWN ACK now that everything is SACK'd.
5430 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5431 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
5432 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
5433 * endpoint must re-send the SHUTDOWN ACK.
5435 * The return value is the disposition.
5437 enum sctp_disposition
sctp_sf_do_9_2_shutdown_ack(
5439 const struct sctp_endpoint
*ep
,
5440 const struct sctp_association
*asoc
,
5441 const union sctp_subtype type
,
5443 struct sctp_cmd_seq
*commands
)
5445 struct sctp_chunk
*chunk
= arg
;
5446 struct sctp_chunk
*reply
;
5448 /* There are 2 ways of getting here:
5449 * 1) called in response to a SHUTDOWN chunk
5450 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
5452 * For the case (2), the arg parameter is set to NULL. We need
5453 * to check that we have a chunk before accessing it's fields.
5456 if (!sctp_vtag_verify(chunk
, asoc
))
5457 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
,
5460 /* Make sure that the SHUTDOWN chunk has a valid length. */
5461 if (!sctp_chunk_length_valid(
5462 chunk
, sizeof(struct sctp_shutdown_chunk
)))
5463 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
,
5467 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5468 * shall send a SHUTDOWN ACK ...
5470 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
5474 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
5475 * the T2-shutdown timer.
5477 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5479 /* and start/restart a T2-shutdown timer of its own, */
5480 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5481 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5483 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
5484 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5485 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5487 /* Enter the SHUTDOWN-ACK-SENT state. */
5488 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5489 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT
));
5491 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5493 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5496 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5498 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5500 return SCTP_DISPOSITION_CONSUME
;
5503 return SCTP_DISPOSITION_NOMEM
;
5507 * Ignore the event defined as other
5509 * The return value is the disposition of the event.
5511 enum sctp_disposition
sctp_sf_ignore_other(struct net
*net
,
5512 const struct sctp_endpoint
*ep
,
5513 const struct sctp_association
*asoc
,
5514 const union sctp_subtype type
,
5516 struct sctp_cmd_seq
*commands
)
5518 pr_debug("%s: the event other type:%d is ignored\n",
5519 __func__
, type
.other
);
5521 return SCTP_DISPOSITION_DISCARD
;
5524 /************************************************************
5525 * These are the state functions for handling timeout events.
5526 ************************************************************/
5531 * Section: 6.3.3 Handle T3-rtx Expiration
5533 * Whenever the retransmission timer T3-rtx expires for a destination
5534 * address, do the following:
5537 * The return value is the disposition of the chunk.
5539 enum sctp_disposition
sctp_sf_do_6_3_3_rtx(struct net
*net
,
5540 const struct sctp_endpoint
*ep
,
5541 const struct sctp_association
*asoc
,
5542 const union sctp_subtype type
,
5544 struct sctp_cmd_seq
*commands
)
5546 struct sctp_transport
*transport
= arg
;
5548 SCTP_INC_STATS(net
, SCTP_MIB_T3_RTX_EXPIREDS
);
5550 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5551 if (asoc
->peer
.zero_window_announced
&&
5552 asoc
->state
== SCTP_STATE_SHUTDOWN_PENDING
) {
5554 * We are here likely because the receiver had its rwnd
5555 * closed for a while and we have not been able to
5556 * transmit the locally queued data within the maximum
5557 * retransmission attempts limit. Start the T5
5558 * shutdown guard timer to give the receiver one last
5559 * chance and some additional time to recover before
5562 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START_ONCE
,
5563 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5565 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5566 SCTP_ERROR(ETIMEDOUT
));
5567 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5568 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5569 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5570 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5571 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5572 return SCTP_DISPOSITION_DELETE_TCB
;
5576 /* E1) For the destination address for which the timer
5577 * expires, adjust its ssthresh with rules defined in Section
5578 * 7.2.3 and set the cwnd <- MTU.
5581 /* E2) For the destination address for which the timer
5582 * expires, set RTO <- RTO * 2 ("back off the timer"). The
5583 * maximum value discussed in rule C7 above (RTO.max) may be
5584 * used to provide an upper bound to this doubling operation.
5587 /* E3) Determine how many of the earliest (i.e., lowest TSN)
5588 * outstanding DATA chunks for the address for which the
5589 * T3-rtx has expired will fit into a single packet, subject
5590 * to the MTU constraint for the path corresponding to the
5591 * destination transport address to which the retransmission
5592 * is being sent (this may be different from the address for
5593 * which the timer expires [see Section 6.4]). Call this
5594 * value K. Bundle and retransmit those K DATA chunks in a
5595 * single packet to the destination endpoint.
5597 * Note: Any DATA chunks that were sent to the address for
5598 * which the T3-rtx timer expired but did not fit in one MTU
5599 * (rule E3 above), should be marked for retransmission and
5600 * sent as soon as cwnd allows (normally when a SACK arrives).
5603 /* Do some failure management (Section 8.2). */
5604 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
5606 /* NB: Rules E4 and F1 are implicit in R1. */
5607 sctp_add_cmd_sf(commands
, SCTP_CMD_RETRAN
, SCTP_TRANSPORT(transport
));
5609 return SCTP_DISPOSITION_CONSUME
;
5613 * Generate delayed SACK on timeout
5615 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
5617 * The guidelines on delayed acknowledgement algorithm specified in
5618 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
5619 * acknowledgement SHOULD be generated for at least every second packet
5620 * (not every second DATA chunk) received, and SHOULD be generated
5621 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
5622 * some situations it may be beneficial for an SCTP transmitter to be
5623 * more conservative than the algorithms detailed in this document
5624 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
5625 * the following algorithms allow.
5627 enum sctp_disposition
sctp_sf_do_6_2_sack(struct net
*net
,
5628 const struct sctp_endpoint
*ep
,
5629 const struct sctp_association
*asoc
,
5630 const union sctp_subtype type
,
5632 struct sctp_cmd_seq
*commands
)
5634 SCTP_INC_STATS(net
, SCTP_MIB_DELAY_SACK_EXPIREDS
);
5635 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
5636 return SCTP_DISPOSITION_CONSUME
;
5640 * sctp_sf_t1_init_timer_expire
5642 * Section: 4 Note: 2
5647 * RFC 2960 Section 4 Notes
5648 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
5649 * and re-start the T1-init timer without changing state. This MUST
5650 * be repeated up to 'Max.Init.Retransmits' times. After that, the
5651 * endpoint MUST abort the initialization process and report the
5652 * error to SCTP user.
5658 enum sctp_disposition
sctp_sf_t1_init_timer_expire(
5660 const struct sctp_endpoint
*ep
,
5661 const struct sctp_association
*asoc
,
5662 const union sctp_subtype type
,
5664 struct sctp_cmd_seq
*commands
)
5666 int attempts
= asoc
->init_err_counter
+ 1;
5667 struct sctp_chunk
*repl
= NULL
;
5668 struct sctp_bind_addr
*bp
;
5670 pr_debug("%s: timer T1 expired (INIT)\n", __func__
);
5672 SCTP_INC_STATS(net
, SCTP_MIB_T1_INIT_EXPIREDS
);
5674 if (attempts
<= asoc
->max_init_attempts
) {
5675 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
5676 repl
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, 0);
5678 return SCTP_DISPOSITION_NOMEM
;
5680 /* Choose transport for INIT. */
5681 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5684 /* Issue a sideeffect to do the needed accounting. */
5685 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_RESTART
,
5686 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5688 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5690 pr_debug("%s: giving up on INIT, attempts:%d "
5691 "max_init_attempts:%d\n", __func__
, attempts
,
5692 asoc
->max_init_attempts
);
5694 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5695 SCTP_ERROR(ETIMEDOUT
));
5696 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5697 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5698 return SCTP_DISPOSITION_DELETE_TCB
;
5701 return SCTP_DISPOSITION_CONSUME
;
5705 * sctp_sf_t1_cookie_timer_expire
5707 * Section: 4 Note: 2
5712 * RFC 2960 Section 4 Notes
5713 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
5714 * COOKIE ECHO and re-start the T1-cookie timer without changing
5715 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
5716 * After that, the endpoint MUST abort the initialization process and
5717 * report the error to SCTP user.
5723 enum sctp_disposition
sctp_sf_t1_cookie_timer_expire(
5725 const struct sctp_endpoint
*ep
,
5726 const struct sctp_association
*asoc
,
5727 const union sctp_subtype type
,
5729 struct sctp_cmd_seq
*commands
)
5731 int attempts
= asoc
->init_err_counter
+ 1;
5732 struct sctp_chunk
*repl
= NULL
;
5734 pr_debug("%s: timer T1 expired (COOKIE-ECHO)\n", __func__
);
5736 SCTP_INC_STATS(net
, SCTP_MIB_T1_COOKIE_EXPIREDS
);
5738 if (attempts
<= asoc
->max_init_attempts
) {
5739 repl
= sctp_make_cookie_echo(asoc
, NULL
);
5741 return SCTP_DISPOSITION_NOMEM
;
5743 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5745 /* Issue a sideeffect to do the needed accounting. */
5746 sctp_add_cmd_sf(commands
, SCTP_CMD_COOKIEECHO_RESTART
,
5747 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
5749 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5751 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5752 SCTP_ERROR(ETIMEDOUT
));
5753 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5754 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5755 return SCTP_DISPOSITION_DELETE_TCB
;
5758 return SCTP_DISPOSITION_CONSUME
;
5761 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
5762 * with the updated last sequential TSN received from its peer.
5764 * An endpoint should limit the number of retransmissions of the
5765 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
5766 * If this threshold is exceeded the endpoint should destroy the TCB and
5767 * MUST report the peer endpoint unreachable to the upper layer (and
5768 * thus the association enters the CLOSED state). The reception of any
5769 * packet from its peer (i.e. as the peer sends all of its queued DATA
5770 * chunks) should clear the endpoint's retransmission count and restart
5771 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
5772 * all of its queued DATA chunks that have not yet been sent.
5774 enum sctp_disposition
sctp_sf_t2_timer_expire(
5776 const struct sctp_endpoint
*ep
,
5777 const struct sctp_association
*asoc
,
5778 const union sctp_subtype type
,
5780 struct sctp_cmd_seq
*commands
)
5782 struct sctp_chunk
*reply
= NULL
;
5784 pr_debug("%s: timer T2 expired\n", __func__
);
5786 SCTP_INC_STATS(net
, SCTP_MIB_T2_SHUTDOWN_EXPIREDS
);
5788 ((struct sctp_association
*)asoc
)->shutdown_retries
++;
5790 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5791 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5792 SCTP_ERROR(ETIMEDOUT
));
5793 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5794 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5795 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5796 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5797 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5798 return SCTP_DISPOSITION_DELETE_TCB
;
5801 switch (asoc
->state
) {
5802 case SCTP_STATE_SHUTDOWN_SENT
:
5803 reply
= sctp_make_shutdown(asoc
, NULL
);
5806 case SCTP_STATE_SHUTDOWN_ACK_SENT
:
5807 reply
= sctp_make_shutdown_ack(asoc
, NULL
);
5818 /* Do some failure management (Section 8.2).
5819 * If we remove the transport an SHUTDOWN was last sent to, don't
5820 * do failure management.
5822 if (asoc
->shutdown_last_sent_to
)
5823 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5824 SCTP_TRANSPORT(asoc
->shutdown_last_sent_to
));
5826 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
5827 * the T2-shutdown timer.
5829 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5831 /* Restart the T2-shutdown timer. */
5832 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5833 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5834 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5835 return SCTP_DISPOSITION_CONSUME
;
5838 return SCTP_DISPOSITION_NOMEM
;
5842 * ADDIP Section 4.1 ASCONF CHunk Procedures
5843 * If the T4 RTO timer expires the endpoint should do B1 to B5
5845 enum sctp_disposition
sctp_sf_t4_timer_expire(
5847 const struct sctp_endpoint
*ep
,
5848 const struct sctp_association
*asoc
,
5849 const union sctp_subtype type
,
5851 struct sctp_cmd_seq
*commands
)
5853 struct sctp_chunk
*chunk
= asoc
->addip_last_asconf
;
5854 struct sctp_transport
*transport
= chunk
->transport
;
5856 SCTP_INC_STATS(net
, SCTP_MIB_T4_RTO_EXPIREDS
);
5858 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
5859 * detection on the appropriate destination address as defined in
5860 * RFC2960 [5] section 8.1 and 8.2.
5863 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5864 SCTP_TRANSPORT(transport
));
5866 /* Reconfig T4 timer and transport. */
5867 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5869 /* ADDIP 4.1 B2) Increment the association error counters and perform
5870 * endpoint failure detection on the association as defined in
5871 * RFC2960 [5] section 8.1 and 8.2.
5872 * association error counter is incremented in SCTP_CMD_STRIKE.
5874 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5875 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5876 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5877 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5878 SCTP_ERROR(ETIMEDOUT
));
5879 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5880 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5881 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5882 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5883 return SCTP_DISPOSITION_ABORT
;
5886 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
5887 * the ASCONF chunk was sent by doubling the RTO timer value.
5888 * This is done in SCTP_CMD_STRIKE.
5891 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
5892 * choose an alternate destination address (please refer to RFC2960
5893 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
5894 * chunk, it MUST be the same (including its serial number) as the last
5897 sctp_chunk_hold(asoc
->addip_last_asconf
);
5898 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5899 SCTP_CHUNK(asoc
->addip_last_asconf
));
5901 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
5902 * destination is selected, then the RTO used will be that of the new
5903 * destination address.
5905 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5906 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5908 return SCTP_DISPOSITION_CONSUME
;
5911 /* sctpimpguide-05 Section 2.12.2
5912 * The sender of the SHUTDOWN MAY also start an overall guard timer
5913 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5914 * At the expiration of this timer the sender SHOULD abort the association
5915 * by sending an ABORT chunk.
5917 enum sctp_disposition
sctp_sf_t5_timer_expire(
5919 const struct sctp_endpoint
*ep
,
5920 const struct sctp_association
*asoc
,
5921 const union sctp_subtype type
,
5923 struct sctp_cmd_seq
*commands
)
5925 struct sctp_chunk
*reply
= NULL
;
5927 pr_debug("%s: timer T5 expired\n", __func__
);
5929 SCTP_INC_STATS(net
, SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS
);
5931 reply
= sctp_make_abort(asoc
, NULL
, 0);
5935 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5936 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5937 SCTP_ERROR(ETIMEDOUT
));
5938 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5939 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5941 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5942 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5944 return SCTP_DISPOSITION_DELETE_TCB
;
5946 return SCTP_DISPOSITION_NOMEM
;
5949 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
5950 * the association is automatically closed by starting the shutdown process.
5951 * The work that needs to be done is same as when SHUTDOWN is initiated by
5952 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
5954 enum sctp_disposition
sctp_sf_autoclose_timer_expire(
5956 const struct sctp_endpoint
*ep
,
5957 const struct sctp_association
*asoc
,
5958 const union sctp_subtype type
,
5960 struct sctp_cmd_seq
*commands
)
5962 enum sctp_disposition disposition
;
5964 SCTP_INC_STATS(net
, SCTP_MIB_AUTOCLOSE_EXPIREDS
);
5966 /* From 9.2 Shutdown of an Association
5967 * Upon receipt of the SHUTDOWN primitive from its upper
5968 * layer, the endpoint enters SHUTDOWN-PENDING state and
5969 * remains there until all outstanding data has been
5970 * acknowledged by its peer. The endpoint accepts no new data
5971 * from its upper layer, but retransmits data to the far end
5972 * if necessary to fill gaps.
5974 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5975 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
5977 disposition
= SCTP_DISPOSITION_CONSUME
;
5978 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
5979 disposition
= sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
, type
,
5986 /*****************************************************************************
5987 * These are sa state functions which could apply to all types of events.
5988 ****************************************************************************/
5991 * This table entry is not implemented.
5994 * (endpoint, asoc, chunk)
5996 * The return value is the disposition of the chunk.
5998 enum sctp_disposition
sctp_sf_not_impl(struct net
*net
,
5999 const struct sctp_endpoint
*ep
,
6000 const struct sctp_association
*asoc
,
6001 const union sctp_subtype type
,
6002 void *arg
, struct sctp_cmd_seq
*commands
)
6004 return SCTP_DISPOSITION_NOT_IMPL
;
6008 * This table entry represents a bug.
6011 * (endpoint, asoc, chunk)
6013 * The return value is the disposition of the chunk.
6015 enum sctp_disposition
sctp_sf_bug(struct net
*net
,
6016 const struct sctp_endpoint
*ep
,
6017 const struct sctp_association
*asoc
,
6018 const union sctp_subtype type
,
6019 void *arg
, struct sctp_cmd_seq
*commands
)
6021 return SCTP_DISPOSITION_BUG
;
6025 * This table entry represents the firing of a timer in the wrong state.
6026 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
6027 * when the association is in the wrong state. This event should
6028 * be ignored, so as to prevent any rearming of the timer.
6031 * (endpoint, asoc, chunk)
6033 * The return value is the disposition of the chunk.
6035 enum sctp_disposition
sctp_sf_timer_ignore(struct net
*net
,
6036 const struct sctp_endpoint
*ep
,
6037 const struct sctp_association
*asoc
,
6038 const union sctp_subtype type
,
6040 struct sctp_cmd_seq
*commands
)
6042 pr_debug("%s: timer %d ignored\n", __func__
, type
.chunk
);
6044 return SCTP_DISPOSITION_CONSUME
;
6047 /********************************************************************
6048 * 2nd Level Abstractions
6049 ********************************************************************/
6051 /* Pull the SACK chunk based on the SACK header. */
6052 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
)
6054 struct sctp_sackhdr
*sack
;
6059 /* Protect ourselves from reading too far into
6060 * the skb from a bogus sender.
6062 sack
= (struct sctp_sackhdr
*) chunk
->skb
->data
;
6064 num_blocks
= ntohs(sack
->num_gap_ack_blocks
);
6065 num_dup_tsns
= ntohs(sack
->num_dup_tsns
);
6066 len
= sizeof(struct sctp_sackhdr
);
6067 len
+= (num_blocks
+ num_dup_tsns
) * sizeof(__u32
);
6068 if (len
> chunk
->skb
->len
)
6071 skb_pull(chunk
->skb
, len
);
6076 /* Create an ABORT packet to be sent as a response, with the specified
6079 static struct sctp_packet
*sctp_abort_pkt_new(
6081 const struct sctp_endpoint
*ep
,
6082 const struct sctp_association
*asoc
,
6083 struct sctp_chunk
*chunk
,
6084 const void *payload
, size_t paylen
)
6086 struct sctp_packet
*packet
;
6087 struct sctp_chunk
*abort
;
6089 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
6093 * The T bit will be set if the asoc is NULL.
6095 abort
= sctp_make_abort(asoc
, chunk
, paylen
);
6097 sctp_ootb_pkt_free(packet
);
6101 /* Reflect vtag if T-Bit is set */
6102 if (sctp_test_T_bit(abort
))
6103 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
6105 /* Add specified error causes, i.e., payload, to the
6108 sctp_addto_chunk(abort
, paylen
, payload
);
6110 /* Set the skb to the belonging sock for accounting. */
6111 abort
->skb
->sk
= ep
->base
.sk
;
6113 sctp_packet_append_chunk(packet
, abort
);
6120 /* Allocate a packet for responding in the OOTB conditions. */
6121 static struct sctp_packet
*sctp_ootb_pkt_new(
6123 const struct sctp_association
*asoc
,
6124 const struct sctp_chunk
*chunk
)
6126 struct sctp_transport
*transport
;
6127 struct sctp_packet
*packet
;
6131 /* Get the source and destination port from the inbound packet. */
6132 sport
= ntohs(chunk
->sctp_hdr
->dest
);
6133 dport
= ntohs(chunk
->sctp_hdr
->source
);
6135 /* The V-tag is going to be the same as the inbound packet if no
6136 * association exists, otherwise, use the peer's vtag.
6139 /* Special case the INIT-ACK as there is no peer's vtag
6142 switch (chunk
->chunk_hdr
->type
) {
6143 case SCTP_CID_INIT_ACK
:
6145 struct sctp_initack_chunk
*initack
;
6147 initack
= (struct sctp_initack_chunk
*)chunk
->chunk_hdr
;
6148 vtag
= ntohl(initack
->init_hdr
.init_tag
);
6152 vtag
= asoc
->peer
.i
.init_tag
;
6156 /* Special case the INIT and stale COOKIE_ECHO as there is no
6159 switch (chunk
->chunk_hdr
->type
) {
6162 struct sctp_init_chunk
*init
;
6164 init
= (struct sctp_init_chunk
*)chunk
->chunk_hdr
;
6165 vtag
= ntohl(init
->init_hdr
.init_tag
);
6169 vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
6174 /* Make a transport for the bucket, Eliza... */
6175 transport
= sctp_transport_new(net
, sctp_source(chunk
), GFP_ATOMIC
);
6179 /* Cache a route for the transport with the chunk's destination as
6180 * the source address.
6182 sctp_transport_route(transport
, (union sctp_addr
*)&chunk
->dest
,
6183 sctp_sk(net
->sctp
.ctl_sock
));
6185 packet
= &transport
->packet
;
6186 sctp_packet_init(packet
, transport
, sport
, dport
);
6187 sctp_packet_config(packet
, vtag
, 0);
6195 /* Free the packet allocated earlier for responding in the OOTB condition. */
6196 void sctp_ootb_pkt_free(struct sctp_packet
*packet
)
6198 sctp_transport_free(packet
->transport
);
6201 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
6202 static void sctp_send_stale_cookie_err(struct net
*net
,
6203 const struct sctp_endpoint
*ep
,
6204 const struct sctp_association
*asoc
,
6205 const struct sctp_chunk
*chunk
,
6206 struct sctp_cmd_seq
*commands
,
6207 struct sctp_chunk
*err_chunk
)
6209 struct sctp_packet
*packet
;
6212 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
6214 struct sctp_signed_cookie
*cookie
;
6216 /* Override the OOTB vtag from the cookie. */
6217 cookie
= chunk
->subh
.cookie_hdr
;
6218 packet
->vtag
= cookie
->c
.peer_vtag
;
6220 /* Set the skb to the belonging sock for accounting. */
6221 err_chunk
->skb
->sk
= ep
->base
.sk
;
6222 sctp_packet_append_chunk(packet
, err_chunk
);
6223 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
6224 SCTP_PACKET(packet
));
6225 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
6227 sctp_chunk_free (err_chunk
);
6232 /* Process a data chunk */
6233 static int sctp_eat_data(const struct sctp_association
*asoc
,
6234 struct sctp_chunk
*chunk
,
6235 struct sctp_cmd_seq
*commands
)
6237 struct sctp_tsnmap
*map
= (struct sctp_tsnmap
*)&asoc
->peer
.tsn_map
;
6238 struct sock
*sk
= asoc
->base
.sk
;
6239 struct net
*net
= sock_net(sk
);
6240 struct sctp_datahdr
*data_hdr
;
6241 struct sctp_chunk
*err
;
6242 enum sctp_verb deliver
;
6247 data_hdr
= (struct sctp_datahdr
*)chunk
->skb
->data
;
6248 chunk
->subh
.data_hdr
= data_hdr
;
6249 skb_pull(chunk
->skb
, sctp_datahdr_len(&asoc
->stream
));
6251 tsn
= ntohl(data_hdr
->tsn
);
6252 pr_debug("%s: TSN 0x%x\n", __func__
, tsn
);
6254 /* ASSERT: Now skb->data is really the user data. */
6256 /* Process ECN based congestion.
6258 * Since the chunk structure is reused for all chunks within
6259 * a packet, we use ecn_ce_done to track if we've already
6260 * done CE processing for this packet.
6262 * We need to do ECN processing even if we plan to discard the
6266 if (asoc
->peer
.ecn_capable
&& !chunk
->ecn_ce_done
) {
6267 struct sctp_af
*af
= SCTP_INPUT_CB(chunk
->skb
)->af
;
6268 chunk
->ecn_ce_done
= 1;
6270 if (af
->is_ce(sctp_gso_headskb(chunk
->skb
))) {
6271 /* Do real work as sideffect. */
6272 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_CE
,
6277 tmp
= sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
);
6279 /* The TSN is too high--silently discard the chunk and
6280 * count on it getting retransmitted later.
6283 chunk
->asoc
->stats
.outofseqtsns
++;
6284 return SCTP_IERROR_HIGH_TSN
;
6285 } else if (tmp
> 0) {
6286 /* This is a duplicate. Record it. */
6287 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_DUP
, SCTP_U32(tsn
));
6288 return SCTP_IERROR_DUP_TSN
;
6291 /* This is a new TSN. */
6293 /* Discard if there is no room in the receive window.
6294 * Actually, allow a little bit of overflow (up to a MTU).
6296 datalen
= ntohs(chunk
->chunk_hdr
->length
);
6297 datalen
-= sctp_datachk_len(&asoc
->stream
);
6299 deliver
= SCTP_CMD_CHUNK_ULP
;
6301 /* Think about partial delivery. */
6302 if ((datalen
>= asoc
->rwnd
) && (!asoc
->ulpq
.pd_mode
)) {
6304 /* Even if we don't accept this chunk there is
6307 sctp_add_cmd_sf(commands
, SCTP_CMD_PART_DELIVER
, SCTP_NULL());
6310 /* Spill over rwnd a little bit. Note: While allowed, this spill over
6311 * seems a bit troublesome in that frag_point varies based on
6312 * PMTU. In cases, such as loopback, this might be a rather
6315 if ((!chunk
->data_accepted
) && (!asoc
->rwnd
|| asoc
->rwnd_over
||
6316 (datalen
> asoc
->rwnd
+ asoc
->frag_point
))) {
6318 /* If this is the next TSN, consider reneging to make
6319 * room. Note: Playing nice with a confused sender. A
6320 * malicious sender can still eat up all our buffer
6321 * space and in the future we may want to detect and
6322 * do more drastic reneging.
6324 if (sctp_tsnmap_has_gap(map
) &&
6325 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
6326 pr_debug("%s: reneging for tsn:%u\n", __func__
, tsn
);
6327 deliver
= SCTP_CMD_RENEGE
;
6329 pr_debug("%s: discard tsn:%u len:%zu, rwnd:%d\n",
6330 __func__
, tsn
, datalen
, asoc
->rwnd
);
6332 return SCTP_IERROR_IGNORE_TSN
;
6337 * Also try to renege to limit our memory usage in the event that
6338 * we are under memory pressure
6339 * If we can't renege, don't worry about it, the sk_rmem_schedule
6340 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
6341 * memory usage too much
6343 if (*sk
->sk_prot_creator
->memory_pressure
) {
6344 if (sctp_tsnmap_has_gap(map
) &&
6345 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
6346 pr_debug("%s: under pressure, reneging for tsn:%u\n",
6348 deliver
= SCTP_CMD_RENEGE
;
6353 * Section 3.3.10.9 No User Data (9)
6357 * No User Data: This error cause is returned to the originator of a
6358 * DATA chunk if a received DATA chunk has no user data.
6360 if (unlikely(0 == datalen
)) {
6361 err
= sctp_make_abort_no_data(asoc
, chunk
, tsn
);
6363 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6366 /* We are going to ABORT, so we might as well stop
6367 * processing the rest of the chunks in the packet.
6369 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
6370 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
6371 SCTP_ERROR(ECONNABORTED
));
6372 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
6373 SCTP_PERR(SCTP_ERROR_NO_DATA
));
6374 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
6375 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
6376 return SCTP_IERROR_NO_DATA
;
6379 chunk
->data_accepted
= 1;
6381 /* Note: Some chunks may get overcounted (if we drop) or overcounted
6382 * if we renege and the chunk arrives again.
6384 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_UNORDERED
) {
6385 SCTP_INC_STATS(net
, SCTP_MIB_INUNORDERCHUNKS
);
6387 chunk
->asoc
->stats
.iuodchunks
++;
6389 SCTP_INC_STATS(net
, SCTP_MIB_INORDERCHUNKS
);
6391 chunk
->asoc
->stats
.iodchunks
++;
6394 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
6396 * If an endpoint receive a DATA chunk with an invalid stream
6397 * identifier, it shall acknowledge the reception of the DATA chunk
6398 * following the normal procedure, immediately send an ERROR chunk
6399 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
6400 * and discard the DATA chunk.
6402 if (ntohs(data_hdr
->stream
) >= asoc
->stream
.incnt
) {
6403 /* Mark tsn as received even though we drop it */
6404 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_TSN
, SCTP_U32(tsn
));
6406 err
= sctp_make_op_error(asoc
, chunk
, SCTP_ERROR_INV_STRM
,
6408 sizeof(data_hdr
->stream
),
6411 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6413 return SCTP_IERROR_BAD_STREAM
;
6416 /* Check to see if the SSN is possible for this TSN.
6417 * The biggest gap we can record is 4K wide. Since SSNs wrap
6418 * at an unsigned short, there is no way that an SSN can
6419 * wrap and for a valid TSN. We can simply check if the current
6420 * SSN is smaller then the next expected one. If it is, it wrapped
6423 if (!asoc
->stream
.si
->validate_data(chunk
))
6424 return SCTP_IERROR_PROTO_VIOLATION
;
6426 /* Send the data up to the user. Note: Schedule the
6427 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
6428 * chunk needs the updated rwnd.
6430 sctp_add_cmd_sf(commands
, deliver
, SCTP_CHUNK(chunk
));
6432 return SCTP_IERROR_NO_ERROR
;