1 /* SCTP kernel implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001-2002 Intel Corp.
6 * Copyright (c) 2002 Nokia Corp.
8 * This is part of the SCTP Linux Kernel Implementation.
10 * These are the state functions for the state machine.
12 * This SCTP implementation is free software;
13 * you can redistribute it and/or modify it under the terms of
14 * the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * This SCTP implementation is distributed in the hope that it
19 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
20 * ************************
21 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 * See the GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with GNU CC; see the file COPYING. If not, write to
26 * the Free Software Foundation, 59 Temple Place - Suite 330,
27 * Boston, MA 02111-1307, USA.
29 * Please send any bug reports or fixes you make to the
31 * lksctp developers <lksctp-developers@lists.sourceforge.net>
33 * Or submit a bug report through the following website:
34 * http://www.sf.net/projects/lksctp
36 * Written or modified by:
37 * La Monte H.P. Yarroll <piggy@acm.org>
38 * Karl Knutson <karl@athena.chicago.il.us>
39 * Mathew Kotowsky <kotowsky@sctp.org>
40 * Sridhar Samudrala <samudrala@us.ibm.com>
41 * Jon Grimm <jgrimm@us.ibm.com>
42 * Hui Huang <hui.huang@nokia.com>
43 * Dajiang Zhang <dajiang.zhang@nokia.com>
44 * Daisy Chang <daisyc@us.ibm.com>
45 * Ardelle Fan <ardelle.fan@intel.com>
46 * Ryan Layer <rmlayer@us.ibm.com>
47 * Kevin Gao <kevin.gao@intel.com>
49 * Any bugs reported given to us we will try to fix... any fixes shared will
50 * be incorporated into the next SCTP release.
53 #include <linux/types.h>
54 #include <linux/kernel.h>
56 #include <linux/ipv6.h>
57 #include <linux/net.h>
58 #include <linux/inet.h>
59 #include <linux/slab.h>
61 #include <net/inet_ecn.h>
62 #include <linux/skbuff.h>
63 #include <net/sctp/sctp.h>
64 #include <net/sctp/sm.h>
65 #include <net/sctp/structs.h>
67 static struct sctp_packet
*sctp_abort_pkt_new(const struct sctp_endpoint
*ep
,
68 const struct sctp_association
*asoc
,
69 struct sctp_chunk
*chunk
,
72 static int sctp_eat_data(const struct sctp_association
*asoc
,
73 struct sctp_chunk
*chunk
,
74 sctp_cmd_seq_t
*commands
);
75 static struct sctp_packet
*sctp_ootb_pkt_new(const struct sctp_association
*asoc
,
76 const struct sctp_chunk
*chunk
);
77 static void sctp_send_stale_cookie_err(const struct sctp_endpoint
*ep
,
78 const struct sctp_association
*asoc
,
79 const struct sctp_chunk
*chunk
,
80 sctp_cmd_seq_t
*commands
,
81 struct sctp_chunk
*err_chunk
);
82 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(const struct sctp_endpoint
*ep
,
83 const struct sctp_association
*asoc
,
84 const sctp_subtype_t type
,
86 sctp_cmd_seq_t
*commands
);
87 static sctp_disposition_t
sctp_sf_shut_8_4_5(const struct sctp_endpoint
*ep
,
88 const struct sctp_association
*asoc
,
89 const sctp_subtype_t type
,
91 sctp_cmd_seq_t
*commands
);
92 static sctp_disposition_t
sctp_sf_tabort_8_4_8(const struct sctp_endpoint
*ep
,
93 const struct sctp_association
*asoc
,
94 const sctp_subtype_t type
,
96 sctp_cmd_seq_t
*commands
);
97 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
);
99 static sctp_disposition_t
sctp_stop_t1_and_abort(sctp_cmd_seq_t
*commands
,
100 __be16 error
, int sk_err
,
101 const struct sctp_association
*asoc
,
102 struct sctp_transport
*transport
);
104 static sctp_disposition_t
sctp_sf_abort_violation(
105 const struct sctp_endpoint
*ep
,
106 const struct sctp_association
*asoc
,
108 sctp_cmd_seq_t
*commands
,
110 const size_t paylen
);
112 static sctp_disposition_t
sctp_sf_violation_chunklen(
113 const struct sctp_endpoint
*ep
,
114 const struct sctp_association
*asoc
,
115 const sctp_subtype_t type
,
117 sctp_cmd_seq_t
*commands
);
119 static sctp_disposition_t
sctp_sf_violation_paramlen(
120 const struct sctp_endpoint
*ep
,
121 const struct sctp_association
*asoc
,
122 const sctp_subtype_t type
,
123 void *arg
, void *ext
,
124 sctp_cmd_seq_t
*commands
);
126 static sctp_disposition_t
sctp_sf_violation_ctsn(
127 const struct sctp_endpoint
*ep
,
128 const struct sctp_association
*asoc
,
129 const sctp_subtype_t type
,
131 sctp_cmd_seq_t
*commands
);
133 static sctp_disposition_t
sctp_sf_violation_chunk(
134 const struct sctp_endpoint
*ep
,
135 const struct sctp_association
*asoc
,
136 const sctp_subtype_t type
,
138 sctp_cmd_seq_t
*commands
);
140 static sctp_ierror_t
sctp_sf_authenticate(const struct sctp_endpoint
*ep
,
141 const struct sctp_association
*asoc
,
142 const sctp_subtype_t type
,
143 struct sctp_chunk
*chunk
);
145 static sctp_disposition_t
__sctp_sf_do_9_1_abort(const struct sctp_endpoint
*ep
,
146 const struct sctp_association
*asoc
,
147 const sctp_subtype_t type
,
149 sctp_cmd_seq_t
*commands
);
151 /* Small helper function that checks if the chunk length
152 * is of the appropriate length. The 'required_length' argument
153 * is set to be the size of a specific chunk we are testing.
154 * Return Values: 1 = Valid length
159 sctp_chunk_length_valid(struct sctp_chunk
*chunk
,
160 __u16 required_length
)
162 __u16 chunk_length
= ntohs(chunk
->chunk_hdr
->length
);
164 if (unlikely(chunk_length
< required_length
))
170 /**********************************************************
171 * These are the state functions for handling chunk events.
172 **********************************************************/
175 * Process the final SHUTDOWN COMPLETE.
177 * Section: 4 (C) (diagram), 9.2
178 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
179 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
180 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
181 * should stop the T2-shutdown timer and remove all knowledge of the
182 * association (and thus the association enters the CLOSED state).
184 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
185 * C) Rules for packet carrying SHUTDOWN COMPLETE:
187 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
188 * if the Verification Tag field of the packet matches its own tag and
189 * the T bit is not set
191 * it is set to its peer's tag and the T bit is set in the Chunk
193 * Otherwise, the receiver MUST silently discard the packet
194 * and take no further action. An endpoint MUST ignore the
195 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
198 * (endpoint, asoc, chunk)
201 * (asoc, reply_msg, msg_up, timers, counters)
203 * The return value is the disposition of the chunk.
205 sctp_disposition_t
sctp_sf_do_4_C(const struct sctp_endpoint
*ep
,
206 const struct sctp_association
*asoc
,
207 const sctp_subtype_t type
,
209 sctp_cmd_seq_t
*commands
)
211 struct sctp_chunk
*chunk
= arg
;
212 struct sctp_ulpevent
*ev
;
214 if (!sctp_vtag_verify_either(chunk
, asoc
))
215 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
217 /* RFC 2960 6.10 Bundling
219 * An endpoint MUST NOT bundle INIT, INIT ACK or
220 * SHUTDOWN COMPLETE with any other chunks.
222 if (!chunk
->singleton
)
223 return sctp_sf_violation_chunk(ep
, asoc
, type
, arg
, commands
);
225 /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */
226 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
227 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
230 /* RFC 2960 10.2 SCTP-to-ULP
232 * H) SHUTDOWN COMPLETE notification
234 * When SCTP completes the shutdown procedures (section 9.2) this
235 * notification is passed to the upper layer.
237 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
238 0, 0, 0, NULL
, GFP_ATOMIC
);
240 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
243 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
244 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
245 * not the chunk should be discarded. If the endpoint is in
246 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
247 * T2-shutdown timer and remove all knowledge of the
248 * association (and thus the association enters the CLOSED
251 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
252 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
254 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
255 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
257 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
258 SCTP_STATE(SCTP_STATE_CLOSED
));
260 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS
);
261 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
263 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
265 return SCTP_DISPOSITION_DELETE_TCB
;
269 * Respond to a normal INIT chunk.
270 * We are the side that is being asked for an association.
272 * Section: 5.1 Normal Establishment of an Association, B
273 * B) "Z" shall respond immediately with an INIT ACK chunk. The
274 * destination IP address of the INIT ACK MUST be set to the source
275 * IP address of the INIT to which this INIT ACK is responding. In
276 * the response, besides filling in other parameters, "Z" must set the
277 * Verification Tag field to Tag_A, and also provide its own
278 * Verification Tag (Tag_Z) in the Initiate Tag field.
280 * Verification Tag: Must be 0.
283 * (endpoint, asoc, chunk)
286 * (asoc, reply_msg, msg_up, timers, counters)
288 * The return value is the disposition of the chunk.
290 sctp_disposition_t
sctp_sf_do_5_1B_init(const struct sctp_endpoint
*ep
,
291 const struct sctp_association
*asoc
,
292 const sctp_subtype_t type
,
294 sctp_cmd_seq_t
*commands
)
296 struct sctp_chunk
*chunk
= arg
;
297 struct sctp_chunk
*repl
;
298 struct sctp_association
*new_asoc
;
299 struct sctp_chunk
*err_chunk
;
300 struct sctp_packet
*packet
;
301 sctp_unrecognized_param_t
*unk_param
;
305 * An endpoint MUST NOT bundle INIT, INIT ACK or
306 * SHUTDOWN COMPLETE with any other chunks.
309 * Furthermore, we require that the receiver of an INIT chunk MUST
310 * enforce these rules by silently discarding an arriving packet
311 * with an INIT chunk that is bundled with other chunks.
313 if (!chunk
->singleton
)
314 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
316 /* If the packet is an OOTB packet which is temporarily on the
317 * control endpoint, respond with an ABORT.
319 if (ep
== sctp_sk((sctp_get_ctl_sock()))->ep
) {
320 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES
);
321 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
324 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
327 if (chunk
->sctp_hdr
->vtag
!= 0)
328 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
330 /* Make sure that the INIT chunk has a valid length.
331 * Normally, this would cause an ABORT with a Protocol Violation
332 * error, but since we don't have an association, we'll
333 * just discard the packet.
335 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_init_chunk_t
)))
336 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
338 /* If the INIT is coming toward a closing socket, we'll send back
339 * and ABORT. Essentially, this catches the race of INIT being
340 * backloged to the socket at the same time as the user isses close().
341 * Since the socket and all its associations are going away, we
342 * can treat this OOTB
344 if (sctp_sstate(ep
->base
.sk
, CLOSING
))
345 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
347 /* Verify the INIT chunk before processing it. */
349 if (!sctp_verify_init(asoc
, chunk
->chunk_hdr
->type
,
350 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
352 /* This chunk contains fatal error. It is to be discarded.
353 * Send an ABORT, with causes if there is any.
356 packet
= sctp_abort_pkt_new(ep
, asoc
, arg
,
357 (__u8
*)(err_chunk
->chunk_hdr
) +
358 sizeof(sctp_chunkhdr_t
),
359 ntohs(err_chunk
->chunk_hdr
->length
) -
360 sizeof(sctp_chunkhdr_t
));
362 sctp_chunk_free(err_chunk
);
365 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
366 SCTP_PACKET(packet
));
367 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
368 return SCTP_DISPOSITION_CONSUME
;
370 return SCTP_DISPOSITION_NOMEM
;
373 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
,
378 /* Grab the INIT header. */
379 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*)chunk
->skb
->data
;
381 /* Tag the variable length parameters. */
382 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
384 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
388 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
,
389 sctp_scope(sctp_source(chunk
)),
393 /* The call, sctp_process_init(), can fail on memory allocation. */
394 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
396 (sctp_init_chunk_t
*)chunk
->chunk_hdr
,
400 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
402 /* If there are errors need to be reported for unknown parameters,
403 * make sure to reserve enough room in the INIT ACK for them.
407 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
408 sizeof(sctp_chunkhdr_t
);
410 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
414 /* If there are errors need to be reported for unknown parameters,
415 * include them in the outgoing INIT ACK as "Unrecognized parameter"
419 /* Get the "Unrecognized parameter" parameter(s) out of the
420 * ERROR chunk generated by sctp_verify_init(). Since the
421 * error cause code for "unknown parameter" and the
422 * "Unrecognized parameter" type is the same, we can
423 * construct the parameters in INIT ACK by copying the
426 unk_param
= (sctp_unrecognized_param_t
*)
427 ((__u8
*)(err_chunk
->chunk_hdr
) +
428 sizeof(sctp_chunkhdr_t
));
429 /* Replace the cause code with the "Unrecognized parameter"
432 sctp_addto_chunk(repl
, len
, unk_param
);
433 sctp_chunk_free(err_chunk
);
436 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
438 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
441 * Note: After sending out INIT ACK with the State Cookie parameter,
442 * "Z" MUST NOT allocate any resources, nor keep any states for the
443 * new association. Otherwise, "Z" will be vulnerable to resource
446 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
448 return SCTP_DISPOSITION_DELETE_TCB
;
451 sctp_association_free(new_asoc
);
454 sctp_chunk_free(err_chunk
);
455 return SCTP_DISPOSITION_NOMEM
;
459 * Respond to a normal INIT ACK chunk.
460 * We are the side that is initiating the association.
462 * Section: 5.1 Normal Establishment of an Association, C
463 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
464 * timer and leave COOKIE-WAIT state. "A" shall then send the State
465 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
466 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
468 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
469 * DATA chunks, but it MUST be the first chunk in the packet and
470 * until the COOKIE ACK is returned the sender MUST NOT send any
471 * other packets to the peer.
473 * Verification Tag: 3.3.3
474 * If the value of the Initiate Tag in a received INIT ACK chunk is
475 * found to be 0, the receiver MUST treat it as an error and close the
476 * association by transmitting an ABORT.
479 * (endpoint, asoc, chunk)
482 * (asoc, reply_msg, msg_up, timers, counters)
484 * The return value is the disposition of the chunk.
486 sctp_disposition_t
sctp_sf_do_5_1C_ack(const struct sctp_endpoint
*ep
,
487 const struct sctp_association
*asoc
,
488 const sctp_subtype_t type
,
490 sctp_cmd_seq_t
*commands
)
492 struct sctp_chunk
*chunk
= arg
;
493 sctp_init_chunk_t
*initchunk
;
494 struct sctp_chunk
*err_chunk
;
495 struct sctp_packet
*packet
;
497 if (!sctp_vtag_verify(chunk
, asoc
))
498 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
501 * An endpoint MUST NOT bundle INIT, INIT ACK or
502 * SHUTDOWN COMPLETE with any other chunks.
504 if (!chunk
->singleton
)
505 return sctp_sf_violation_chunk(ep
, asoc
, type
, arg
, commands
);
507 /* Make sure that the INIT-ACK chunk has a valid length */
508 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_initack_chunk_t
)))
509 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
511 /* Grab the INIT header. */
512 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
514 /* Verify the INIT chunk before processing it. */
516 if (!sctp_verify_init(asoc
, chunk
->chunk_hdr
->type
,
517 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
520 sctp_error_t error
= SCTP_ERROR_NO_RESOURCE
;
522 /* This chunk contains fatal error. It is to be discarded.
523 * Send an ABORT, with causes. If there are no causes,
524 * then there wasn't enough memory. Just terminate
528 packet
= sctp_abort_pkt_new(ep
, asoc
, arg
,
529 (__u8
*)(err_chunk
->chunk_hdr
) +
530 sizeof(sctp_chunkhdr_t
),
531 ntohs(err_chunk
->chunk_hdr
->length
) -
532 sizeof(sctp_chunkhdr_t
));
534 sctp_chunk_free(err_chunk
);
537 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
538 SCTP_PACKET(packet
));
539 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
540 error
= SCTP_ERROR_INV_PARAM
;
544 /* SCTP-AUTH, Section 6.3:
545 * It should be noted that if the receiver wants to tear
546 * down an association in an authenticated way only, the
547 * handling of malformed packets should not result in
548 * tearing down the association.
550 * This means that if we only want to abort associations
551 * in an authenticated way (i.e AUTH+ABORT), then we
552 * can't destroy this association just becuase the packet
555 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
556 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
558 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
559 return sctp_stop_t1_and_abort(commands
, error
, ECONNREFUSED
,
560 asoc
, chunk
->transport
);
563 /* Tag the variable length parameters. Note that we never
564 * convert the parameters in an INIT chunk.
566 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
568 initchunk
= (sctp_init_chunk_t
*) chunk
->chunk_hdr
;
570 sctp_add_cmd_sf(commands
, SCTP_CMD_PEER_INIT
,
571 SCTP_PEER_INIT(initchunk
));
573 /* Reset init error count upon receipt of INIT-ACK. */
574 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
576 /* 5.1 C) "A" shall stop the T1-init timer and leave
577 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
578 * timer, and enter the COOKIE-ECHOED state.
580 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
581 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
582 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
583 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
584 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
585 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED
));
587 /* SCTP-AUTH: genereate the assocition shared keys so that
588 * we can potentially signe the COOKIE-ECHO.
590 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_SHKEY
, SCTP_NULL());
592 /* 5.1 C) "A" shall then send the State Cookie received in the
593 * INIT ACK chunk in a COOKIE ECHO chunk, ...
595 /* If there is any errors to report, send the ERROR chunk generated
596 * for unknown parameters as well.
598 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_COOKIE_ECHO
,
599 SCTP_CHUNK(err_chunk
));
601 return SCTP_DISPOSITION_CONSUME
;
605 * Respond to a normal COOKIE ECHO chunk.
606 * We are the side that is being asked for an association.
608 * Section: 5.1 Normal Establishment of an Association, D
609 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
610 * with a COOKIE ACK chunk after building a TCB and moving to
611 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
612 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
613 * chunk MUST be the first chunk in the packet.
615 * IMPLEMENTATION NOTE: An implementation may choose to send the
616 * Communication Up notification to the SCTP user upon reception
617 * of a valid COOKIE ECHO chunk.
619 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
620 * D) Rules for packet carrying a COOKIE ECHO
622 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
623 * Initial Tag received in the INIT ACK.
625 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
628 * (endpoint, asoc, chunk)
631 * (asoc, reply_msg, msg_up, timers, counters)
633 * The return value is the disposition of the chunk.
635 sctp_disposition_t
sctp_sf_do_5_1D_ce(const struct sctp_endpoint
*ep
,
636 const struct sctp_association
*asoc
,
637 const sctp_subtype_t type
, void *arg
,
638 sctp_cmd_seq_t
*commands
)
640 struct sctp_chunk
*chunk
= arg
;
641 struct sctp_association
*new_asoc
;
642 sctp_init_chunk_t
*peer_init
;
643 struct sctp_chunk
*repl
;
644 struct sctp_ulpevent
*ev
, *ai_ev
= NULL
;
646 struct sctp_chunk
*err_chk_p
;
649 /* If the packet is an OOTB packet which is temporarily on the
650 * control endpoint, respond with an ABORT.
652 if (ep
== sctp_sk((sctp_get_ctl_sock()))->ep
) {
653 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES
);
654 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
657 /* Make sure that the COOKIE_ECHO chunk has a valid length.
658 * In this case, we check that we have enough for at least a
659 * chunk header. More detailed verification is done
660 * in sctp_unpack_cookie().
662 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
663 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
665 /* If the endpoint is not listening or if the number of associations
666 * on the TCP-style socket exceed the max backlog, respond with an
670 if (!sctp_sstate(sk
, LISTENING
) ||
671 (sctp_style(sk
, TCP
) && sk_acceptq_is_full(sk
)))
672 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
674 /* "Decode" the chunk. We have no optional parameters so we
677 chunk
->subh
.cookie_hdr
=
678 (struct sctp_signed_cookie
*)chunk
->skb
->data
;
679 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
680 sizeof(sctp_chunkhdr_t
)))
683 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
684 * "Z" will reply with a COOKIE ACK chunk after building a TCB
685 * and moving to the ESTABLISHED state.
687 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
692 case -SCTP_IERROR_NOMEM
:
695 case -SCTP_IERROR_STALE_COOKIE
:
696 sctp_send_stale_cookie_err(ep
, asoc
, chunk
, commands
,
698 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
700 case -SCTP_IERROR_BAD_SIG
:
702 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
707 /* Delay state machine commands until later.
709 * Re-build the bind address for the association is done in
710 * the sctp_unpack_cookie() already.
712 /* This is a brand-new association, so these are not yet side
713 * effects--it is safe to run them here.
715 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
717 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
718 &chunk
->subh
.cookie_hdr
->c
.peer_addr
,
719 peer_init
, GFP_ATOMIC
))
722 /* SCTP-AUTH: Now that we've populate required fields in
723 * sctp_process_init, set up the assocaition shared keys as
724 * necessary so that we can potentially authenticate the ACK
726 error
= sctp_auth_asoc_init_active_key(new_asoc
, GFP_ATOMIC
);
730 /* SCTP-AUTH: auth_chunk pointer is only set when the cookie-echo
731 * is supposed to be authenticated and we have to do delayed
732 * authentication. We've just recreated the association using
733 * the information in the cookie and now it's much easier to
734 * do the authentication.
736 if (chunk
->auth_chunk
) {
737 struct sctp_chunk auth
;
740 /* set-up our fake chunk so that we can process it */
741 auth
.skb
= chunk
->auth_chunk
;
742 auth
.asoc
= chunk
->asoc
;
743 auth
.sctp_hdr
= chunk
->sctp_hdr
;
744 auth
.chunk_hdr
= (sctp_chunkhdr_t
*)skb_push(chunk
->auth_chunk
,
745 sizeof(sctp_chunkhdr_t
));
746 skb_pull(chunk
->auth_chunk
, sizeof(sctp_chunkhdr_t
));
747 auth
.transport
= chunk
->transport
;
749 ret
= sctp_sf_authenticate(ep
, new_asoc
, type
, &auth
);
751 /* We can now safely free the auth_chunk clone */
752 kfree_skb(chunk
->auth_chunk
);
754 if (ret
!= SCTP_IERROR_NO_ERROR
) {
755 sctp_association_free(new_asoc
);
756 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
760 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
764 /* RFC 2960 5.1 Normal Establishment of an Association
766 * D) IMPLEMENTATION NOTE: An implementation may choose to
767 * send the Communication Up notification to the SCTP user
768 * upon reception of a valid COOKIE ECHO chunk.
770 ev
= sctp_ulpevent_make_assoc_change(new_asoc
, 0, SCTP_COMM_UP
, 0,
771 new_asoc
->c
.sinit_num_ostreams
,
772 new_asoc
->c
.sinit_max_instreams
,
777 /* Sockets API Draft Section 5.3.1.6
778 * When a peer sends a Adaptation Layer Indication parameter , SCTP
779 * delivers this notification to inform the application that of the
780 * peers requested adaptation layer.
782 if (new_asoc
->peer
.adaptation_ind
) {
783 ai_ev
= sctp_ulpevent_make_adaptation_indication(new_asoc
,
789 /* Add all the state machine commands now since we've created
790 * everything. This way we don't introduce memory corruptions
791 * during side-effect processing and correclty count established
794 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
795 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
796 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
797 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
798 SCTP_INC_STATS(SCTP_MIB_PASSIVEESTABS
);
799 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
801 if (new_asoc
->autoclose
)
802 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
803 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
805 /* This will send the COOKIE ACK */
806 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
808 /* Queue the ASSOC_CHANGE event */
809 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
811 /* Send up the Adaptation Layer Indication event */
813 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
814 SCTP_ULPEVENT(ai_ev
));
816 return SCTP_DISPOSITION_CONSUME
;
819 sctp_ulpevent_free(ev
);
821 sctp_chunk_free(repl
);
823 sctp_association_free(new_asoc
);
825 return SCTP_DISPOSITION_NOMEM
;
829 * Respond to a normal COOKIE ACK chunk.
830 * We are the side that is being asked for an association.
832 * RFC 2960 5.1 Normal Establishment of an Association
834 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
835 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
836 * timer. It may also notify its ULP about the successful
837 * establishment of the association with a Communication Up
838 * notification (see Section 10).
842 * (endpoint, asoc, chunk)
845 * (asoc, reply_msg, msg_up, timers, counters)
847 * The return value is the disposition of the chunk.
849 sctp_disposition_t
sctp_sf_do_5_1E_ca(const struct sctp_endpoint
*ep
,
850 const struct sctp_association
*asoc
,
851 const sctp_subtype_t type
, void *arg
,
852 sctp_cmd_seq_t
*commands
)
854 struct sctp_chunk
*chunk
= arg
;
855 struct sctp_ulpevent
*ev
;
857 if (!sctp_vtag_verify(chunk
, asoc
))
858 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
860 /* Verify that the chunk length for the COOKIE-ACK is OK.
861 * If we don't do this, any bundled chunks may be junked.
863 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
864 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
867 /* Reset init error count upon receipt of COOKIE-ACK,
868 * to avoid problems with the managemement of this
869 * counter in stale cookie situations when a transition back
870 * from the COOKIE-ECHOED state to the COOKIE-WAIT
871 * state is performed.
873 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
875 /* RFC 2960 5.1 Normal Establishment of an Association
877 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
878 * from the COOKIE-ECHOED state to the ESTABLISHED state,
879 * stopping the T1-cookie timer.
881 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
882 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
883 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
884 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
885 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
886 SCTP_INC_STATS(SCTP_MIB_ACTIVEESTABS
);
887 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
889 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
890 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
892 /* It may also notify its ULP about the successful
893 * establishment of the association with a Communication Up
894 * notification (see Section 10).
896 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_COMM_UP
,
897 0, asoc
->c
.sinit_num_ostreams
,
898 asoc
->c
.sinit_max_instreams
,
904 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
906 /* Sockets API Draft Section 5.3.1.6
907 * When a peer sends a Adaptation Layer Indication parameter , SCTP
908 * delivers this notification to inform the application that of the
909 * peers requested adaptation layer.
911 if (asoc
->peer
.adaptation_ind
) {
912 ev
= sctp_ulpevent_make_adaptation_indication(asoc
, GFP_ATOMIC
);
916 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
920 return SCTP_DISPOSITION_CONSUME
;
922 return SCTP_DISPOSITION_NOMEM
;
925 /* Generate and sendout a heartbeat packet. */
926 static sctp_disposition_t
sctp_sf_heartbeat(const struct sctp_endpoint
*ep
,
927 const struct sctp_association
*asoc
,
928 const sctp_subtype_t type
,
930 sctp_cmd_seq_t
*commands
)
932 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
933 struct sctp_chunk
*reply
;
934 sctp_sender_hb_info_t hbinfo
;
937 hbinfo
.param_hdr
.type
= SCTP_PARAM_HEARTBEAT_INFO
;
938 hbinfo
.param_hdr
.length
= htons(sizeof(sctp_sender_hb_info_t
));
939 hbinfo
.daddr
= transport
->ipaddr
;
940 hbinfo
.sent_at
= jiffies
;
941 hbinfo
.hb_nonce
= transport
->hb_nonce
;
943 /* Send a heartbeat to our peer. */
944 paylen
= sizeof(sctp_sender_hb_info_t
);
945 reply
= sctp_make_heartbeat(asoc
, transport
, &hbinfo
, paylen
);
947 return SCTP_DISPOSITION_NOMEM
;
949 /* Set rto_pending indicating that an RTT measurement
950 * is started with this heartbeat chunk.
952 sctp_add_cmd_sf(commands
, SCTP_CMD_RTO_PENDING
,
953 SCTP_TRANSPORT(transport
));
955 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
956 return SCTP_DISPOSITION_CONSUME
;
959 /* Generate a HEARTBEAT packet on the given transport. */
960 sctp_disposition_t
sctp_sf_sendbeat_8_3(const struct sctp_endpoint
*ep
,
961 const struct sctp_association
*asoc
,
962 const sctp_subtype_t type
,
964 sctp_cmd_seq_t
*commands
)
966 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
968 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
969 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
970 SCTP_ERROR(ETIMEDOUT
));
971 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
972 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
973 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
974 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
975 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
976 return SCTP_DISPOSITION_DELETE_TCB
;
980 * The Sender-specific Heartbeat Info field should normally include
981 * information about the sender's current time when this HEARTBEAT
982 * chunk is sent and the destination transport address to which this
983 * HEARTBEAT is sent (see Section 8.3).
986 if (transport
->param_flags
& SPP_HB_ENABLE
) {
987 if (SCTP_DISPOSITION_NOMEM
==
988 sctp_sf_heartbeat(ep
, asoc
, type
, arg
,
990 return SCTP_DISPOSITION_NOMEM
;
992 /* Set transport error counter and association error counter
993 * when sending heartbeat.
995 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
996 SCTP_TRANSPORT(transport
));
998 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_IDLE
,
999 SCTP_TRANSPORT(transport
));
1000 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMER_UPDATE
,
1001 SCTP_TRANSPORT(transport
));
1003 return SCTP_DISPOSITION_CONSUME
;
1007 * Process an heartbeat request.
1009 * Section: 8.3 Path Heartbeat
1010 * The receiver of the HEARTBEAT should immediately respond with a
1011 * HEARTBEAT ACK that contains the Heartbeat Information field copied
1012 * from the received HEARTBEAT chunk.
1014 * Verification Tag: 8.5 Verification Tag [Normal verification]
1015 * When receiving an SCTP packet, the endpoint MUST ensure that the
1016 * value in the Verification Tag field of the received SCTP packet
1017 * matches its own Tag. If the received Verification Tag value does not
1018 * match the receiver's own tag value, the receiver shall silently
1019 * discard the packet and shall not process it any further except for
1020 * those cases listed in Section 8.5.1 below.
1023 * (endpoint, asoc, chunk)
1026 * (asoc, reply_msg, msg_up, timers, counters)
1028 * The return value is the disposition of the chunk.
1030 sctp_disposition_t
sctp_sf_beat_8_3(const struct sctp_endpoint
*ep
,
1031 const struct sctp_association
*asoc
,
1032 const sctp_subtype_t type
,
1034 sctp_cmd_seq_t
*commands
)
1036 struct sctp_chunk
*chunk
= arg
;
1037 struct sctp_chunk
*reply
;
1040 if (!sctp_vtag_verify(chunk
, asoc
))
1041 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1043 /* Make sure that the HEARTBEAT chunk has a valid length. */
1044 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_heartbeat_chunk_t
)))
1045 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1048 /* 8.3 The receiver of the HEARTBEAT should immediately
1049 * respond with a HEARTBEAT ACK that contains the Heartbeat
1050 * Information field copied from the received HEARTBEAT chunk.
1052 chunk
->subh
.hb_hdr
= (sctp_heartbeathdr_t
*) chunk
->skb
->data
;
1053 paylen
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(sctp_chunkhdr_t
);
1054 if (!pskb_pull(chunk
->skb
, paylen
))
1057 reply
= sctp_make_heartbeat_ack(asoc
, chunk
,
1058 chunk
->subh
.hb_hdr
, paylen
);
1062 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
1063 return SCTP_DISPOSITION_CONSUME
;
1066 return SCTP_DISPOSITION_NOMEM
;
1070 * Process the returning HEARTBEAT ACK.
1072 * Section: 8.3 Path Heartbeat
1073 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
1074 * should clear the error counter of the destination transport
1075 * address to which the HEARTBEAT was sent, and mark the destination
1076 * transport address as active if it is not so marked. The endpoint may
1077 * optionally report to the upper layer when an inactive destination
1078 * address is marked as active due to the reception of the latest
1079 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
1080 * clear the association overall error count as well (as defined
1083 * The receiver of the HEARTBEAT ACK should also perform an RTT
1084 * measurement for that destination transport address using the time
1085 * value carried in the HEARTBEAT ACK chunk.
1087 * Verification Tag: 8.5 Verification Tag [Normal verification]
1090 * (endpoint, asoc, chunk)
1093 * (asoc, reply_msg, msg_up, timers, counters)
1095 * The return value is the disposition of the chunk.
1097 sctp_disposition_t
sctp_sf_backbeat_8_3(const struct sctp_endpoint
*ep
,
1098 const struct sctp_association
*asoc
,
1099 const sctp_subtype_t type
,
1101 sctp_cmd_seq_t
*commands
)
1103 struct sctp_chunk
*chunk
= arg
;
1104 union sctp_addr from_addr
;
1105 struct sctp_transport
*link
;
1106 sctp_sender_hb_info_t
*hbinfo
;
1107 unsigned long max_interval
;
1109 if (!sctp_vtag_verify(chunk
, asoc
))
1110 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1112 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1113 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
) +
1114 sizeof(sctp_sender_hb_info_t
)))
1115 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1118 hbinfo
= (sctp_sender_hb_info_t
*) chunk
->skb
->data
;
1119 /* Make sure that the length of the parameter is what we expect */
1120 if (ntohs(hbinfo
->param_hdr
.length
) !=
1121 sizeof(sctp_sender_hb_info_t
)) {
1122 return SCTP_DISPOSITION_DISCARD
;
1125 from_addr
= hbinfo
->daddr
;
1126 link
= sctp_assoc_lookup_paddr(asoc
, &from_addr
);
1128 /* This should never happen, but lets log it if so. */
1129 if (unlikely(!link
)) {
1130 if (from_addr
.sa
.sa_family
== AF_INET6
) {
1131 if (net_ratelimit())
1133 "%s association %p could not find address %pI6\n",
1136 &from_addr
.v6
.sin6_addr
);
1138 if (net_ratelimit())
1140 "%s association %p could not find address %pI4\n",
1143 &from_addr
.v4
.sin_addr
.s_addr
);
1145 return SCTP_DISPOSITION_DISCARD
;
1148 /* Validate the 64-bit random nonce. */
1149 if (hbinfo
->hb_nonce
!= link
->hb_nonce
)
1150 return SCTP_DISPOSITION_DISCARD
;
1152 max_interval
= link
->hbinterval
+ link
->rto
;
1154 /* Check if the timestamp looks valid. */
1155 if (time_after(hbinfo
->sent_at
, jiffies
) ||
1156 time_after(jiffies
, hbinfo
->sent_at
+ max_interval
)) {
1157 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp "
1158 "received for transport: %p\n",
1160 return SCTP_DISPOSITION_DISCARD
;
1163 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1164 * the HEARTBEAT should clear the error counter of the
1165 * destination transport address to which the HEARTBEAT was
1166 * sent and mark the destination transport address as active if
1167 * it is not so marked.
1169 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_ON
, SCTP_TRANSPORT(link
));
1171 return SCTP_DISPOSITION_CONSUME
;
1174 /* Helper function to send out an abort for the restart
1177 static int sctp_sf_send_restart_abort(union sctp_addr
*ssa
,
1178 struct sctp_chunk
*init
,
1179 sctp_cmd_seq_t
*commands
)
1182 struct sctp_packet
*pkt
;
1183 union sctp_addr_param
*addrparm
;
1184 struct sctp_errhdr
*errhdr
;
1185 struct sctp_endpoint
*ep
;
1186 char buffer
[sizeof(struct sctp_errhdr
)+sizeof(union sctp_addr_param
)];
1187 struct sctp_af
*af
= sctp_get_af_specific(ssa
->v4
.sin_family
);
1189 /* Build the error on the stack. We are way to malloc crazy
1190 * throughout the code today.
1192 errhdr
= (struct sctp_errhdr
*)buffer
;
1193 addrparm
= (union sctp_addr_param
*)errhdr
->variable
;
1195 /* Copy into a parm format. */
1196 len
= af
->to_addr_param(ssa
, addrparm
);
1197 len
+= sizeof(sctp_errhdr_t
);
1199 errhdr
->cause
= SCTP_ERROR_RESTART
;
1200 errhdr
->length
= htons(len
);
1202 /* Assign to the control socket. */
1203 ep
= sctp_sk((sctp_get_ctl_sock()))->ep
;
1205 /* Association is NULL since this may be a restart attack and we
1206 * want to send back the attacker's vtag.
1208 pkt
= sctp_abort_pkt_new(ep
, NULL
, init
, errhdr
, len
);
1212 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
, SCTP_PACKET(pkt
));
1214 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
1216 /* Discard the rest of the inbound packet. */
1217 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
1220 /* Even if there is no memory, treat as a failure so
1221 * the packet will get dropped.
1226 static bool list_has_sctp_addr(const struct list_head
*list
,
1227 union sctp_addr
*ipaddr
)
1229 struct sctp_transport
*addr
;
1231 list_for_each_entry(addr
, list
, transports
) {
1232 if (sctp_cmp_addr_exact(ipaddr
, &addr
->ipaddr
))
1238 /* A restart is occurring, check to make sure no new addresses
1239 * are being added as we may be under a takeover attack.
1241 static int sctp_sf_check_restart_addrs(const struct sctp_association
*new_asoc
,
1242 const struct sctp_association
*asoc
,
1243 struct sctp_chunk
*init
,
1244 sctp_cmd_seq_t
*commands
)
1246 struct sctp_transport
*new_addr
;
1249 /* Implementor's Guide - Section 5.2.2
1251 * Before responding the endpoint MUST check to see if the
1252 * unexpected INIT adds new addresses to the association. If new
1253 * addresses are added to the association, the endpoint MUST respond
1257 /* Search through all current addresses and make sure
1258 * we aren't adding any new ones.
1260 list_for_each_entry(new_addr
, &new_asoc
->peer
.transport_addr_list
,
1262 if (!list_has_sctp_addr(&asoc
->peer
.transport_addr_list
,
1263 &new_addr
->ipaddr
)) {
1264 sctp_sf_send_restart_abort(&new_addr
->ipaddr
, init
,
1271 /* Return success if all addresses were found. */
1275 /* Populate the verification/tie tags based on overlapping INIT
1278 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1280 static void sctp_tietags_populate(struct sctp_association
*new_asoc
,
1281 const struct sctp_association
*asoc
)
1283 switch (asoc
->state
) {
1285 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1287 case SCTP_STATE_COOKIE_WAIT
:
1288 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1289 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1290 new_asoc
->c
.peer_ttag
= 0;
1293 case SCTP_STATE_COOKIE_ECHOED
:
1294 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1295 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1296 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1299 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1300 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1303 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1304 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1308 /* Other parameters for the endpoint SHOULD be copied from the
1309 * existing parameters of the association (e.g. number of
1310 * outbound streams) into the INIT ACK and cookie.
1312 new_asoc
->rwnd
= asoc
->rwnd
;
1313 new_asoc
->c
.sinit_num_ostreams
= asoc
->c
.sinit_num_ostreams
;
1314 new_asoc
->c
.sinit_max_instreams
= asoc
->c
.sinit_max_instreams
;
1315 new_asoc
->c
.initial_tsn
= asoc
->c
.initial_tsn
;
1319 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1322 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1324 * Returns value representing action to be taken. These action values
1325 * correspond to Action/Description values in RFC 2960, Table 2.
1327 static char sctp_tietags_compare(struct sctp_association
*new_asoc
,
1328 const struct sctp_association
*asoc
)
1330 /* In this case, the peer may have restarted. */
1331 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1332 (asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) &&
1333 (asoc
->c
.my_vtag
== new_asoc
->c
.my_ttag
) &&
1334 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_ttag
))
1337 /* Collision case B. */
1338 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1339 ((asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) ||
1340 (0 == asoc
->c
.peer_vtag
))) {
1344 /* Collision case D. */
1345 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1346 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
))
1349 /* Collision case C. */
1350 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1351 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
) &&
1352 (0 == new_asoc
->c
.my_ttag
) &&
1353 (0 == new_asoc
->c
.peer_ttag
))
1356 /* No match to any of the special cases; discard this packet. */
1360 /* Common helper routine for both duplicate and simulataneous INIT
1363 static sctp_disposition_t
sctp_sf_do_unexpected_init(
1364 const struct sctp_endpoint
*ep
,
1365 const struct sctp_association
*asoc
,
1366 const sctp_subtype_t type
,
1367 void *arg
, sctp_cmd_seq_t
*commands
)
1369 sctp_disposition_t retval
;
1370 struct sctp_chunk
*chunk
= arg
;
1371 struct sctp_chunk
*repl
;
1372 struct sctp_association
*new_asoc
;
1373 struct sctp_chunk
*err_chunk
;
1374 struct sctp_packet
*packet
;
1375 sctp_unrecognized_param_t
*unk_param
;
1379 * An endpoint MUST NOT bundle INIT, INIT ACK or
1380 * SHUTDOWN COMPLETE with any other chunks.
1383 * Furthermore, we require that the receiver of an INIT chunk MUST
1384 * enforce these rules by silently discarding an arriving packet
1385 * with an INIT chunk that is bundled with other chunks.
1387 if (!chunk
->singleton
)
1388 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1390 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1393 if (chunk
->sctp_hdr
->vtag
!= 0)
1394 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
1396 /* Make sure that the INIT chunk has a valid length.
1397 * In this case, we generate a protocol violation since we have
1398 * an association established.
1400 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_init_chunk_t
)))
1401 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1403 /* Grab the INIT header. */
1404 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
1406 /* Tag the variable length parameters. */
1407 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
1409 /* Verify the INIT chunk before processing it. */
1411 if (!sctp_verify_init(asoc
, chunk
->chunk_hdr
->type
,
1412 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
1414 /* This chunk contains fatal error. It is to be discarded.
1415 * Send an ABORT, with causes if there is any.
1418 packet
= sctp_abort_pkt_new(ep
, asoc
, arg
,
1419 (__u8
*)(err_chunk
->chunk_hdr
) +
1420 sizeof(sctp_chunkhdr_t
),
1421 ntohs(err_chunk
->chunk_hdr
->length
) -
1422 sizeof(sctp_chunkhdr_t
));
1425 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
1426 SCTP_PACKET(packet
));
1427 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
1428 retval
= SCTP_DISPOSITION_CONSUME
;
1430 retval
= SCTP_DISPOSITION_NOMEM
;
1434 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
,
1439 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
1443 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
,
1444 sctp_scope(sctp_source(chunk
)), GFP_ATOMIC
) < 0)
1447 /* In the outbound INIT ACK the endpoint MUST copy its current
1448 * Verification Tag and Peers Verification tag into a reserved
1449 * place (local tie-tag and per tie-tag) within the state cookie.
1451 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
1453 (sctp_init_chunk_t
*)chunk
->chunk_hdr
,
1457 /* Make sure no new addresses are being added during the
1458 * restart. Do not do this check for COOKIE-WAIT state,
1459 * since there are no peer addresses to check against.
1460 * Upon return an ABORT will have been sent if needed.
1462 if (!sctp_state(asoc
, COOKIE_WAIT
)) {
1463 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
,
1465 retval
= SCTP_DISPOSITION_CONSUME
;
1470 sctp_tietags_populate(new_asoc
, asoc
);
1472 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1474 /* If there are errors need to be reported for unknown parameters,
1475 * make sure to reserve enough room in the INIT ACK for them.
1479 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
1480 sizeof(sctp_chunkhdr_t
);
1483 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
1487 /* If there are errors need to be reported for unknown parameters,
1488 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1492 /* Get the "Unrecognized parameter" parameter(s) out of the
1493 * ERROR chunk generated by sctp_verify_init(). Since the
1494 * error cause code for "unknown parameter" and the
1495 * "Unrecognized parameter" type is the same, we can
1496 * construct the parameters in INIT ACK by copying the
1497 * ERROR causes over.
1499 unk_param
= (sctp_unrecognized_param_t
*)
1500 ((__u8
*)(err_chunk
->chunk_hdr
) +
1501 sizeof(sctp_chunkhdr_t
));
1502 /* Replace the cause code with the "Unrecognized parameter"
1505 sctp_addto_chunk(repl
, len
, unk_param
);
1508 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
1509 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1512 * Note: After sending out INIT ACK with the State Cookie parameter,
1513 * "Z" MUST NOT allocate any resources for this new association.
1514 * Otherwise, "Z" will be vulnerable to resource attacks.
1516 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
1517 retval
= SCTP_DISPOSITION_CONSUME
;
1522 retval
= SCTP_DISPOSITION_NOMEM
;
1525 sctp_association_free(new_asoc
);
1528 sctp_chunk_free(err_chunk
);
1533 * Handle simultanous INIT.
1534 * This means we started an INIT and then we got an INIT request from
1537 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1538 * This usually indicates an initialization collision, i.e., each
1539 * endpoint is attempting, at about the same time, to establish an
1540 * association with the other endpoint.
1542 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1543 * endpoint MUST respond with an INIT ACK using the same parameters it
1544 * sent in its original INIT chunk (including its Verification Tag,
1545 * unchanged). These original parameters are combined with those from the
1546 * newly received INIT chunk. The endpoint shall also generate a State
1547 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1548 * INIT to calculate the State Cookie.
1550 * After that, the endpoint MUST NOT change its state, the T1-init
1551 * timer shall be left running and the corresponding TCB MUST NOT be
1552 * destroyed. The normal procedures for handling State Cookies when
1553 * a TCB exists will resolve the duplicate INITs to a single association.
1555 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1556 * its Tie-Tags with the Tag information of itself and its peer (see
1557 * section 5.2.2 for a description of the Tie-Tags).
1559 * Verification Tag: Not explicit, but an INIT can not have a valid
1560 * verification tag, so we skip the check.
1563 * (endpoint, asoc, chunk)
1566 * (asoc, reply_msg, msg_up, timers, counters)
1568 * The return value is the disposition of the chunk.
1570 sctp_disposition_t
sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint
*ep
,
1571 const struct sctp_association
*asoc
,
1572 const sctp_subtype_t type
,
1574 sctp_cmd_seq_t
*commands
)
1576 /* Call helper to do the real work for both simulataneous and
1577 * duplicate INIT chunk handling.
1579 return sctp_sf_do_unexpected_init(ep
, asoc
, type
, arg
, commands
);
1583 * Handle duplicated INIT messages. These are usually delayed
1586 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1587 * COOKIE-ECHOED and COOKIE-WAIT
1589 * Unless otherwise stated, upon reception of an unexpected INIT for
1590 * this association, the endpoint shall generate an INIT ACK with a
1591 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1592 * current Verification Tag and peer's Verification Tag into a reserved
1593 * place within the state cookie. We shall refer to these locations as
1594 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1595 * containing this INIT ACK MUST carry a Verification Tag value equal to
1596 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1597 * MUST contain a new Initiation Tag (randomly generated see Section
1598 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1599 * existing parameters of the association (e.g. number of outbound
1600 * streams) into the INIT ACK and cookie.
1602 * After sending out the INIT ACK, the endpoint shall take no further
1603 * actions, i.e., the existing association, including its current state,
1604 * and the corresponding TCB MUST NOT be changed.
1606 * Note: Only when a TCB exists and the association is not in a COOKIE-
1607 * WAIT state are the Tie-Tags populated. For a normal association INIT
1608 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1609 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1610 * State Cookie are populated as specified in section 5.2.1.
1612 * Verification Tag: Not specified, but an INIT has no way of knowing
1613 * what the verification tag could be, so we ignore it.
1616 * (endpoint, asoc, chunk)
1619 * (asoc, reply_msg, msg_up, timers, counters)
1621 * The return value is the disposition of the chunk.
1623 sctp_disposition_t
sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint
*ep
,
1624 const struct sctp_association
*asoc
,
1625 const sctp_subtype_t type
,
1627 sctp_cmd_seq_t
*commands
)
1629 /* Call helper to do the real work for both simulataneous and
1630 * duplicate INIT chunk handling.
1632 return sctp_sf_do_unexpected_init(ep
, asoc
, type
, arg
, commands
);
1637 * Unexpected INIT-ACK handler.
1640 * If an INIT ACK received by an endpoint in any state other than the
1641 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1642 * An unexpected INIT ACK usually indicates the processing of an old or
1643 * duplicated INIT chunk.
1645 sctp_disposition_t
sctp_sf_do_5_2_3_initack(const struct sctp_endpoint
*ep
,
1646 const struct sctp_association
*asoc
,
1647 const sctp_subtype_t type
,
1648 void *arg
, sctp_cmd_seq_t
*commands
)
1650 /* Per the above section, we'll discard the chunk if we have an
1651 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1653 if (ep
== sctp_sk((sctp_get_ctl_sock()))->ep
)
1654 return sctp_sf_ootb(ep
, asoc
, type
, arg
, commands
);
1656 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
1659 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1662 * A) In this case, the peer may have restarted.
1664 static sctp_disposition_t
sctp_sf_do_dupcook_a(const struct sctp_endpoint
*ep
,
1665 const struct sctp_association
*asoc
,
1666 struct sctp_chunk
*chunk
,
1667 sctp_cmd_seq_t
*commands
,
1668 struct sctp_association
*new_asoc
)
1670 sctp_init_chunk_t
*peer_init
;
1671 struct sctp_ulpevent
*ev
;
1672 struct sctp_chunk
*repl
;
1673 struct sctp_chunk
*err
;
1674 sctp_disposition_t disposition
;
1676 /* new_asoc is a brand-new association, so these are not yet
1677 * side effects--it is safe to run them here.
1679 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1681 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
1682 sctp_source(chunk
), peer_init
,
1686 /* Make sure no new addresses are being added during the
1687 * restart. Though this is a pretty complicated attack
1688 * since you'd have to get inside the cookie.
1690 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
, commands
)) {
1691 return SCTP_DISPOSITION_CONSUME
;
1694 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1695 * the peer has restarted (Action A), it MUST NOT setup a new
1696 * association but instead resend the SHUTDOWN ACK and send an ERROR
1697 * chunk with a "Cookie Received while Shutting Down" error cause to
1700 if (sctp_state(asoc
, SHUTDOWN_ACK_SENT
)) {
1701 disposition
= sctp_sf_do_9_2_reshutack(ep
, asoc
,
1702 SCTP_ST_CHUNK(chunk
->chunk_hdr
->type
),
1704 if (SCTP_DISPOSITION_NOMEM
== disposition
)
1707 err
= sctp_make_op_error(asoc
, chunk
,
1708 SCTP_ERROR_COOKIE_IN_SHUTDOWN
,
1711 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1714 return SCTP_DISPOSITION_CONSUME
;
1717 /* For now, fail any unsent/unacked data. Consider the optional
1718 * choice of resending of this data.
1720 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_OUTQUEUE
, SCTP_NULL());
1722 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1726 /* Report association restart to upper layer. */
1727 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_RESTART
, 0,
1728 new_asoc
->c
.sinit_num_ostreams
,
1729 new_asoc
->c
.sinit_max_instreams
,
1734 /* Update the content of current association. */
1735 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1736 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1737 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
1738 return SCTP_DISPOSITION_CONSUME
;
1741 sctp_chunk_free(repl
);
1743 return SCTP_DISPOSITION_NOMEM
;
1746 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1749 * B) In this case, both sides may be attempting to start an association
1750 * at about the same time but the peer endpoint started its INIT
1751 * after responding to the local endpoint's INIT
1753 /* This case represents an initialization collision. */
1754 static sctp_disposition_t
sctp_sf_do_dupcook_b(const struct sctp_endpoint
*ep
,
1755 const struct sctp_association
*asoc
,
1756 struct sctp_chunk
*chunk
,
1757 sctp_cmd_seq_t
*commands
,
1758 struct sctp_association
*new_asoc
)
1760 sctp_init_chunk_t
*peer_init
;
1761 struct sctp_chunk
*repl
;
1763 /* new_asoc is a brand-new association, so these are not yet
1764 * side effects--it is safe to run them here.
1766 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1767 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
1768 sctp_source(chunk
), peer_init
,
1772 /* Update the content of current association. */
1773 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1774 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1775 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1776 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
1777 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
1779 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1783 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1785 /* RFC 2960 5.1 Normal Establishment of an Association
1787 * D) IMPLEMENTATION NOTE: An implementation may choose to
1788 * send the Communication Up notification to the SCTP user
1789 * upon reception of a valid COOKIE ECHO chunk.
1791 * Sadly, this needs to be implemented as a side-effect, because
1792 * we are not guaranteed to have set the association id of the real
1793 * association and so these notifications need to be delayed until
1794 * the association id is allocated.
1797 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_CHANGE
, SCTP_U8(SCTP_COMM_UP
));
1799 /* Sockets API Draft Section 5.3.1.6
1800 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1801 * delivers this notification to inform the application that of the
1802 * peers requested adaptation layer.
1804 * This also needs to be done as a side effect for the same reason as
1807 if (asoc
->peer
.adaptation_ind
)
1808 sctp_add_cmd_sf(commands
, SCTP_CMD_ADAPTATION_IND
, SCTP_NULL());
1810 return SCTP_DISPOSITION_CONSUME
;
1813 return SCTP_DISPOSITION_NOMEM
;
1816 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1819 * C) In this case, the local endpoint's cookie has arrived late.
1820 * Before it arrived, the local endpoint sent an INIT and received an
1821 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1822 * but a new tag of its own.
1824 /* This case represents an initialization collision. */
1825 static sctp_disposition_t
sctp_sf_do_dupcook_c(const struct sctp_endpoint
*ep
,
1826 const struct sctp_association
*asoc
,
1827 struct sctp_chunk
*chunk
,
1828 sctp_cmd_seq_t
*commands
,
1829 struct sctp_association
*new_asoc
)
1831 /* The cookie should be silently discarded.
1832 * The endpoint SHOULD NOT change states and should leave
1833 * any timers running.
1835 return SCTP_DISPOSITION_DISCARD
;
1838 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1842 * D) When both local and remote tags match the endpoint should always
1843 * enter the ESTABLISHED state, if it has not already done so.
1845 /* This case represents an initialization collision. */
1846 static sctp_disposition_t
sctp_sf_do_dupcook_d(const struct sctp_endpoint
*ep
,
1847 const struct sctp_association
*asoc
,
1848 struct sctp_chunk
*chunk
,
1849 sctp_cmd_seq_t
*commands
,
1850 struct sctp_association
*new_asoc
)
1852 struct sctp_ulpevent
*ev
= NULL
, *ai_ev
= NULL
;
1853 struct sctp_chunk
*repl
;
1855 /* Clarification from Implementor's Guide:
1856 * D) When both local and remote tags match the endpoint should
1857 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1858 * It should stop any cookie timer that may be running and send
1862 /* Don't accidentally move back into established state. */
1863 if (asoc
->state
< SCTP_STATE_ESTABLISHED
) {
1864 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1865 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
1866 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1867 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1868 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
1869 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
,
1872 /* RFC 2960 5.1 Normal Establishment of an Association
1874 * D) IMPLEMENTATION NOTE: An implementation may choose
1875 * to send the Communication Up notification to the
1876 * SCTP user upon reception of a valid COOKIE
1879 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0,
1881 asoc
->c
.sinit_num_ostreams
,
1882 asoc
->c
.sinit_max_instreams
,
1887 /* Sockets API Draft Section 5.3.1.6
1888 * When a peer sends a Adaptation Layer Indication parameter,
1889 * SCTP delivers this notification to inform the application
1890 * that of the peers requested adaptation layer.
1892 if (asoc
->peer
.adaptation_ind
) {
1893 ai_ev
= sctp_ulpevent_make_adaptation_indication(asoc
,
1901 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1905 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1908 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1911 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1912 SCTP_ULPEVENT(ai_ev
));
1914 return SCTP_DISPOSITION_CONSUME
;
1918 sctp_ulpevent_free(ai_ev
);
1920 sctp_ulpevent_free(ev
);
1921 return SCTP_DISPOSITION_NOMEM
;
1925 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1926 * chunk was retransmitted and then delayed in the network.
1928 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1930 * Verification Tag: None. Do cookie validation.
1933 * (endpoint, asoc, chunk)
1936 * (asoc, reply_msg, msg_up, timers, counters)
1938 * The return value is the disposition of the chunk.
1940 sctp_disposition_t
sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint
*ep
,
1941 const struct sctp_association
*asoc
,
1942 const sctp_subtype_t type
,
1944 sctp_cmd_seq_t
*commands
)
1946 sctp_disposition_t retval
;
1947 struct sctp_chunk
*chunk
= arg
;
1948 struct sctp_association
*new_asoc
;
1951 struct sctp_chunk
*err_chk_p
;
1953 /* Make sure that the chunk has a valid length from the protocol
1954 * perspective. In this case check to make sure we have at least
1955 * enough for the chunk header. Cookie length verification is
1958 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
1959 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1962 /* "Decode" the chunk. We have no optional parameters so we
1963 * are in good shape.
1965 chunk
->subh
.cookie_hdr
= (struct sctp_signed_cookie
*)chunk
->skb
->data
;
1966 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
1967 sizeof(sctp_chunkhdr_t
)))
1970 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
1971 * of a duplicate COOKIE ECHO match the Verification Tags of the
1972 * current association, consider the State Cookie valid even if
1973 * the lifespan is exceeded.
1975 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
1980 case -SCTP_IERROR_NOMEM
:
1983 case -SCTP_IERROR_STALE_COOKIE
:
1984 sctp_send_stale_cookie_err(ep
, asoc
, chunk
, commands
,
1986 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1987 case -SCTP_IERROR_BAD_SIG
:
1989 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1993 /* Compare the tie_tag in cookie with the verification tag of
1994 * current association.
1996 action
= sctp_tietags_compare(new_asoc
, asoc
);
1999 case 'A': /* Association restart. */
2000 retval
= sctp_sf_do_dupcook_a(ep
, asoc
, chunk
, commands
,
2004 case 'B': /* Collision case B. */
2005 retval
= sctp_sf_do_dupcook_b(ep
, asoc
, chunk
, commands
,
2009 case 'C': /* Collision case C. */
2010 retval
= sctp_sf_do_dupcook_c(ep
, asoc
, chunk
, commands
,
2014 case 'D': /* Collision case D. */
2015 retval
= sctp_sf_do_dupcook_d(ep
, asoc
, chunk
, commands
,
2019 default: /* Discard packet for all others. */
2020 retval
= sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2024 /* Delete the tempory new association. */
2025 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
2026 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
2031 return SCTP_DISPOSITION_NOMEM
;
2035 * Process an ABORT. (SHUTDOWN-PENDING state)
2037 * See sctp_sf_do_9_1_abort().
2039 sctp_disposition_t
sctp_sf_shutdown_pending_abort(
2040 const struct sctp_endpoint
*ep
,
2041 const struct sctp_association
*asoc
,
2042 const sctp_subtype_t type
,
2044 sctp_cmd_seq_t
*commands
)
2046 struct sctp_chunk
*chunk
= arg
;
2048 if (!sctp_vtag_verify_either(chunk
, asoc
))
2049 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2051 /* Make sure that the ABORT chunk has a valid length.
2052 * Since this is an ABORT chunk, we have to discard it
2053 * because of the following text:
2054 * RFC 2960, Section 3.3.7
2055 * If an endpoint receives an ABORT with a format error or for an
2056 * association that doesn't exist, it MUST silently discard it.
2057 * Becasue the length is "invalid", we can't really discard just
2058 * as we do not know its true length. So, to be safe, discard the
2061 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2062 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2064 /* ADD-IP: Special case for ABORT chunks
2065 * F4) One special consideration is that ABORT Chunks arriving
2066 * destined to the IP address being deleted MUST be
2067 * ignored (see Section 5.3.1 for further details).
2069 if (SCTP_ADDR_DEL
==
2070 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2071 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
2073 return __sctp_sf_do_9_1_abort(ep
, asoc
, type
, arg
, commands
);
2077 * Process an ABORT. (SHUTDOWN-SENT state)
2079 * See sctp_sf_do_9_1_abort().
2081 sctp_disposition_t
sctp_sf_shutdown_sent_abort(const struct sctp_endpoint
*ep
,
2082 const struct sctp_association
*asoc
,
2083 const sctp_subtype_t type
,
2085 sctp_cmd_seq_t
*commands
)
2087 struct sctp_chunk
*chunk
= arg
;
2089 if (!sctp_vtag_verify_either(chunk
, asoc
))
2090 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2092 /* Make sure that the ABORT chunk has a valid length.
2093 * Since this is an ABORT chunk, we have to discard it
2094 * because of the following text:
2095 * RFC 2960, Section 3.3.7
2096 * If an endpoint receives an ABORT with a format error or for an
2097 * association that doesn't exist, it MUST silently discard it.
2098 * Becasue the length is "invalid", we can't really discard just
2099 * as we do not know its true length. So, to be safe, discard the
2102 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2103 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2105 /* ADD-IP: Special case for ABORT chunks
2106 * F4) One special consideration is that ABORT Chunks arriving
2107 * destined to the IP address being deleted MUST be
2108 * ignored (see Section 5.3.1 for further details).
2110 if (SCTP_ADDR_DEL
==
2111 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2112 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
2114 /* Stop the T2-shutdown timer. */
2115 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2116 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2118 /* Stop the T5-shutdown guard timer. */
2119 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2120 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
2122 return __sctp_sf_do_9_1_abort(ep
, asoc
, type
, arg
, commands
);
2126 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2128 * See sctp_sf_do_9_1_abort().
2130 sctp_disposition_t
sctp_sf_shutdown_ack_sent_abort(
2131 const struct sctp_endpoint
*ep
,
2132 const struct sctp_association
*asoc
,
2133 const sctp_subtype_t type
,
2135 sctp_cmd_seq_t
*commands
)
2137 /* The same T2 timer, so we should be able to use
2138 * common function with the SHUTDOWN-SENT state.
2140 return sctp_sf_shutdown_sent_abort(ep
, asoc
, type
, arg
, commands
);
2144 * Handle an Error received in COOKIE_ECHOED state.
2146 * Only handle the error type of stale COOKIE Error, the other errors will
2150 * (endpoint, asoc, chunk)
2153 * (asoc, reply_msg, msg_up, timers, counters)
2155 * The return value is the disposition of the chunk.
2157 sctp_disposition_t
sctp_sf_cookie_echoed_err(const struct sctp_endpoint
*ep
,
2158 const struct sctp_association
*asoc
,
2159 const sctp_subtype_t type
,
2161 sctp_cmd_seq_t
*commands
)
2163 struct sctp_chunk
*chunk
= arg
;
2166 if (!sctp_vtag_verify(chunk
, asoc
))
2167 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2169 /* Make sure that the ERROR chunk has a valid length.
2170 * The parameter walking depends on this as well.
2172 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
2173 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2176 /* Process the error here */
2177 sctp_walk_errors(err
, chunk
->chunk_hdr
) {
2178 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
)
2179 return sctp_sf_do_5_2_6_stale(ep
, asoc
, type
,
2183 /* It is possible to have malformed error causes, and that
2184 * will cause us to end the walk early. However, since
2185 * we are discarding the packet, there should be no adverse
2188 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2192 * Handle a Stale COOKIE Error
2194 * Section: 5.2.6 Handle Stale COOKIE Error
2195 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2196 * one of the following three alternatives.
2198 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2199 * Preservative parameter requesting an extension to the lifetime of
2200 * the State Cookie. When calculating the time extension, an
2201 * implementation SHOULD use the RTT information measured based on the
2202 * previous COOKIE ECHO / ERROR exchange, and should add no more
2203 * than 1 second beyond the measured RTT, due to long State Cookie
2204 * lifetimes making the endpoint more subject to a replay attack.
2206 * Verification Tag: Not explicit, but safe to ignore.
2209 * (endpoint, asoc, chunk)
2212 * (asoc, reply_msg, msg_up, timers, counters)
2214 * The return value is the disposition of the chunk.
2216 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(const struct sctp_endpoint
*ep
,
2217 const struct sctp_association
*asoc
,
2218 const sctp_subtype_t type
,
2220 sctp_cmd_seq_t
*commands
)
2222 struct sctp_chunk
*chunk
= arg
;
2224 sctp_cookie_preserve_param_t bht
;
2226 struct sctp_chunk
*reply
;
2227 struct sctp_bind_addr
*bp
;
2228 int attempts
= asoc
->init_err_counter
+ 1;
2230 if (attempts
> asoc
->max_init_attempts
) {
2231 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
2232 SCTP_ERROR(ETIMEDOUT
));
2233 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2234 SCTP_PERR(SCTP_ERROR_STALE_COOKIE
));
2235 return SCTP_DISPOSITION_DELETE_TCB
;
2238 err
= (sctp_errhdr_t
*)(chunk
->skb
->data
);
2240 /* When calculating the time extension, an implementation
2241 * SHOULD use the RTT information measured based on the
2242 * previous COOKIE ECHO / ERROR exchange, and should add no
2243 * more than 1 second beyond the measured RTT, due to long
2244 * State Cookie lifetimes making the endpoint more subject to
2246 * Measure of Staleness's unit is usec. (1/1000000 sec)
2247 * Suggested Cookie Life-span Increment's unit is msec.
2249 * In general, if you use the suggested cookie life, the value
2250 * found in the field of measure of staleness should be doubled
2251 * to give ample time to retransmit the new cookie and thus
2252 * yield a higher probability of success on the reattempt.
2254 stale
= ntohl(*(__be32
*)((u8
*)err
+ sizeof(sctp_errhdr_t
)));
2255 stale
= (stale
* 2) / 1000;
2257 bht
.param_hdr
.type
= SCTP_PARAM_COOKIE_PRESERVATIVE
;
2258 bht
.param_hdr
.length
= htons(sizeof(bht
));
2259 bht
.lifespan_increment
= htonl(stale
);
2261 /* Build that new INIT chunk. */
2262 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
2263 reply
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, sizeof(bht
));
2267 sctp_addto_chunk(reply
, sizeof(bht
), &bht
);
2269 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2270 sctp_add_cmd_sf(commands
, SCTP_CMD_CLEAR_INIT_TAG
, SCTP_NULL());
2272 /* Stop pending T3-rtx and heartbeat timers */
2273 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
2274 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
2276 /* Delete non-primary peer ip addresses since we are transitioning
2277 * back to the COOKIE-WAIT state
2279 sctp_add_cmd_sf(commands
, SCTP_CMD_DEL_NON_PRIMARY
, SCTP_NULL());
2281 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2284 sctp_add_cmd_sf(commands
, SCTP_CMD_T1_RETRAN
,
2285 SCTP_TRANSPORT(asoc
->peer
.primary_path
));
2287 /* Cast away the const modifier, as we want to just
2288 * rerun it through as a sideffect.
2290 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_INC
, SCTP_NULL());
2292 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2293 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
2294 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2295 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
2296 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
2297 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2299 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2301 return SCTP_DISPOSITION_CONSUME
;
2304 return SCTP_DISPOSITION_NOMEM
;
2311 * After checking the Verification Tag, the receiving endpoint shall
2312 * remove the association from its record, and shall report the
2313 * termination to its upper layer.
2315 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2316 * B) Rules for packet carrying ABORT:
2318 * - The endpoint shall always fill in the Verification Tag field of the
2319 * outbound packet with the destination endpoint's tag value if it
2322 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2323 * MUST follow the procedure described in Section 8.4.
2325 * - The receiver MUST accept the packet if the Verification Tag
2326 * matches either its own tag, OR the tag of its peer. Otherwise, the
2327 * receiver MUST silently discard the packet and take no further
2331 * (endpoint, asoc, chunk)
2334 * (asoc, reply_msg, msg_up, timers, counters)
2336 * The return value is the disposition of the chunk.
2338 sctp_disposition_t
sctp_sf_do_9_1_abort(const struct sctp_endpoint
*ep
,
2339 const struct sctp_association
*asoc
,
2340 const sctp_subtype_t type
,
2342 sctp_cmd_seq_t
*commands
)
2344 struct sctp_chunk
*chunk
= arg
;
2346 if (!sctp_vtag_verify_either(chunk
, asoc
))
2347 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2349 /* Make sure that the ABORT chunk has a valid length.
2350 * Since this is an ABORT chunk, we have to discard it
2351 * because of the following text:
2352 * RFC 2960, Section 3.3.7
2353 * If an endpoint receives an ABORT with a format error or for an
2354 * association that doesn't exist, it MUST silently discard it.
2355 * Becasue the length is "invalid", we can't really discard just
2356 * as we do not know its true length. So, to be safe, discard the
2359 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2360 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2362 /* ADD-IP: Special case for ABORT chunks
2363 * F4) One special consideration is that ABORT Chunks arriving
2364 * destined to the IP address being deleted MUST be
2365 * ignored (see Section 5.3.1 for further details).
2367 if (SCTP_ADDR_DEL
==
2368 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2369 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
2371 return __sctp_sf_do_9_1_abort(ep
, asoc
, type
, arg
, commands
);
2374 static sctp_disposition_t
__sctp_sf_do_9_1_abort(const struct sctp_endpoint
*ep
,
2375 const struct sctp_association
*asoc
,
2376 const sctp_subtype_t type
,
2378 sctp_cmd_seq_t
*commands
)
2380 struct sctp_chunk
*chunk
= arg
;
2382 __be16 error
= SCTP_ERROR_NO_ERROR
;
2384 /* See if we have an error cause code in the chunk. */
2385 len
= ntohs(chunk
->chunk_hdr
->length
);
2386 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2387 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2389 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(ECONNRESET
));
2390 /* ASSOC_FAILED will DELETE_TCB. */
2391 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
, SCTP_PERR(error
));
2392 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
2393 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
2395 return SCTP_DISPOSITION_ABORT
;
2399 * Process an ABORT. (COOKIE-WAIT state)
2401 * See sctp_sf_do_9_1_abort() above.
2403 sctp_disposition_t
sctp_sf_cookie_wait_abort(const struct sctp_endpoint
*ep
,
2404 const struct sctp_association
*asoc
,
2405 const sctp_subtype_t type
,
2407 sctp_cmd_seq_t
*commands
)
2409 struct sctp_chunk
*chunk
= arg
;
2411 __be16 error
= SCTP_ERROR_NO_ERROR
;
2413 if (!sctp_vtag_verify_either(chunk
, asoc
))
2414 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2416 /* Make sure that the ABORT chunk has a valid length.
2417 * Since this is an ABORT chunk, we have to discard it
2418 * because of the following text:
2419 * RFC 2960, Section 3.3.7
2420 * If an endpoint receives an ABORT with a format error or for an
2421 * association that doesn't exist, it MUST silently discard it.
2422 * Becasue the length is "invalid", we can't really discard just
2423 * as we do not know its true length. So, to be safe, discard the
2426 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2427 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2429 /* See if we have an error cause code in the chunk. */
2430 len
= ntohs(chunk
->chunk_hdr
->length
);
2431 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2432 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2434 return sctp_stop_t1_and_abort(commands
, error
, ECONNREFUSED
, asoc
,
2439 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2441 sctp_disposition_t
sctp_sf_cookie_wait_icmp_abort(const struct sctp_endpoint
*ep
,
2442 const struct sctp_association
*asoc
,
2443 const sctp_subtype_t type
,
2445 sctp_cmd_seq_t
*commands
)
2447 return sctp_stop_t1_and_abort(commands
, SCTP_ERROR_NO_ERROR
,
2449 (struct sctp_transport
*)arg
);
2453 * Process an ABORT. (COOKIE-ECHOED state)
2455 sctp_disposition_t
sctp_sf_cookie_echoed_abort(const struct sctp_endpoint
*ep
,
2456 const struct sctp_association
*asoc
,
2457 const sctp_subtype_t type
,
2459 sctp_cmd_seq_t
*commands
)
2461 /* There is a single T1 timer, so we should be able to use
2462 * common function with the COOKIE-WAIT state.
2464 return sctp_sf_cookie_wait_abort(ep
, asoc
, type
, arg
, commands
);
2468 * Stop T1 timer and abort association with "INIT failed".
2470 * This is common code called by several sctp_sf_*_abort() functions above.
2472 static sctp_disposition_t
sctp_stop_t1_and_abort(sctp_cmd_seq_t
*commands
,
2473 __be16 error
, int sk_err
,
2474 const struct sctp_association
*asoc
,
2475 struct sctp_transport
*transport
)
2477 SCTP_DEBUG_PRINTK("ABORT received (INIT).\n");
2478 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2479 SCTP_STATE(SCTP_STATE_CLOSED
));
2480 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
2481 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2482 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2483 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(sk_err
));
2484 /* CMD_INIT_FAILED will DELETE_TCB. */
2485 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2487 return SCTP_DISPOSITION_ABORT
;
2491 * sctp_sf_do_9_2_shut
2494 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2495 * - enter the SHUTDOWN-RECEIVED state,
2497 * - stop accepting new data from its SCTP user
2499 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2500 * that all its outstanding DATA chunks have been received by the
2503 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2504 * send a SHUTDOWN in response to a ULP request. And should discard
2505 * subsequent SHUTDOWN chunks.
2507 * If there are still outstanding DATA chunks left, the SHUTDOWN
2508 * receiver shall continue to follow normal data transmission
2509 * procedures defined in Section 6 until all outstanding DATA chunks
2510 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2511 * new data from its SCTP user.
2513 * Verification Tag: 8.5 Verification Tag [Normal verification]
2516 * (endpoint, asoc, chunk)
2519 * (asoc, reply_msg, msg_up, timers, counters)
2521 * The return value is the disposition of the chunk.
2523 sctp_disposition_t
sctp_sf_do_9_2_shutdown(const struct sctp_endpoint
*ep
,
2524 const struct sctp_association
*asoc
,
2525 const sctp_subtype_t type
,
2527 sctp_cmd_seq_t
*commands
)
2529 struct sctp_chunk
*chunk
= arg
;
2530 sctp_shutdownhdr_t
*sdh
;
2531 sctp_disposition_t disposition
;
2532 struct sctp_ulpevent
*ev
;
2535 if (!sctp_vtag_verify(chunk
, asoc
))
2536 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2538 /* Make sure that the SHUTDOWN chunk has a valid length. */
2539 if (!sctp_chunk_length_valid(chunk
,
2540 sizeof(struct sctp_shutdown_chunk_t
)))
2541 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2544 /* Convert the elaborate header. */
2545 sdh
= (sctp_shutdownhdr_t
*)chunk
->skb
->data
;
2546 skb_pull(chunk
->skb
, sizeof(sctp_shutdownhdr_t
));
2547 chunk
->subh
.shutdown_hdr
= sdh
;
2548 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2550 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2551 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn
);
2552 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc
->ctsn_ack_point
);
2553 return SCTP_DISPOSITION_DISCARD
;
2556 /* If Cumulative TSN Ack beyond the max tsn currently
2557 * send, terminating the association and respond to the
2558 * sender with an ABORT.
2560 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2561 return sctp_sf_violation_ctsn(ep
, asoc
, type
, arg
, commands
);
2563 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2564 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2565 * inform the application that it should cease sending data.
2567 ev
= sctp_ulpevent_make_shutdown_event(asoc
, 0, GFP_ATOMIC
);
2569 disposition
= SCTP_DISPOSITION_NOMEM
;
2572 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
2574 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2575 * - enter the SHUTDOWN-RECEIVED state,
2576 * - stop accepting new data from its SCTP user
2578 * [This is implicit in the new state.]
2580 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2581 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED
));
2582 disposition
= SCTP_DISPOSITION_CONSUME
;
2584 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
2585 disposition
= sctp_sf_do_9_2_shutdown_ack(ep
, asoc
, type
,
2589 if (SCTP_DISPOSITION_NOMEM
== disposition
)
2592 /* - verify, by checking the Cumulative TSN Ack field of the
2593 * chunk, that all its outstanding DATA chunks have been
2594 * received by the SHUTDOWN sender.
2596 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2597 SCTP_BE32(chunk
->subh
.shutdown_hdr
->cum_tsn_ack
));
2604 * sctp_sf_do_9_2_shut_ctsn
2606 * Once an endpoint has reached the SHUTDOWN-RECEIVED state,
2607 * it MUST NOT send a SHUTDOWN in response to a ULP request.
2608 * The Cumulative TSN Ack of the received SHUTDOWN chunk
2609 * MUST be processed.
2611 sctp_disposition_t
sctp_sf_do_9_2_shut_ctsn(const struct sctp_endpoint
*ep
,
2612 const struct sctp_association
*asoc
,
2613 const sctp_subtype_t type
,
2615 sctp_cmd_seq_t
*commands
)
2617 struct sctp_chunk
*chunk
= arg
;
2618 sctp_shutdownhdr_t
*sdh
;
2621 if (!sctp_vtag_verify(chunk
, asoc
))
2622 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2624 /* Make sure that the SHUTDOWN chunk has a valid length. */
2625 if (!sctp_chunk_length_valid(chunk
,
2626 sizeof(struct sctp_shutdown_chunk_t
)))
2627 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2630 sdh
= (sctp_shutdownhdr_t
*)chunk
->skb
->data
;
2631 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2633 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2634 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn
);
2635 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc
->ctsn_ack_point
);
2636 return SCTP_DISPOSITION_DISCARD
;
2639 /* If Cumulative TSN Ack beyond the max tsn currently
2640 * send, terminating the association and respond to the
2641 * sender with an ABORT.
2643 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2644 return sctp_sf_violation_ctsn(ep
, asoc
, type
, arg
, commands
);
2646 /* verify, by checking the Cumulative TSN Ack field of the
2647 * chunk, that all its outstanding DATA chunks have been
2648 * received by the SHUTDOWN sender.
2650 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2651 SCTP_BE32(sdh
->cum_tsn_ack
));
2653 return SCTP_DISPOSITION_CONSUME
;
2657 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2658 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2659 * transport addresses (either in the IP addresses or in the INIT chunk)
2660 * that belong to this association, it should discard the INIT chunk and
2661 * retransmit the SHUTDOWN ACK chunk.
2663 sctp_disposition_t
sctp_sf_do_9_2_reshutack(const struct sctp_endpoint
*ep
,
2664 const struct sctp_association
*asoc
,
2665 const sctp_subtype_t type
,
2667 sctp_cmd_seq_t
*commands
)
2669 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
2670 struct sctp_chunk
*reply
;
2672 /* Make sure that the chunk has a valid length */
2673 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
2674 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2677 /* Since we are not going to really process this INIT, there
2678 * is no point in verifying chunk boundries. Just generate
2681 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
2685 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2686 * the T2-SHUTDOWN timer.
2688 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
2690 /* and restart the T2-shutdown timer. */
2691 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2692 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2694 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2696 return SCTP_DISPOSITION_CONSUME
;
2698 return SCTP_DISPOSITION_NOMEM
;
2702 * sctp_sf_do_ecn_cwr
2704 * Section: Appendix A: Explicit Congestion Notification
2708 * RFC 2481 details a specific bit for a sender to send in the header of
2709 * its next outbound TCP segment to indicate to its peer that it has
2710 * reduced its congestion window. This is termed the CWR bit. For
2711 * SCTP the same indication is made by including the CWR chunk.
2712 * This chunk contains one data element, i.e. the TSN number that
2713 * was sent in the ECNE chunk. This element represents the lowest
2714 * TSN number in the datagram that was originally marked with the
2717 * Verification Tag: 8.5 Verification Tag [Normal verification]
2719 * (endpoint, asoc, chunk)
2722 * (asoc, reply_msg, msg_up, timers, counters)
2724 * The return value is the disposition of the chunk.
2726 sctp_disposition_t
sctp_sf_do_ecn_cwr(const struct sctp_endpoint
*ep
,
2727 const struct sctp_association
*asoc
,
2728 const sctp_subtype_t type
,
2730 sctp_cmd_seq_t
*commands
)
2733 struct sctp_chunk
*chunk
= arg
;
2736 if (!sctp_vtag_verify(chunk
, asoc
))
2737 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2739 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2740 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2743 cwr
= (sctp_cwrhdr_t
*) chunk
->skb
->data
;
2744 skb_pull(chunk
->skb
, sizeof(sctp_cwrhdr_t
));
2746 lowest_tsn
= ntohl(cwr
->lowest_tsn
);
2748 /* Does this CWR ack the last sent congestion notification? */
2749 if (TSN_lte(asoc
->last_ecne_tsn
, lowest_tsn
)) {
2750 /* Stop sending ECNE. */
2751 sctp_add_cmd_sf(commands
,
2753 SCTP_U32(lowest_tsn
));
2755 return SCTP_DISPOSITION_CONSUME
;
2761 * Section: Appendix A: Explicit Congestion Notification
2765 * RFC 2481 details a specific bit for a receiver to send back in its
2766 * TCP acknowledgements to notify the sender of the Congestion
2767 * Experienced (CE) bit having arrived from the network. For SCTP this
2768 * same indication is made by including the ECNE chunk. This chunk
2769 * contains one data element, i.e. the lowest TSN associated with the IP
2770 * datagram marked with the CE bit.....
2772 * Verification Tag: 8.5 Verification Tag [Normal verification]
2774 * (endpoint, asoc, chunk)
2777 * (asoc, reply_msg, msg_up, timers, counters)
2779 * The return value is the disposition of the chunk.
2781 sctp_disposition_t
sctp_sf_do_ecne(const struct sctp_endpoint
*ep
,
2782 const struct sctp_association
*asoc
,
2783 const sctp_subtype_t type
,
2785 sctp_cmd_seq_t
*commands
)
2787 sctp_ecnehdr_t
*ecne
;
2788 struct sctp_chunk
*chunk
= arg
;
2790 if (!sctp_vtag_verify(chunk
, asoc
))
2791 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2793 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2794 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2797 ecne
= (sctp_ecnehdr_t
*) chunk
->skb
->data
;
2798 skb_pull(chunk
->skb
, sizeof(sctp_ecnehdr_t
));
2800 /* If this is a newer ECNE than the last CWR packet we sent out */
2801 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_ECNE
,
2802 SCTP_U32(ntohl(ecne
->lowest_tsn
)));
2804 return SCTP_DISPOSITION_CONSUME
;
2808 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2810 * The SCTP endpoint MUST always acknowledge the reception of each valid
2813 * The guidelines on delayed acknowledgement algorithm specified in
2814 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2815 * acknowledgement SHOULD be generated for at least every second packet
2816 * (not every second DATA chunk) received, and SHOULD be generated within
2817 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2818 * situations it may be beneficial for an SCTP transmitter to be more
2819 * conservative than the algorithms detailed in this document allow.
2820 * However, an SCTP transmitter MUST NOT be more aggressive than the
2821 * following algorithms allow.
2823 * A SCTP receiver MUST NOT generate more than one SACK for every
2824 * incoming packet, other than to update the offered window as the
2825 * receiving application consumes new data.
2827 * Verification Tag: 8.5 Verification Tag [Normal verification]
2830 * (endpoint, asoc, chunk)
2833 * (asoc, reply_msg, msg_up, timers, counters)
2835 * The return value is the disposition of the chunk.
2837 sctp_disposition_t
sctp_sf_eat_data_6_2(const struct sctp_endpoint
*ep
,
2838 const struct sctp_association
*asoc
,
2839 const sctp_subtype_t type
,
2841 sctp_cmd_seq_t
*commands
)
2843 struct sctp_chunk
*chunk
= arg
;
2844 sctp_arg_t force
= SCTP_NOFORCE();
2847 if (!sctp_vtag_verify(chunk
, asoc
)) {
2848 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
2850 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2853 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
2854 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2857 error
= sctp_eat_data(asoc
, chunk
, commands
);
2859 case SCTP_IERROR_NO_ERROR
:
2861 case SCTP_IERROR_HIGH_TSN
:
2862 case SCTP_IERROR_BAD_STREAM
:
2863 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
2864 goto discard_noforce
;
2865 case SCTP_IERROR_DUP_TSN
:
2866 case SCTP_IERROR_IGNORE_TSN
:
2867 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
2869 case SCTP_IERROR_NO_DATA
:
2871 case SCTP_IERROR_PROTO_VIOLATION
:
2872 return sctp_sf_abort_violation(ep
, asoc
, chunk
, commands
,
2873 (u8
*)chunk
->subh
.data_hdr
, sizeof(sctp_datahdr_t
));
2878 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_SACK_IMM
)
2879 force
= SCTP_FORCE();
2881 if (asoc
->autoclose
) {
2882 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2883 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
2886 /* If this is the last chunk in a packet, we need to count it
2887 * toward sack generation. Note that we need to SACK every
2888 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2889 * THEM. We elect to NOT generate SACK's if the chunk fails
2890 * the verification tag test.
2892 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2894 * The SCTP endpoint MUST always acknowledge the reception of
2895 * each valid DATA chunk.
2897 * The guidelines on delayed acknowledgement algorithm
2898 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2899 * Specifically, an acknowledgement SHOULD be generated for at
2900 * least every second packet (not every second DATA chunk)
2901 * received, and SHOULD be generated within 200 ms of the
2902 * arrival of any unacknowledged DATA chunk. In some
2903 * situations it may be beneficial for an SCTP transmitter to
2904 * be more conservative than the algorithms detailed in this
2905 * document allow. However, an SCTP transmitter MUST NOT be
2906 * more aggressive than the following algorithms allow.
2908 if (chunk
->end_of_packet
)
2909 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, force
);
2911 return SCTP_DISPOSITION_CONSUME
;
2914 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2916 * When a packet arrives with duplicate DATA chunk(s) and with
2917 * no new DATA chunk(s), the endpoint MUST immediately send a
2918 * SACK with no delay. If a packet arrives with duplicate
2919 * DATA chunk(s) bundled with new DATA chunks, the endpoint
2920 * MAY immediately send a SACK. Normally receipt of duplicate
2921 * DATA chunks will occur when the original SACK chunk was lost
2922 * and the peer's RTO has expired. The duplicate TSN number(s)
2923 * SHOULD be reported in the SACK as duplicate.
2925 /* In our case, we split the MAY SACK advice up whether or not
2926 * the last chunk is a duplicate.'
2928 if (chunk
->end_of_packet
)
2929 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
2930 return SCTP_DISPOSITION_DISCARD
;
2933 if (chunk
->end_of_packet
)
2934 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, force
);
2936 return SCTP_DISPOSITION_DISCARD
;
2938 return SCTP_DISPOSITION_CONSUME
;
2943 * sctp_sf_eat_data_fast_4_4
2946 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
2947 * DATA chunks without delay.
2949 * Verification Tag: 8.5 Verification Tag [Normal verification]
2951 * (endpoint, asoc, chunk)
2954 * (asoc, reply_msg, msg_up, timers, counters)
2956 * The return value is the disposition of the chunk.
2958 sctp_disposition_t
sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint
*ep
,
2959 const struct sctp_association
*asoc
,
2960 const sctp_subtype_t type
,
2962 sctp_cmd_seq_t
*commands
)
2964 struct sctp_chunk
*chunk
= arg
;
2967 if (!sctp_vtag_verify(chunk
, asoc
)) {
2968 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
2970 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2973 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
2974 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2977 error
= sctp_eat_data(asoc
, chunk
, commands
);
2979 case SCTP_IERROR_NO_ERROR
:
2980 case SCTP_IERROR_HIGH_TSN
:
2981 case SCTP_IERROR_DUP_TSN
:
2982 case SCTP_IERROR_IGNORE_TSN
:
2983 case SCTP_IERROR_BAD_STREAM
:
2985 case SCTP_IERROR_NO_DATA
:
2987 case SCTP_IERROR_PROTO_VIOLATION
:
2988 return sctp_sf_abort_violation(ep
, asoc
, chunk
, commands
,
2989 (u8
*)chunk
->subh
.data_hdr
, sizeof(sctp_datahdr_t
));
2994 /* Go a head and force a SACK, since we are shutting down. */
2996 /* Implementor's Guide.
2998 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
2999 * respond to each received packet containing one or more DATA chunk(s)
3000 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3002 if (chunk
->end_of_packet
) {
3003 /* We must delay the chunk creation since the cumulative
3004 * TSN has not been updated yet.
3006 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3007 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3008 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3009 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3013 return SCTP_DISPOSITION_CONSUME
;
3017 * Section: 6.2 Processing a Received SACK
3018 * D) Any time a SACK arrives, the endpoint performs the following:
3020 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
3021 * then drop the SACK. Since Cumulative TSN Ack is monotonically
3022 * increasing, a SACK whose Cumulative TSN Ack is less than the
3023 * Cumulative TSN Ack Point indicates an out-of-order SACK.
3025 * ii) Set rwnd equal to the newly received a_rwnd minus the number
3026 * of bytes still outstanding after processing the Cumulative TSN Ack
3027 * and the Gap Ack Blocks.
3029 * iii) If the SACK is missing a TSN that was previously
3030 * acknowledged via a Gap Ack Block (e.g., the data receiver
3031 * reneged on the data), then mark the corresponding DATA chunk
3032 * as available for retransmit: Mark it as missing for fast
3033 * retransmit as described in Section 7.2.4 and if no retransmit
3034 * timer is running for the destination address to which the DATA
3035 * chunk was originally transmitted, then T3-rtx is started for
3036 * that destination address.
3038 * Verification Tag: 8.5 Verification Tag [Normal verification]
3041 * (endpoint, asoc, chunk)
3044 * (asoc, reply_msg, msg_up, timers, counters)
3046 * The return value is the disposition of the chunk.
3048 sctp_disposition_t
sctp_sf_eat_sack_6_2(const struct sctp_endpoint
*ep
,
3049 const struct sctp_association
*asoc
,
3050 const sctp_subtype_t type
,
3052 sctp_cmd_seq_t
*commands
)
3054 struct sctp_chunk
*chunk
= arg
;
3055 sctp_sackhdr_t
*sackh
;
3058 if (!sctp_vtag_verify(chunk
, asoc
))
3059 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3061 /* Make sure that the SACK chunk has a valid length. */
3062 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_sack_chunk_t
)))
3063 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3066 /* Pull the SACK chunk from the data buffer */
3067 sackh
= sctp_sm_pull_sack(chunk
);
3068 /* Was this a bogus SACK? */
3070 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3071 chunk
->subh
.sack_hdr
= sackh
;
3072 ctsn
= ntohl(sackh
->cum_tsn_ack
);
3074 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
3075 * Ack Point, then drop the SACK. Since Cumulative TSN
3076 * Ack is monotonically increasing, a SACK whose
3077 * Cumulative TSN Ack is less than the Cumulative TSN Ack
3078 * Point indicates an out-of-order SACK.
3080 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
3081 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn
);
3082 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc
->ctsn_ack_point
);
3083 return SCTP_DISPOSITION_DISCARD
;
3086 /* If Cumulative TSN Ack beyond the max tsn currently
3087 * send, terminating the association and respond to the
3088 * sender with an ABORT.
3090 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
3091 return sctp_sf_violation_ctsn(ep
, asoc
, type
, arg
, commands
);
3093 /* Return this SACK for further processing. */
3094 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_SACK
, SCTP_SACKH(sackh
));
3096 /* Note: We do the rest of the work on the PROCESS_SACK
3099 return SCTP_DISPOSITION_CONSUME
;
3103 * Generate an ABORT in response to a packet.
3105 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
3107 * 8) The receiver should respond to the sender of the OOTB packet with
3108 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3109 * MUST fill in the Verification Tag field of the outbound packet
3110 * with the value found in the Verification Tag field of the OOTB
3111 * packet and set the T-bit in the Chunk Flags to indicate that the
3112 * Verification Tag is reflected. After sending this ABORT, the
3113 * receiver of the OOTB packet shall discard the OOTB packet and take
3114 * no further action.
3118 * The return value is the disposition of the chunk.
3120 static sctp_disposition_t
sctp_sf_tabort_8_4_8(const struct sctp_endpoint
*ep
,
3121 const struct sctp_association
*asoc
,
3122 const sctp_subtype_t type
,
3124 sctp_cmd_seq_t
*commands
)
3126 struct sctp_packet
*packet
= NULL
;
3127 struct sctp_chunk
*chunk
= arg
;
3128 struct sctp_chunk
*abort
;
3130 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
3133 /* Make an ABORT. The T bit will be set if the asoc
3136 abort
= sctp_make_abort(asoc
, chunk
, 0);
3138 sctp_ootb_pkt_free(packet
);
3139 return SCTP_DISPOSITION_NOMEM
;
3142 /* Reflect vtag if T-Bit is set */
3143 if (sctp_test_T_bit(abort
))
3144 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3146 /* Set the skb to the belonging sock for accounting. */
3147 abort
->skb
->sk
= ep
->base
.sk
;
3149 sctp_packet_append_chunk(packet
, abort
);
3151 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3152 SCTP_PACKET(packet
));
3154 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
3156 sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3157 return SCTP_DISPOSITION_CONSUME
;
3160 return SCTP_DISPOSITION_NOMEM
;
3164 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
3165 * event as ULP notification for each cause included in the chunk.
3167 * API 5.3.1.3 - SCTP_REMOTE_ERROR
3169 * The return value is the disposition of the chunk.
3171 sctp_disposition_t
sctp_sf_operr_notify(const struct sctp_endpoint
*ep
,
3172 const struct sctp_association
*asoc
,
3173 const sctp_subtype_t type
,
3175 sctp_cmd_seq_t
*commands
)
3177 struct sctp_chunk
*chunk
= arg
;
3179 if (!sctp_vtag_verify(chunk
, asoc
))
3180 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3182 /* Make sure that the ERROR chunk has a valid length. */
3183 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
3184 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3187 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_OPERR
,
3190 return SCTP_DISPOSITION_CONSUME
;
3194 * Process an inbound SHUTDOWN ACK.
3197 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3198 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3199 * peer, and remove all record of the association.
3201 * The return value is the disposition.
3203 sctp_disposition_t
sctp_sf_do_9_2_final(const struct sctp_endpoint
*ep
,
3204 const struct sctp_association
*asoc
,
3205 const sctp_subtype_t type
,
3207 sctp_cmd_seq_t
*commands
)
3209 struct sctp_chunk
*chunk
= arg
;
3210 struct sctp_chunk
*reply
;
3211 struct sctp_ulpevent
*ev
;
3213 if (!sctp_vtag_verify(chunk
, asoc
))
3214 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3216 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3217 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3218 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3220 /* 10.2 H) SHUTDOWN COMPLETE notification
3222 * When SCTP completes the shutdown procedures (section 9.2) this
3223 * notification is passed to the upper layer.
3225 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
3226 0, 0, 0, NULL
, GFP_ATOMIC
);
3230 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3231 reply
= sctp_make_shutdown_complete(asoc
, chunk
);
3235 /* Do all the commands now (after allocation), so that we
3236 * have consistent state if memory allocation failes
3238 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
3240 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3241 * stop the T2-shutdown timer,
3243 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3244 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3246 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3247 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
3249 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
3250 SCTP_STATE(SCTP_STATE_CLOSED
));
3251 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS
);
3252 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3253 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
3255 /* ...and remove all record of the association. */
3256 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
3257 return SCTP_DISPOSITION_DELETE_TCB
;
3260 sctp_ulpevent_free(ev
);
3262 return SCTP_DISPOSITION_NOMEM
;
3266 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3268 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3269 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3270 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3271 * packet must fill in the Verification Tag field of the outbound
3272 * packet with the Verification Tag received in the SHUTDOWN ACK and
3273 * set the T-bit in the Chunk Flags to indicate that the Verification
3276 * 8) The receiver should respond to the sender of the OOTB packet with
3277 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3278 * MUST fill in the Verification Tag field of the outbound packet
3279 * with the value found in the Verification Tag field of the OOTB
3280 * packet and set the T-bit in the Chunk Flags to indicate that the
3281 * Verification Tag is reflected. After sending this ABORT, the
3282 * receiver of the OOTB packet shall discard the OOTB packet and take
3283 * no further action.
3285 sctp_disposition_t
sctp_sf_ootb(const struct sctp_endpoint
*ep
,
3286 const struct sctp_association
*asoc
,
3287 const sctp_subtype_t type
,
3289 sctp_cmd_seq_t
*commands
)
3291 struct sctp_chunk
*chunk
= arg
;
3292 struct sk_buff
*skb
= chunk
->skb
;
3293 sctp_chunkhdr_t
*ch
;
3295 int ootb_shut_ack
= 0;
3297 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES
);
3299 ch
= (sctp_chunkhdr_t
*) chunk
->chunk_hdr
;
3301 /* Report violation if the chunk is less then minimal */
3302 if (ntohs(ch
->length
) < sizeof(sctp_chunkhdr_t
))
3303 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3306 /* Now that we know we at least have a chunk header,
3307 * do things that are type appropriate.
3309 if (SCTP_CID_SHUTDOWN_ACK
== ch
->type
)
3312 /* RFC 2960, Section 3.3.7
3313 * Moreover, under any circumstances, an endpoint that
3314 * receives an ABORT MUST NOT respond to that ABORT by
3315 * sending an ABORT of its own.
3317 if (SCTP_CID_ABORT
== ch
->type
)
3318 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3320 /* Report violation if chunk len overflows */
3321 ch_end
= ((__u8
*)ch
) + WORD_ROUND(ntohs(ch
->length
));
3322 if (ch_end
> skb_tail_pointer(skb
))
3323 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3326 ch
= (sctp_chunkhdr_t
*) ch_end
;
3327 } while (ch_end
< skb_tail_pointer(skb
));
3330 return sctp_sf_shut_8_4_5(ep
, asoc
, type
, arg
, commands
);
3332 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
3336 * Handle an "Out of the blue" SHUTDOWN ACK.
3338 * Section: 8.4 5, sctpimpguide 2.41.
3340 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3341 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3342 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3343 * packet must fill in the Verification Tag field of the outbound
3344 * packet with the Verification Tag received in the SHUTDOWN ACK and
3345 * set the T-bit in the Chunk Flags to indicate that the Verification
3349 * (endpoint, asoc, type, arg, commands)
3352 * (sctp_disposition_t)
3354 * The return value is the disposition of the chunk.
3356 static sctp_disposition_t
sctp_sf_shut_8_4_5(const struct sctp_endpoint
*ep
,
3357 const struct sctp_association
*asoc
,
3358 const sctp_subtype_t type
,
3360 sctp_cmd_seq_t
*commands
)
3362 struct sctp_packet
*packet
= NULL
;
3363 struct sctp_chunk
*chunk
= arg
;
3364 struct sctp_chunk
*shut
;
3366 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
3369 /* Make an SHUTDOWN_COMPLETE.
3370 * The T bit will be set if the asoc is NULL.
3372 shut
= sctp_make_shutdown_complete(asoc
, chunk
);
3374 sctp_ootb_pkt_free(packet
);
3375 return SCTP_DISPOSITION_NOMEM
;
3378 /* Reflect vtag if T-Bit is set */
3379 if (sctp_test_T_bit(shut
))
3380 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3382 /* Set the skb to the belonging sock for accounting. */
3383 shut
->skb
->sk
= ep
->base
.sk
;
3385 sctp_packet_append_chunk(packet
, shut
);
3387 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3388 SCTP_PACKET(packet
));
3390 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
3392 /* If the chunk length is invalid, we don't want to process
3393 * the reset of the packet.
3395 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3396 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3398 /* We need to discard the rest of the packet to prevent
3399 * potential bomming attacks from additional bundled chunks.
3400 * This is documented in SCTP Threats ID.
3402 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3405 return SCTP_DISPOSITION_NOMEM
;
3409 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3411 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3412 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3413 * procedures in section 8.4 SHOULD be followed, in other words it
3414 * should be treated as an Out Of The Blue packet.
3415 * [This means that we do NOT check the Verification Tag on these
3419 sctp_disposition_t
sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint
*ep
,
3420 const struct sctp_association
*asoc
,
3421 const sctp_subtype_t type
,
3423 sctp_cmd_seq_t
*commands
)
3425 struct sctp_chunk
*chunk
= arg
;
3427 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3428 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3429 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3432 /* Although we do have an association in this case, it corresponds
3433 * to a restarted association. So the packet is treated as an OOTB
3434 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3435 * called with a NULL association.
3437 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES
);
3439 return sctp_sf_shut_8_4_5(ep
, NULL
, type
, arg
, commands
);
3442 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3443 sctp_disposition_t
sctp_sf_do_asconf(const struct sctp_endpoint
*ep
,
3444 const struct sctp_association
*asoc
,
3445 const sctp_subtype_t type
, void *arg
,
3446 sctp_cmd_seq_t
*commands
)
3448 struct sctp_chunk
*chunk
= arg
;
3449 struct sctp_chunk
*asconf_ack
= NULL
;
3450 struct sctp_paramhdr
*err_param
= NULL
;
3451 sctp_addiphdr_t
*hdr
;
3452 union sctp_addr_param
*addr_param
;
3456 if (!sctp_vtag_verify(chunk
, asoc
)) {
3457 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3459 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3462 /* ADD-IP: Section 4.1.1
3463 * This chunk MUST be sent in an authenticated way by using
3464 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3465 * is received unauthenticated it MUST be silently discarded as
3466 * described in [I-D.ietf-tsvwg-sctp-auth].
3468 if (!sctp_addip_noauth
&& !chunk
->auth
)
3469 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
3471 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3472 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_addip_chunk_t
)))
3473 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3476 hdr
= (sctp_addiphdr_t
*)chunk
->skb
->data
;
3477 serial
= ntohl(hdr
->serial
);
3479 addr_param
= (union sctp_addr_param
*)hdr
->params
;
3480 length
= ntohs(addr_param
->p
.length
);
3481 if (length
< sizeof(sctp_paramhdr_t
))
3482 return sctp_sf_violation_paramlen(ep
, asoc
, type
, arg
,
3483 (void *)addr_param
, commands
);
3485 /* Verify the ASCONF chunk before processing it. */
3486 if (!sctp_verify_asconf(asoc
,
3487 (sctp_paramhdr_t
*)((void *)addr_param
+ length
),
3488 (void *)chunk
->chunk_end
,
3490 return sctp_sf_violation_paramlen(ep
, asoc
, type
, arg
,
3491 (void *)err_param
, commands
);
3493 /* ADDIP 5.2 E1) Compare the value of the serial number to the value
3494 * the endpoint stored in a new association variable
3495 * 'Peer-Serial-Number'.
3497 if (serial
== asoc
->peer
.addip_serial
+ 1) {
3498 /* If this is the first instance of ASCONF in the packet,
3499 * we can clean our old ASCONF-ACKs.
3501 if (!chunk
->has_asconf
)
3502 sctp_assoc_clean_asconf_ack_cache(asoc
);
3504 /* ADDIP 5.2 E4) When the Sequence Number matches the next one
3505 * expected, process the ASCONF as described below and after
3506 * processing the ASCONF Chunk, append an ASCONF-ACK Chunk to
3507 * the response packet and cache a copy of it (in the event it
3508 * later needs to be retransmitted).
3510 * Essentially, do V1-V5.
3512 asconf_ack
= sctp_process_asconf((struct sctp_association
*)
3515 return SCTP_DISPOSITION_NOMEM
;
3516 } else if (serial
< asoc
->peer
.addip_serial
+ 1) {
3518 * If the value found in the Sequence Number is less than the
3519 * ('Peer- Sequence-Number' + 1), simply skip to the next
3520 * ASCONF, and include in the outbound response packet
3521 * any previously cached ASCONF-ACK response that was
3522 * sent and saved that matches the Sequence Number of the
3523 * ASCONF. Note: It is possible that no cached ASCONF-ACK
3524 * Chunk exists. This will occur when an older ASCONF
3525 * arrives out of order. In such a case, the receiver
3526 * should skip the ASCONF Chunk and not include ASCONF-ACK
3527 * Chunk for that chunk.
3529 asconf_ack
= sctp_assoc_lookup_asconf_ack(asoc
, hdr
->serial
);
3531 return SCTP_DISPOSITION_DISCARD
;
3533 /* Reset the transport so that we select the correct one
3534 * this time around. This is to make sure that we don't
3535 * accidentally use a stale transport that's been removed.
3537 asconf_ack
->transport
= NULL
;
3539 /* ADDIP 5.2 E5) Otherwise, the ASCONF Chunk is discarded since
3540 * it must be either a stale packet or from an attacker.
3542 return SCTP_DISPOSITION_DISCARD
;
3545 asconf_ack
->dest
= chunk
->source
;
3546 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(asconf_ack
));
3548 return SCTP_DISPOSITION_CONSUME
;
3552 * ADDIP Section 4.3 General rules for address manipulation
3553 * When building TLV parameters for the ASCONF Chunk that will add or
3554 * delete IP addresses the D0 to D13 rules should be applied:
3556 sctp_disposition_t
sctp_sf_do_asconf_ack(const struct sctp_endpoint
*ep
,
3557 const struct sctp_association
*asoc
,
3558 const sctp_subtype_t type
, void *arg
,
3559 sctp_cmd_seq_t
*commands
)
3561 struct sctp_chunk
*asconf_ack
= arg
;
3562 struct sctp_chunk
*last_asconf
= asoc
->addip_last_asconf
;
3563 struct sctp_chunk
*abort
;
3564 struct sctp_paramhdr
*err_param
= NULL
;
3565 sctp_addiphdr_t
*addip_hdr
;
3566 __u32 sent_serial
, rcvd_serial
;
3568 if (!sctp_vtag_verify(asconf_ack
, asoc
)) {
3569 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3571 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3574 /* ADD-IP, Section 4.1.2:
3575 * This chunk MUST be sent in an authenticated way by using
3576 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3577 * is received unauthenticated it MUST be silently discarded as
3578 * described in [I-D.ietf-tsvwg-sctp-auth].
3580 if (!sctp_addip_noauth
&& !asconf_ack
->auth
)
3581 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
3583 /* Make sure that the ADDIP chunk has a valid length. */
3584 if (!sctp_chunk_length_valid(asconf_ack
, sizeof(sctp_addip_chunk_t
)))
3585 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3588 addip_hdr
= (sctp_addiphdr_t
*)asconf_ack
->skb
->data
;
3589 rcvd_serial
= ntohl(addip_hdr
->serial
);
3591 /* Verify the ASCONF-ACK chunk before processing it. */
3592 if (!sctp_verify_asconf(asoc
,
3593 (sctp_paramhdr_t
*)addip_hdr
->params
,
3594 (void *)asconf_ack
->chunk_end
,
3596 return sctp_sf_violation_paramlen(ep
, asoc
, type
, arg
,
3597 (void *)err_param
, commands
);
3600 addip_hdr
= (sctp_addiphdr_t
*)last_asconf
->subh
.addip_hdr
;
3601 sent_serial
= ntohl(addip_hdr
->serial
);
3603 sent_serial
= asoc
->addip_serial
- 1;
3606 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3607 * equal to the next serial number to be used but no ASCONF chunk is
3608 * outstanding the endpoint MUST ABORT the association. Note that a
3609 * sequence number is greater than if it is no more than 2^^31-1
3610 * larger than the current sequence number (using serial arithmetic).
3612 if (ADDIP_SERIAL_gte(rcvd_serial
, sent_serial
+ 1) &&
3613 !(asoc
->addip_last_asconf
)) {
3614 abort
= sctp_make_abort(asoc
, asconf_ack
,
3615 sizeof(sctp_errhdr_t
));
3617 sctp_init_cause(abort
, SCTP_ERROR_ASCONF_ACK
, 0);
3618 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3621 /* We are going to ABORT, so we might as well stop
3622 * processing the rest of the chunks in the packet.
3624 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3625 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3626 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
3627 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3628 SCTP_ERROR(ECONNABORTED
));
3629 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3630 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3631 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
3632 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3633 return SCTP_DISPOSITION_ABORT
;
3636 if ((rcvd_serial
== sent_serial
) && asoc
->addip_last_asconf
) {
3637 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3638 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3640 if (!sctp_process_asconf_ack((struct sctp_association
*)asoc
,
3642 /* Successfully processed ASCONF_ACK. We can
3643 * release the next asconf if we have one.
3645 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_NEXT_ASCONF
,
3647 return SCTP_DISPOSITION_CONSUME
;
3650 abort
= sctp_make_abort(asoc
, asconf_ack
,
3651 sizeof(sctp_errhdr_t
));
3653 sctp_init_cause(abort
, SCTP_ERROR_RSRC_LOW
, 0);
3654 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3657 /* We are going to ABORT, so we might as well stop
3658 * processing the rest of the chunks in the packet.
3660 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
3661 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3662 SCTP_ERROR(ECONNABORTED
));
3663 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3664 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3665 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
3666 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3667 return SCTP_DISPOSITION_ABORT
;
3670 return SCTP_DISPOSITION_DISCARD
;
3674 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3676 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3677 * its cumulative TSN point to the value carried in the FORWARD TSN
3678 * chunk, and then MUST further advance its cumulative TSN point locally
3680 * After the above processing, the data receiver MUST stop reporting any
3681 * missing TSNs earlier than or equal to the new cumulative TSN point.
3683 * Verification Tag: 8.5 Verification Tag [Normal verification]
3685 * The return value is the disposition of the chunk.
3687 sctp_disposition_t
sctp_sf_eat_fwd_tsn(const struct sctp_endpoint
*ep
,
3688 const struct sctp_association
*asoc
,
3689 const sctp_subtype_t type
,
3691 sctp_cmd_seq_t
*commands
)
3693 struct sctp_chunk
*chunk
= arg
;
3694 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3695 struct sctp_fwdtsn_skip
*skip
;
3699 if (!sctp_vtag_verify(chunk
, asoc
)) {
3700 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3702 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3705 /* Make sure that the FORWARD_TSN chunk has valid length. */
3706 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3707 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3710 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3711 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3712 len
= ntohs(chunk
->chunk_hdr
->length
);
3713 len
-= sizeof(struct sctp_chunkhdr
);
3714 skb_pull(chunk
->skb
, len
);
3716 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3717 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __func__
, tsn
);
3719 /* The TSN is too high--silently discard the chunk and count on it
3720 * getting retransmitted later.
3722 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3723 goto discard_noforce
;
3725 /* Silently discard the chunk if stream-id is not valid */
3726 sctp_walk_fwdtsn(skip
, chunk
) {
3727 if (ntohs(skip
->stream
) >= asoc
->c
.sinit_max_instreams
)
3728 goto discard_noforce
;
3731 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3732 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3733 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3736 /* Count this as receiving DATA. */
3737 if (asoc
->autoclose
) {
3738 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3739 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
3742 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
3744 return SCTP_DISPOSITION_CONSUME
;
3747 return SCTP_DISPOSITION_DISCARD
;
3750 sctp_disposition_t
sctp_sf_eat_fwd_tsn_fast(
3751 const struct sctp_endpoint
*ep
,
3752 const struct sctp_association
*asoc
,
3753 const sctp_subtype_t type
,
3755 sctp_cmd_seq_t
*commands
)
3757 struct sctp_chunk
*chunk
= arg
;
3758 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3759 struct sctp_fwdtsn_skip
*skip
;
3763 if (!sctp_vtag_verify(chunk
, asoc
)) {
3764 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3766 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3769 /* Make sure that the FORWARD_TSN chunk has a valid length. */
3770 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3771 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3774 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3775 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3776 len
= ntohs(chunk
->chunk_hdr
->length
);
3777 len
-= sizeof(struct sctp_chunkhdr
);
3778 skb_pull(chunk
->skb
, len
);
3780 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3781 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __func__
, tsn
);
3783 /* The TSN is too high--silently discard the chunk and count on it
3784 * getting retransmitted later.
3786 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3789 /* Silently discard the chunk if stream-id is not valid */
3790 sctp_walk_fwdtsn(skip
, chunk
) {
3791 if (ntohs(skip
->stream
) >= asoc
->c
.sinit_max_instreams
)
3795 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3796 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3797 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3800 /* Go a head and force a SACK, since we are shutting down. */
3802 /* Implementor's Guide.
3804 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3805 * respond to each received packet containing one or more DATA chunk(s)
3806 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3808 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3809 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3810 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3811 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3813 return SCTP_DISPOSITION_CONSUME
;
3817 * SCTP-AUTH Section 6.3 Receving authenticated chukns
3819 * The receiver MUST use the HMAC algorithm indicated in the HMAC
3820 * Identifier field. If this algorithm was not specified by the
3821 * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk
3822 * during association setup, the AUTH chunk and all chunks after it MUST
3823 * be discarded and an ERROR chunk SHOULD be sent with the error cause
3824 * defined in Section 4.1.
3826 * If an endpoint with no shared key receives a Shared Key Identifier
3827 * other than 0, it MUST silently discard all authenticated chunks. If
3828 * the endpoint has at least one endpoint pair shared key for the peer,
3829 * it MUST use the key specified by the Shared Key Identifier if a
3830 * key has been configured for that Shared Key Identifier. If no
3831 * endpoint pair shared key has been configured for that Shared Key
3832 * Identifier, all authenticated chunks MUST be silently discarded.
3834 * Verification Tag: 8.5 Verification Tag [Normal verification]
3836 * The return value is the disposition of the chunk.
3838 static sctp_ierror_t
sctp_sf_authenticate(const struct sctp_endpoint
*ep
,
3839 const struct sctp_association
*asoc
,
3840 const sctp_subtype_t type
,
3841 struct sctp_chunk
*chunk
)
3843 struct sctp_authhdr
*auth_hdr
;
3844 struct sctp_hmac
*hmac
;
3845 unsigned int sig_len
;
3850 /* Pull in the auth header, so we can do some more verification */
3851 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
3852 chunk
->subh
.auth_hdr
= auth_hdr
;
3853 skb_pull(chunk
->skb
, sizeof(struct sctp_authhdr
));
3855 /* Make sure that we suport the HMAC algorithm from the auth
3858 if (!sctp_auth_asoc_verify_hmac_id(asoc
, auth_hdr
->hmac_id
))
3859 return SCTP_IERROR_AUTH_BAD_HMAC
;
3861 /* Make sure that the provided shared key identifier has been
3864 key_id
= ntohs(auth_hdr
->shkey_id
);
3865 if (key_id
!= asoc
->active_key_id
&& !sctp_auth_get_shkey(asoc
, key_id
))
3866 return SCTP_IERROR_AUTH_BAD_KEYID
;
3869 /* Make sure that the length of the signature matches what
3872 sig_len
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(sctp_auth_chunk_t
);
3873 hmac
= sctp_auth_get_hmac(ntohs(auth_hdr
->hmac_id
));
3874 if (sig_len
!= hmac
->hmac_len
)
3875 return SCTP_IERROR_PROTO_VIOLATION
;
3877 /* Now that we've done validation checks, we can compute and
3878 * verify the hmac. The steps involved are:
3879 * 1. Save the digest from the chunk.
3880 * 2. Zero out the digest in the chunk.
3881 * 3. Compute the new digest
3882 * 4. Compare saved and new digests.
3884 digest
= auth_hdr
->hmac
;
3885 skb_pull(chunk
->skb
, sig_len
);
3887 save_digest
= kmemdup(digest
, sig_len
, GFP_ATOMIC
);
3891 memset(digest
, 0, sig_len
);
3893 sctp_auth_calculate_hmac(asoc
, chunk
->skb
,
3894 (struct sctp_auth_chunk
*)chunk
->chunk_hdr
,
3897 /* Discard the packet if the digests do not match */
3898 if (memcmp(save_digest
, digest
, sig_len
)) {
3900 return SCTP_IERROR_BAD_SIG
;
3906 return SCTP_IERROR_NO_ERROR
;
3908 return SCTP_IERROR_NOMEM
;
3911 sctp_disposition_t
sctp_sf_eat_auth(const struct sctp_endpoint
*ep
,
3912 const struct sctp_association
*asoc
,
3913 const sctp_subtype_t type
,
3915 sctp_cmd_seq_t
*commands
)
3917 struct sctp_authhdr
*auth_hdr
;
3918 struct sctp_chunk
*chunk
= arg
;
3919 struct sctp_chunk
*err_chunk
;
3920 sctp_ierror_t error
;
3922 /* Make sure that the peer has AUTH capable */
3923 if (!asoc
->peer
.auth_capable
)
3924 return sctp_sf_unk_chunk(ep
, asoc
, type
, arg
, commands
);
3926 if (!sctp_vtag_verify(chunk
, asoc
)) {
3927 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3929 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3932 /* Make sure that the AUTH chunk has valid length. */
3933 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_auth_chunk
)))
3934 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3937 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
3938 error
= sctp_sf_authenticate(ep
, asoc
, type
, chunk
);
3940 case SCTP_IERROR_AUTH_BAD_HMAC
:
3941 /* Generate the ERROR chunk and discard the rest
3944 err_chunk
= sctp_make_op_error(asoc
, chunk
,
3945 SCTP_ERROR_UNSUP_HMAC
,
3949 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3950 SCTP_CHUNK(err_chunk
));
3953 case SCTP_IERROR_AUTH_BAD_KEYID
:
3954 case SCTP_IERROR_BAD_SIG
:
3955 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3957 case SCTP_IERROR_PROTO_VIOLATION
:
3958 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3961 case SCTP_IERROR_NOMEM
:
3962 return SCTP_DISPOSITION_NOMEM
;
3967 if (asoc
->active_key_id
!= ntohs(auth_hdr
->shkey_id
)) {
3968 struct sctp_ulpevent
*ev
;
3970 ev
= sctp_ulpevent_make_authkey(asoc
, ntohs(auth_hdr
->shkey_id
),
3971 SCTP_AUTH_NEWKEY
, GFP_ATOMIC
);
3976 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
3980 return SCTP_DISPOSITION_CONSUME
;
3984 * Process an unknown chunk.
3986 * Section: 3.2. Also, 2.1 in the implementor's guide.
3988 * Chunk Types are encoded such that the highest-order two bits specify
3989 * the action that must be taken if the processing endpoint does not
3990 * recognize the Chunk Type.
3992 * 00 - Stop processing this SCTP packet and discard it, do not process
3993 * any further chunks within it.
3995 * 01 - Stop processing this SCTP packet and discard it, do not process
3996 * any further chunks within it, and report the unrecognized
3997 * chunk in an 'Unrecognized Chunk Type'.
3999 * 10 - Skip this chunk and continue processing.
4001 * 11 - Skip this chunk and continue processing, but report in an ERROR
4002 * Chunk using the 'Unrecognized Chunk Type' cause of error.
4004 * The return value is the disposition of the chunk.
4006 sctp_disposition_t
sctp_sf_unk_chunk(const struct sctp_endpoint
*ep
,
4007 const struct sctp_association
*asoc
,
4008 const sctp_subtype_t type
,
4010 sctp_cmd_seq_t
*commands
)
4012 struct sctp_chunk
*unk_chunk
= arg
;
4013 struct sctp_chunk
*err_chunk
;
4014 sctp_chunkhdr_t
*hdr
;
4016 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type
.chunk
);
4018 if (!sctp_vtag_verify(unk_chunk
, asoc
))
4019 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
4021 /* Make sure that the chunk has a valid length.
4022 * Since we don't know the chunk type, we use a general
4023 * chunkhdr structure to make a comparison.
4025 if (!sctp_chunk_length_valid(unk_chunk
, sizeof(sctp_chunkhdr_t
)))
4026 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
4029 switch (type
.chunk
& SCTP_CID_ACTION_MASK
) {
4030 case SCTP_CID_ACTION_DISCARD
:
4031 /* Discard the packet. */
4032 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
4034 case SCTP_CID_ACTION_DISCARD_ERR
:
4035 /* Generate an ERROR chunk as response. */
4036 hdr
= unk_chunk
->chunk_hdr
;
4037 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4038 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4039 WORD_ROUND(ntohs(hdr
->length
)),
4042 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4043 SCTP_CHUNK(err_chunk
));
4046 /* Discard the packet. */
4047 sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
4048 return SCTP_DISPOSITION_CONSUME
;
4050 case SCTP_CID_ACTION_SKIP
:
4051 /* Skip the chunk. */
4052 return SCTP_DISPOSITION_DISCARD
;
4054 case SCTP_CID_ACTION_SKIP_ERR
:
4055 /* Generate an ERROR chunk as response. */
4056 hdr
= unk_chunk
->chunk_hdr
;
4057 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4058 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4059 WORD_ROUND(ntohs(hdr
->length
)),
4062 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4063 SCTP_CHUNK(err_chunk
));
4065 /* Skip the chunk. */
4066 return SCTP_DISPOSITION_CONSUME
;
4072 return SCTP_DISPOSITION_DISCARD
;
4076 * Discard the chunk.
4078 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
4079 * [Too numerous to mention...]
4080 * Verification Tag: No verification needed.
4082 * (endpoint, asoc, chunk)
4085 * (asoc, reply_msg, msg_up, timers, counters)
4087 * The return value is the disposition of the chunk.
4089 sctp_disposition_t
sctp_sf_discard_chunk(const struct sctp_endpoint
*ep
,
4090 const struct sctp_association
*asoc
,
4091 const sctp_subtype_t type
,
4093 sctp_cmd_seq_t
*commands
)
4095 struct sctp_chunk
*chunk
= arg
;
4097 /* Make sure that the chunk has a valid length.
4098 * Since we don't know the chunk type, we use a general
4099 * chunkhdr structure to make a comparison.
4101 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
4102 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
4105 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type
.chunk
);
4106 return SCTP_DISPOSITION_DISCARD
;
4110 * Discard the whole packet.
4114 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
4115 * silently discard the OOTB packet and take no further action.
4117 * Verification Tag: No verification necessary
4120 * (endpoint, asoc, chunk)
4123 * (asoc, reply_msg, msg_up, timers, counters)
4125 * The return value is the disposition of the chunk.
4127 sctp_disposition_t
sctp_sf_pdiscard(const struct sctp_endpoint
*ep
,
4128 const struct sctp_association
*asoc
,
4129 const sctp_subtype_t type
,
4131 sctp_cmd_seq_t
*commands
)
4133 SCTP_INC_STATS(SCTP_MIB_IN_PKT_DISCARDS
);
4134 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
4136 return SCTP_DISPOSITION_CONSUME
;
4141 * The other end is violating protocol.
4143 * Section: Not specified
4144 * Verification Tag: Not specified
4146 * (endpoint, asoc, chunk)
4149 * (asoc, reply_msg, msg_up, timers, counters)
4151 * We simply tag the chunk as a violation. The state machine will log
4152 * the violation and continue.
4154 sctp_disposition_t
sctp_sf_violation(const struct sctp_endpoint
*ep
,
4155 const struct sctp_association
*asoc
,
4156 const sctp_subtype_t type
,
4158 sctp_cmd_seq_t
*commands
)
4160 struct sctp_chunk
*chunk
= arg
;
4162 /* Make sure that the chunk has a valid length. */
4163 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
4164 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
4167 return SCTP_DISPOSITION_VIOLATION
;
4171 * Common function to handle a protocol violation.
4173 static sctp_disposition_t
sctp_sf_abort_violation(
4174 const struct sctp_endpoint
*ep
,
4175 const struct sctp_association
*asoc
,
4177 sctp_cmd_seq_t
*commands
,
4178 const __u8
*payload
,
4179 const size_t paylen
)
4181 struct sctp_packet
*packet
= NULL
;
4182 struct sctp_chunk
*chunk
= arg
;
4183 struct sctp_chunk
*abort
= NULL
;
4185 /* SCTP-AUTH, Section 6.3:
4186 * It should be noted that if the receiver wants to tear
4187 * down an association in an authenticated way only, the
4188 * handling of malformed packets should not result in
4189 * tearing down the association.
4191 * This means that if we only want to abort associations
4192 * in an authenticated way (i.e AUTH+ABORT), then we
4193 * can't destroy this association just becuase the packet
4196 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4199 /* Make the abort chunk. */
4200 abort
= sctp_make_abort_violation(asoc
, chunk
, payload
, paylen
);
4205 /* Treat INIT-ACK as a special case during COOKIE-WAIT. */
4206 if (chunk
->chunk_hdr
->type
== SCTP_CID_INIT_ACK
&&
4207 !asoc
->peer
.i
.init_tag
) {
4208 sctp_initack_chunk_t
*initack
;
4210 initack
= (sctp_initack_chunk_t
*)chunk
->chunk_hdr
;
4211 if (!sctp_chunk_length_valid(chunk
,
4212 sizeof(sctp_initack_chunk_t
)))
4213 abort
->chunk_hdr
->flags
|= SCTP_CHUNK_FLAG_T
;
4215 unsigned int inittag
;
4217 inittag
= ntohl(initack
->init_hdr
.init_tag
);
4218 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_INITTAG
,
4223 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4224 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
4226 if (asoc
->state
<= SCTP_STATE_COOKIE_ECHOED
) {
4227 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4228 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4229 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4230 SCTP_ERROR(ECONNREFUSED
));
4231 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4232 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4234 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4235 SCTP_ERROR(ECONNABORTED
));
4236 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4237 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4238 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
4241 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
4246 if (sctp_test_T_bit(abort
))
4247 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
4249 abort
->skb
->sk
= ep
->base
.sk
;
4251 sctp_packet_append_chunk(packet
, abort
);
4253 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
4254 SCTP_PACKET(packet
));
4256 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
4259 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4262 sctp_sf_pdiscard(ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4263 return SCTP_DISPOSITION_ABORT
;
4266 sctp_chunk_free(abort
);
4268 return SCTP_DISPOSITION_NOMEM
;
4272 * Handle a protocol violation when the chunk length is invalid.
4273 * "Invalid" length is identified as smaller than the minimal length a
4274 * given chunk can be. For example, a SACK chunk has invalid length
4275 * if its length is set to be smaller than the size of sctp_sack_chunk_t.
4277 * We inform the other end by sending an ABORT with a Protocol Violation
4280 * Section: Not specified
4281 * Verification Tag: Nothing to do
4283 * (endpoint, asoc, chunk)
4286 * (reply_msg, msg_up, counters)
4288 * Generate an ABORT chunk and terminate the association.
4290 static sctp_disposition_t
sctp_sf_violation_chunklen(
4291 const struct sctp_endpoint
*ep
,
4292 const struct sctp_association
*asoc
,
4293 const sctp_subtype_t type
,
4295 sctp_cmd_seq_t
*commands
)
4297 static const char err_str
[]="The following chunk had invalid length:";
4299 return sctp_sf_abort_violation(ep
, asoc
, arg
, commands
, err_str
,
4304 * Handle a protocol violation when the parameter length is invalid.
4305 * "Invalid" length is identified as smaller than the minimal length a
4306 * given parameter can be.
4308 static sctp_disposition_t
sctp_sf_violation_paramlen(
4309 const struct sctp_endpoint
*ep
,
4310 const struct sctp_association
*asoc
,
4311 const sctp_subtype_t type
,
4312 void *arg
, void *ext
,
4313 sctp_cmd_seq_t
*commands
)
4315 struct sctp_chunk
*chunk
= arg
;
4316 struct sctp_paramhdr
*param
= ext
;
4317 struct sctp_chunk
*abort
= NULL
;
4319 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4322 /* Make the abort chunk. */
4323 abort
= sctp_make_violation_paramlen(asoc
, chunk
, param
);
4327 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4328 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
4330 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4331 SCTP_ERROR(ECONNABORTED
));
4332 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4333 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4334 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
4335 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4338 sctp_sf_pdiscard(ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4339 return SCTP_DISPOSITION_ABORT
;
4341 return SCTP_DISPOSITION_NOMEM
;
4344 /* Handle a protocol violation when the peer trying to advance the
4345 * cumulative tsn ack to a point beyond the max tsn currently sent.
4347 * We inform the other end by sending an ABORT with a Protocol Violation
4350 static sctp_disposition_t
sctp_sf_violation_ctsn(
4351 const struct sctp_endpoint
*ep
,
4352 const struct sctp_association
*asoc
,
4353 const sctp_subtype_t type
,
4355 sctp_cmd_seq_t
*commands
)
4357 static const char err_str
[]="The cumulative tsn ack beyond the max tsn currently sent:";
4359 return sctp_sf_abort_violation(ep
, asoc
, arg
, commands
, err_str
,
4363 /* Handle protocol violation of an invalid chunk bundling. For example,
4364 * when we have an association and we recieve bundled INIT-ACK, or
4365 * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle"
4366 * statement from the specs. Additinally, there might be an attacker
4367 * on the path and we may not want to continue this communication.
4369 static sctp_disposition_t
sctp_sf_violation_chunk(
4370 const struct sctp_endpoint
*ep
,
4371 const struct sctp_association
*asoc
,
4372 const sctp_subtype_t type
,
4374 sctp_cmd_seq_t
*commands
)
4376 static const char err_str
[]="The following chunk violates protocol:";
4379 return sctp_sf_violation(ep
, asoc
, type
, arg
, commands
);
4381 return sctp_sf_abort_violation(ep
, asoc
, arg
, commands
, err_str
,
4384 /***************************************************************************
4385 * These are the state functions for handling primitive (Section 10) events.
4386 ***************************************************************************/
4388 * sctp_sf_do_prm_asoc
4390 * Section: 10.1 ULP-to-SCTP
4393 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
4394 * outbound stream count)
4395 * -> association id [,destination transport addr list] [,outbound stream
4398 * This primitive allows the upper layer to initiate an association to a
4399 * specific peer endpoint.
4401 * The peer endpoint shall be specified by one of the transport addresses
4402 * which defines the endpoint (see Section 1.4). If the local SCTP
4403 * instance has not been initialized, the ASSOCIATE is considered an
4405 * [This is not relevant for the kernel implementation since we do all
4406 * initialization at boot time. It we hadn't initialized we wouldn't
4407 * get anywhere near this code.]
4409 * An association id, which is a local handle to the SCTP association,
4410 * will be returned on successful establishment of the association. If
4411 * SCTP is not able to open an SCTP association with the peer endpoint,
4412 * an error is returned.
4413 * [In the kernel implementation, the struct sctp_association needs to
4414 * be created BEFORE causing this primitive to run.]
4416 * Other association parameters may be returned, including the
4417 * complete destination transport addresses of the peer as well as the
4418 * outbound stream count of the local endpoint. One of the transport
4419 * address from the returned destination addresses will be selected by
4420 * the local endpoint as default primary path for sending SCTP packets
4421 * to this peer. The returned "destination transport addr list" can
4422 * be used by the ULP to change the default primary path or to force
4423 * sending a packet to a specific transport address. [All of this
4424 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
4427 * Mandatory attributes:
4429 * o local SCTP instance name - obtained from the INITIALIZE operation.
4430 * [This is the argument asoc.]
4431 * o destination transport addr - specified as one of the transport
4432 * addresses of the peer endpoint with which the association is to be
4434 * [This is asoc->peer.active_path.]
4435 * o outbound stream count - the number of outbound streams the ULP
4436 * would like to open towards this peer endpoint.
4437 * [BUG: This is not currently implemented.]
4438 * Optional attributes:
4442 * The return value is a disposition.
4444 sctp_disposition_t
sctp_sf_do_prm_asoc(const struct sctp_endpoint
*ep
,
4445 const struct sctp_association
*asoc
,
4446 const sctp_subtype_t type
,
4448 sctp_cmd_seq_t
*commands
)
4450 struct sctp_chunk
*repl
;
4451 struct sctp_association
* my_asoc
;
4453 /* The comment below says that we enter COOKIE-WAIT AFTER
4454 * sending the INIT, but that doesn't actually work in our
4457 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4458 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
4460 /* RFC 2960 5.1 Normal Establishment of an Association
4462 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
4463 * must provide its Verification Tag (Tag_A) in the Initiate
4464 * Tag field. Tag_A SHOULD be a random number in the range of
4465 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
4468 repl
= sctp_make_init(asoc
, &asoc
->base
.bind_addr
, GFP_ATOMIC
, 0);
4472 /* Cast away the const modifier, as we want to just
4473 * rerun it through as a sideffect.
4475 my_asoc
= (struct sctp_association
*)asoc
;
4476 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(my_asoc
));
4478 /* Choose transport for INIT. */
4479 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
4482 /* After sending the INIT, "A" starts the T1-init timer and
4483 * enters the COOKIE-WAIT state.
4485 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4486 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4487 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
4488 return SCTP_DISPOSITION_CONSUME
;
4491 return SCTP_DISPOSITION_NOMEM
;
4495 * Process the SEND primitive.
4497 * Section: 10.1 ULP-to-SCTP
4500 * Format: SEND(association id, buffer address, byte count [,context]
4501 * [,stream id] [,life time] [,destination transport address]
4502 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
4505 * This is the main method to send user data via SCTP.
4507 * Mandatory attributes:
4509 * o association id - local handle to the SCTP association
4511 * o buffer address - the location where the user message to be
4512 * transmitted is stored;
4514 * o byte count - The size of the user data in number of bytes;
4516 * Optional attributes:
4518 * o context - an optional 32 bit integer that will be carried in the
4519 * sending failure notification to the ULP if the transportation of
4520 * this User Message fails.
4522 * o stream id - to indicate which stream to send the data on. If not
4523 * specified, stream 0 will be used.
4525 * o life time - specifies the life time of the user data. The user data
4526 * will not be sent by SCTP after the life time expires. This
4527 * parameter can be used to avoid efforts to transmit stale
4528 * user messages. SCTP notifies the ULP if the data cannot be
4529 * initiated to transport (i.e. sent to the destination via SCTP's
4530 * send primitive) within the life time variable. However, the
4531 * user data will be transmitted if SCTP has attempted to transmit a
4532 * chunk before the life time expired.
4534 * o destination transport address - specified as one of the destination
4535 * transport addresses of the peer endpoint to which this packet
4536 * should be sent. Whenever possible, SCTP should use this destination
4537 * transport address for sending the packets, instead of the current
4540 * o unorder flag - this flag, if present, indicates that the user
4541 * would like the data delivered in an unordered fashion to the peer
4542 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
4545 * o no-bundle flag - instructs SCTP not to bundle this user data with
4546 * other outbound DATA chunks. SCTP MAY still bundle even when
4547 * this flag is present, when faced with network congestion.
4549 * o payload protocol-id - A 32 bit unsigned integer that is to be
4550 * passed to the peer indicating the type of payload protocol data
4551 * being transmitted. This value is passed as opaque data by SCTP.
4553 * The return value is the disposition.
4555 sctp_disposition_t
sctp_sf_do_prm_send(const struct sctp_endpoint
*ep
,
4556 const struct sctp_association
*asoc
,
4557 const sctp_subtype_t type
,
4559 sctp_cmd_seq_t
*commands
)
4561 struct sctp_datamsg
*msg
= arg
;
4563 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_MSG
, SCTP_DATAMSG(msg
));
4564 return SCTP_DISPOSITION_CONSUME
;
4568 * Process the SHUTDOWN primitive.
4573 * Format: SHUTDOWN(association id)
4576 * Gracefully closes an association. Any locally queued user data
4577 * will be delivered to the peer. The association will be terminated only
4578 * after the peer acknowledges all the SCTP packets sent. A success code
4579 * will be returned on successful termination of the association. If
4580 * attempting to terminate the association results in a failure, an error
4581 * code shall be returned.
4583 * Mandatory attributes:
4585 * o association id - local handle to the SCTP association
4587 * Optional attributes:
4591 * The return value is the disposition.
4593 sctp_disposition_t
sctp_sf_do_9_2_prm_shutdown(
4594 const struct sctp_endpoint
*ep
,
4595 const struct sctp_association
*asoc
,
4596 const sctp_subtype_t type
,
4598 sctp_cmd_seq_t
*commands
)
4602 /* From 9.2 Shutdown of an Association
4603 * Upon receipt of the SHUTDOWN primitive from its upper
4604 * layer, the endpoint enters SHUTDOWN-PENDING state and
4605 * remains there until all outstanding data has been
4606 * acknowledged by its peer. The endpoint accepts no new data
4607 * from its upper layer, but retransmits data to the far end
4608 * if necessary to fill gaps.
4610 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4611 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
4613 disposition
= SCTP_DISPOSITION_CONSUME
;
4614 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
4615 disposition
= sctp_sf_do_9_2_start_shutdown(ep
, asoc
, type
,
4622 * Process the ABORT primitive.
4627 * Format: Abort(association id [, cause code])
4630 * Ungracefully closes an association. Any locally queued user data
4631 * will be discarded and an ABORT chunk is sent to the peer. A success code
4632 * will be returned on successful abortion of the association. If
4633 * attempting to abort the association results in a failure, an error
4634 * code shall be returned.
4636 * Mandatory attributes:
4638 * o association id - local handle to the SCTP association
4640 * Optional attributes:
4642 * o cause code - reason of the abort to be passed to the peer
4646 * The return value is the disposition.
4648 sctp_disposition_t
sctp_sf_do_9_1_prm_abort(
4649 const struct sctp_endpoint
*ep
,
4650 const struct sctp_association
*asoc
,
4651 const sctp_subtype_t type
,
4653 sctp_cmd_seq_t
*commands
)
4655 /* From 9.1 Abort of an Association
4656 * Upon receipt of the ABORT primitive from its upper
4657 * layer, the endpoint enters CLOSED state and
4658 * discard all outstanding data has been
4659 * acknowledged by its peer. The endpoint accepts no new data
4660 * from its upper layer, but retransmits data to the far end
4661 * if necessary to fill gaps.
4663 struct sctp_chunk
*abort
= arg
;
4664 sctp_disposition_t retval
;
4666 retval
= SCTP_DISPOSITION_CONSUME
;
4668 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4670 /* Even if we can't send the ABORT due to low memory delete the
4671 * TCB. This is a departure from our typical NOMEM handling.
4674 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4675 SCTP_ERROR(ECONNABORTED
));
4676 /* Delete the established association. */
4677 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4678 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4680 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4681 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
4686 /* We tried an illegal operation on an association which is closed. */
4687 sctp_disposition_t
sctp_sf_error_closed(const struct sctp_endpoint
*ep
,
4688 const struct sctp_association
*asoc
,
4689 const sctp_subtype_t type
,
4691 sctp_cmd_seq_t
*commands
)
4693 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
, SCTP_ERROR(-EINVAL
));
4694 return SCTP_DISPOSITION_CONSUME
;
4697 /* We tried an illegal operation on an association which is shutting
4700 sctp_disposition_t
sctp_sf_error_shutdown(const struct sctp_endpoint
*ep
,
4701 const struct sctp_association
*asoc
,
4702 const sctp_subtype_t type
,
4704 sctp_cmd_seq_t
*commands
)
4706 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
,
4707 SCTP_ERROR(-ESHUTDOWN
));
4708 return SCTP_DISPOSITION_CONSUME
;
4712 * sctp_cookie_wait_prm_shutdown
4714 * Section: 4 Note: 2
4719 * The RFC does not explicitly address this issue, but is the route through the
4720 * state table when someone issues a shutdown while in COOKIE_WAIT state.
4725 sctp_disposition_t
sctp_sf_cookie_wait_prm_shutdown(
4726 const struct sctp_endpoint
*ep
,
4727 const struct sctp_association
*asoc
,
4728 const sctp_subtype_t type
,
4730 sctp_cmd_seq_t
*commands
)
4732 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4733 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4735 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4736 SCTP_STATE(SCTP_STATE_CLOSED
));
4738 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS
);
4740 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
4742 return SCTP_DISPOSITION_DELETE_TCB
;
4746 * sctp_cookie_echoed_prm_shutdown
4748 * Section: 4 Note: 2
4753 * The RFC does not explcitly address this issue, but is the route through the
4754 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
4759 sctp_disposition_t
sctp_sf_cookie_echoed_prm_shutdown(
4760 const struct sctp_endpoint
*ep
,
4761 const struct sctp_association
*asoc
,
4762 const sctp_subtype_t type
,
4763 void *arg
, sctp_cmd_seq_t
*commands
)
4765 /* There is a single T1 timer, so we should be able to use
4766 * common function with the COOKIE-WAIT state.
4768 return sctp_sf_cookie_wait_prm_shutdown(ep
, asoc
, type
, arg
, commands
);
4772 * sctp_sf_cookie_wait_prm_abort
4774 * Section: 4 Note: 2
4779 * The RFC does not explicitly address this issue, but is the route through the
4780 * state table when someone issues an abort while in COOKIE_WAIT state.
4785 sctp_disposition_t
sctp_sf_cookie_wait_prm_abort(
4786 const struct sctp_endpoint
*ep
,
4787 const struct sctp_association
*asoc
,
4788 const sctp_subtype_t type
,
4790 sctp_cmd_seq_t
*commands
)
4792 struct sctp_chunk
*abort
= arg
;
4793 sctp_disposition_t retval
;
4795 /* Stop T1-init timer */
4796 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4797 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4798 retval
= SCTP_DISPOSITION_CONSUME
;
4800 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4802 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4803 SCTP_STATE(SCTP_STATE_CLOSED
));
4805 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4807 /* Even if we can't send the ABORT due to low memory delete the
4808 * TCB. This is a departure from our typical NOMEM handling.
4811 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4812 SCTP_ERROR(ECONNREFUSED
));
4813 /* Delete the established association. */
4814 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4815 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4821 * sctp_sf_cookie_echoed_prm_abort
4823 * Section: 4 Note: 3
4828 * The RFC does not explcitly address this issue, but is the route through the
4829 * state table when someone issues an abort while in COOKIE_ECHOED state.
4834 sctp_disposition_t
sctp_sf_cookie_echoed_prm_abort(
4835 const struct sctp_endpoint
*ep
,
4836 const struct sctp_association
*asoc
,
4837 const sctp_subtype_t type
,
4839 sctp_cmd_seq_t
*commands
)
4841 /* There is a single T1 timer, so we should be able to use
4842 * common function with the COOKIE-WAIT state.
4844 return sctp_sf_cookie_wait_prm_abort(ep
, asoc
, type
, arg
, commands
);
4848 * sctp_sf_shutdown_pending_prm_abort
4853 * The RFC does not explicitly address this issue, but is the route through the
4854 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
4859 sctp_disposition_t
sctp_sf_shutdown_pending_prm_abort(
4860 const struct sctp_endpoint
*ep
,
4861 const struct sctp_association
*asoc
,
4862 const sctp_subtype_t type
,
4864 sctp_cmd_seq_t
*commands
)
4866 /* Stop the T5-shutdown guard timer. */
4867 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4868 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
4870 return sctp_sf_do_9_1_prm_abort(ep
, asoc
, type
, arg
, commands
);
4874 * sctp_sf_shutdown_sent_prm_abort
4879 * The RFC does not explicitly address this issue, but is the route through the
4880 * state table when someone issues an abort while in SHUTDOWN-SENT state.
4885 sctp_disposition_t
sctp_sf_shutdown_sent_prm_abort(
4886 const struct sctp_endpoint
*ep
,
4887 const struct sctp_association
*asoc
,
4888 const sctp_subtype_t type
,
4890 sctp_cmd_seq_t
*commands
)
4892 /* Stop the T2-shutdown timer. */
4893 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4894 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
4896 /* Stop the T5-shutdown guard timer. */
4897 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4898 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
4900 return sctp_sf_do_9_1_prm_abort(ep
, asoc
, type
, arg
, commands
);
4904 * sctp_sf_cookie_echoed_prm_abort
4909 * The RFC does not explcitly address this issue, but is the route through the
4910 * state table when someone issues an abort while in COOKIE_ECHOED state.
4915 sctp_disposition_t
sctp_sf_shutdown_ack_sent_prm_abort(
4916 const struct sctp_endpoint
*ep
,
4917 const struct sctp_association
*asoc
,
4918 const sctp_subtype_t type
,
4920 sctp_cmd_seq_t
*commands
)
4922 /* The same T2 timer, so we should be able to use
4923 * common function with the SHUTDOWN-SENT state.
4925 return sctp_sf_shutdown_sent_prm_abort(ep
, asoc
, type
, arg
, commands
);
4929 * Process the REQUESTHEARTBEAT primitive
4932 * J) Request Heartbeat
4934 * Format: REQUESTHEARTBEAT(association id, destination transport address)
4938 * Instructs the local endpoint to perform a HeartBeat on the specified
4939 * destination transport address of the given association. The returned
4940 * result should indicate whether the transmission of the HEARTBEAT
4941 * chunk to the destination address is successful.
4943 * Mandatory attributes:
4945 * o association id - local handle to the SCTP association
4947 * o destination transport address - the transport address of the
4948 * association on which a heartbeat should be issued.
4950 sctp_disposition_t
sctp_sf_do_prm_requestheartbeat(
4951 const struct sctp_endpoint
*ep
,
4952 const struct sctp_association
*asoc
,
4953 const sctp_subtype_t type
,
4955 sctp_cmd_seq_t
*commands
)
4957 if (SCTP_DISPOSITION_NOMEM
== sctp_sf_heartbeat(ep
, asoc
, type
,
4958 (struct sctp_transport
*)arg
, commands
))
4959 return SCTP_DISPOSITION_NOMEM
;
4962 * RFC 2960 (bis), section 8.3
4964 * D) Request an on-demand HEARTBEAT on a specific destination
4965 * transport address of a given association.
4967 * The endpoint should increment the respective error counter of
4968 * the destination transport address each time a HEARTBEAT is sent
4969 * to that address and not acknowledged within one RTO.
4972 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
4973 SCTP_TRANSPORT(arg
));
4974 return SCTP_DISPOSITION_CONSUME
;
4978 * ADDIP Section 4.1 ASCONF Chunk Procedures
4979 * When an endpoint has an ASCONF signaled change to be sent to the
4980 * remote endpoint it should do A1 to A9
4982 sctp_disposition_t
sctp_sf_do_prm_asconf(const struct sctp_endpoint
*ep
,
4983 const struct sctp_association
*asoc
,
4984 const sctp_subtype_t type
,
4986 sctp_cmd_seq_t
*commands
)
4988 struct sctp_chunk
*chunk
= arg
;
4990 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
4991 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4992 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
4993 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
4994 return SCTP_DISPOSITION_CONSUME
;
4998 * Ignore the primitive event
5000 * The return value is the disposition of the primitive.
5002 sctp_disposition_t
sctp_sf_ignore_primitive(
5003 const struct sctp_endpoint
*ep
,
5004 const struct sctp_association
*asoc
,
5005 const sctp_subtype_t type
,
5007 sctp_cmd_seq_t
*commands
)
5009 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type
.primitive
);
5010 return SCTP_DISPOSITION_DISCARD
;
5013 /***************************************************************************
5014 * These are the state functions for the OTHER events.
5015 ***************************************************************************/
5018 * Start the shutdown negotiation.
5021 * Once all its outstanding data has been acknowledged, the endpoint
5022 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
5023 * TSN Ack field the last sequential TSN it has received from the peer.
5024 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
5025 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
5026 * with the updated last sequential TSN received from its peer.
5028 * The return value is the disposition.
5030 sctp_disposition_t
sctp_sf_do_9_2_start_shutdown(
5031 const struct sctp_endpoint
*ep
,
5032 const struct sctp_association
*asoc
,
5033 const sctp_subtype_t type
,
5035 sctp_cmd_seq_t
*commands
)
5037 struct sctp_chunk
*reply
;
5039 /* Once all its outstanding data has been acknowledged, the
5040 * endpoint shall send a SHUTDOWN chunk to its peer including
5041 * in the Cumulative TSN Ack field the last sequential TSN it
5042 * has received from the peer.
5044 reply
= sctp_make_shutdown(asoc
, NULL
);
5048 /* Set the transport for the SHUTDOWN chunk and the timeout for the
5049 * T2-shutdown timer.
5051 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5053 /* It shall then start the T2-shutdown timer */
5054 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5055 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5057 /* RFC 4960 Section 9.2
5058 * The sender of the SHUTDOWN MAY also start an overall guard timer
5059 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5061 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5062 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5064 if (asoc
->autoclose
)
5065 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5066 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5068 /* and enter the SHUTDOWN-SENT state. */
5069 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5070 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT
));
5072 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5074 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5077 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5079 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5081 return SCTP_DISPOSITION_CONSUME
;
5084 return SCTP_DISPOSITION_NOMEM
;
5088 * Generate a SHUTDOWN ACK now that everything is SACK'd.
5092 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5093 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
5094 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
5095 * endpoint must re-send the SHUTDOWN ACK.
5097 * The return value is the disposition.
5099 sctp_disposition_t
sctp_sf_do_9_2_shutdown_ack(
5100 const struct sctp_endpoint
*ep
,
5101 const struct sctp_association
*asoc
,
5102 const sctp_subtype_t type
,
5104 sctp_cmd_seq_t
*commands
)
5106 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
5107 struct sctp_chunk
*reply
;
5109 /* There are 2 ways of getting here:
5110 * 1) called in response to a SHUTDOWN chunk
5111 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
5113 * For the case (2), the arg parameter is set to NULL. We need
5114 * to check that we have a chunk before accessing it's fields.
5117 if (!sctp_vtag_verify(chunk
, asoc
))
5118 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
5120 /* Make sure that the SHUTDOWN chunk has a valid length. */
5121 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_shutdown_chunk_t
)))
5122 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
5126 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5127 * shall send a SHUTDOWN ACK ...
5129 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
5133 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
5134 * the T2-shutdown timer.
5136 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5138 /* and start/restart a T2-shutdown timer of its own, */
5139 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5140 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5142 if (asoc
->autoclose
)
5143 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5144 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5146 /* Enter the SHUTDOWN-ACK-SENT state. */
5147 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5148 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT
));
5150 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5152 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5155 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5157 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5159 return SCTP_DISPOSITION_CONSUME
;
5162 return SCTP_DISPOSITION_NOMEM
;
5166 * Ignore the event defined as other
5168 * The return value is the disposition of the event.
5170 sctp_disposition_t
sctp_sf_ignore_other(const struct sctp_endpoint
*ep
,
5171 const struct sctp_association
*asoc
,
5172 const sctp_subtype_t type
,
5174 sctp_cmd_seq_t
*commands
)
5176 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type
.other
);
5177 return SCTP_DISPOSITION_DISCARD
;
5180 /************************************************************
5181 * These are the state functions for handling timeout events.
5182 ************************************************************/
5187 * Section: 6.3.3 Handle T3-rtx Expiration
5189 * Whenever the retransmission timer T3-rtx expires for a destination
5190 * address, do the following:
5193 * The return value is the disposition of the chunk.
5195 sctp_disposition_t
sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint
*ep
,
5196 const struct sctp_association
*asoc
,
5197 const sctp_subtype_t type
,
5199 sctp_cmd_seq_t
*commands
)
5201 struct sctp_transport
*transport
= arg
;
5203 SCTP_INC_STATS(SCTP_MIB_T3_RTX_EXPIREDS
);
5205 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5206 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5207 SCTP_ERROR(ETIMEDOUT
));
5208 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5209 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5210 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5211 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
5212 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
5213 return SCTP_DISPOSITION_DELETE_TCB
;
5216 /* E1) For the destination address for which the timer
5217 * expires, adjust its ssthresh with rules defined in Section
5218 * 7.2.3 and set the cwnd <- MTU.
5221 /* E2) For the destination address for which the timer
5222 * expires, set RTO <- RTO * 2 ("back off the timer"). The
5223 * maximum value discussed in rule C7 above (RTO.max) may be
5224 * used to provide an upper bound to this doubling operation.
5227 /* E3) Determine how many of the earliest (i.e., lowest TSN)
5228 * outstanding DATA chunks for the address for which the
5229 * T3-rtx has expired will fit into a single packet, subject
5230 * to the MTU constraint for the path corresponding to the
5231 * destination transport address to which the retransmission
5232 * is being sent (this may be different from the address for
5233 * which the timer expires [see Section 6.4]). Call this
5234 * value K. Bundle and retransmit those K DATA chunks in a
5235 * single packet to the destination endpoint.
5237 * Note: Any DATA chunks that were sent to the address for
5238 * which the T3-rtx timer expired but did not fit in one MTU
5239 * (rule E3 above), should be marked for retransmission and
5240 * sent as soon as cwnd allows (normally when a SACK arrives).
5243 /* Do some failure management (Section 8.2). */
5244 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
5246 /* NB: Rules E4 and F1 are implicit in R1. */
5247 sctp_add_cmd_sf(commands
, SCTP_CMD_RETRAN
, SCTP_TRANSPORT(transport
));
5249 return SCTP_DISPOSITION_CONSUME
;
5253 * Generate delayed SACK on timeout
5255 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
5257 * The guidelines on delayed acknowledgement algorithm specified in
5258 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
5259 * acknowledgement SHOULD be generated for at least every second packet
5260 * (not every second DATA chunk) received, and SHOULD be generated
5261 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
5262 * some situations it may be beneficial for an SCTP transmitter to be
5263 * more conservative than the algorithms detailed in this document
5264 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
5265 * the following algorithms allow.
5267 sctp_disposition_t
sctp_sf_do_6_2_sack(const struct sctp_endpoint
*ep
,
5268 const struct sctp_association
*asoc
,
5269 const sctp_subtype_t type
,
5271 sctp_cmd_seq_t
*commands
)
5273 SCTP_INC_STATS(SCTP_MIB_DELAY_SACK_EXPIREDS
);
5274 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
5275 return SCTP_DISPOSITION_CONSUME
;
5279 * sctp_sf_t1_init_timer_expire
5281 * Section: 4 Note: 2
5286 * RFC 2960 Section 4 Notes
5287 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
5288 * and re-start the T1-init timer without changing state. This MUST
5289 * be repeated up to 'Max.Init.Retransmits' times. After that, the
5290 * endpoint MUST abort the initialization process and report the
5291 * error to SCTP user.
5297 sctp_disposition_t
sctp_sf_t1_init_timer_expire(const struct sctp_endpoint
*ep
,
5298 const struct sctp_association
*asoc
,
5299 const sctp_subtype_t type
,
5301 sctp_cmd_seq_t
*commands
)
5303 struct sctp_chunk
*repl
= NULL
;
5304 struct sctp_bind_addr
*bp
;
5305 int attempts
= asoc
->init_err_counter
+ 1;
5307 SCTP_DEBUG_PRINTK("Timer T1 expired (INIT).\n");
5308 SCTP_INC_STATS(SCTP_MIB_T1_INIT_EXPIREDS
);
5310 if (attempts
<= asoc
->max_init_attempts
) {
5311 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
5312 repl
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, 0);
5314 return SCTP_DISPOSITION_NOMEM
;
5316 /* Choose transport for INIT. */
5317 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5320 /* Issue a sideeffect to do the needed accounting. */
5321 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_RESTART
,
5322 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5324 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5326 SCTP_DEBUG_PRINTK("Giving up on INIT, attempts: %d"
5327 " max_init_attempts: %d\n",
5328 attempts
, asoc
->max_init_attempts
);
5329 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5330 SCTP_ERROR(ETIMEDOUT
));
5331 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5332 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5333 return SCTP_DISPOSITION_DELETE_TCB
;
5336 return SCTP_DISPOSITION_CONSUME
;
5340 * sctp_sf_t1_cookie_timer_expire
5342 * Section: 4 Note: 2
5347 * RFC 2960 Section 4 Notes
5348 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
5349 * COOKIE ECHO and re-start the T1-cookie timer without changing
5350 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
5351 * After that, the endpoint MUST abort the initialization process and
5352 * report the error to SCTP user.
5358 sctp_disposition_t
sctp_sf_t1_cookie_timer_expire(const struct sctp_endpoint
*ep
,
5359 const struct sctp_association
*asoc
,
5360 const sctp_subtype_t type
,
5362 sctp_cmd_seq_t
*commands
)
5364 struct sctp_chunk
*repl
= NULL
;
5365 int attempts
= asoc
->init_err_counter
+ 1;
5367 SCTP_DEBUG_PRINTK("Timer T1 expired (COOKIE-ECHO).\n");
5368 SCTP_INC_STATS(SCTP_MIB_T1_COOKIE_EXPIREDS
);
5370 if (attempts
<= asoc
->max_init_attempts
) {
5371 repl
= sctp_make_cookie_echo(asoc
, NULL
);
5373 return SCTP_DISPOSITION_NOMEM
;
5375 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5377 /* Issue a sideeffect to do the needed accounting. */
5378 sctp_add_cmd_sf(commands
, SCTP_CMD_COOKIEECHO_RESTART
,
5379 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
5381 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5383 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5384 SCTP_ERROR(ETIMEDOUT
));
5385 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5386 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5387 return SCTP_DISPOSITION_DELETE_TCB
;
5390 return SCTP_DISPOSITION_CONSUME
;
5393 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
5394 * with the updated last sequential TSN received from its peer.
5396 * An endpoint should limit the number of retransmissions of the
5397 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
5398 * If this threshold is exceeded the endpoint should destroy the TCB and
5399 * MUST report the peer endpoint unreachable to the upper layer (and
5400 * thus the association enters the CLOSED state). The reception of any
5401 * packet from its peer (i.e. as the peer sends all of its queued DATA
5402 * chunks) should clear the endpoint's retransmission count and restart
5403 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
5404 * all of its queued DATA chunks that have not yet been sent.
5406 sctp_disposition_t
sctp_sf_t2_timer_expire(const struct sctp_endpoint
*ep
,
5407 const struct sctp_association
*asoc
,
5408 const sctp_subtype_t type
,
5410 sctp_cmd_seq_t
*commands
)
5412 struct sctp_chunk
*reply
= NULL
;
5414 SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
5415 SCTP_INC_STATS(SCTP_MIB_T2_SHUTDOWN_EXPIREDS
);
5417 ((struct sctp_association
*)asoc
)->shutdown_retries
++;
5419 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5420 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5421 SCTP_ERROR(ETIMEDOUT
));
5422 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5423 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5424 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5425 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
5426 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
5427 return SCTP_DISPOSITION_DELETE_TCB
;
5430 switch (asoc
->state
) {
5431 case SCTP_STATE_SHUTDOWN_SENT
:
5432 reply
= sctp_make_shutdown(asoc
, NULL
);
5435 case SCTP_STATE_SHUTDOWN_ACK_SENT
:
5436 reply
= sctp_make_shutdown_ack(asoc
, NULL
);
5447 /* Do some failure management (Section 8.2).
5448 * If we remove the transport an SHUTDOWN was last sent to, don't
5449 * do failure management.
5451 if (asoc
->shutdown_last_sent_to
)
5452 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5453 SCTP_TRANSPORT(asoc
->shutdown_last_sent_to
));
5455 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
5456 * the T2-shutdown timer.
5458 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5460 /* Restart the T2-shutdown timer. */
5461 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5462 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5463 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5464 return SCTP_DISPOSITION_CONSUME
;
5467 return SCTP_DISPOSITION_NOMEM
;
5471 * ADDIP Section 4.1 ASCONF CHunk Procedures
5472 * If the T4 RTO timer expires the endpoint should do B1 to B5
5474 sctp_disposition_t
sctp_sf_t4_timer_expire(
5475 const struct sctp_endpoint
*ep
,
5476 const struct sctp_association
*asoc
,
5477 const sctp_subtype_t type
,
5479 sctp_cmd_seq_t
*commands
)
5481 struct sctp_chunk
*chunk
= asoc
->addip_last_asconf
;
5482 struct sctp_transport
*transport
= chunk
->transport
;
5484 SCTP_INC_STATS(SCTP_MIB_T4_RTO_EXPIREDS
);
5486 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
5487 * detection on the appropriate destination address as defined in
5488 * RFC2960 [5] section 8.1 and 8.2.
5491 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5492 SCTP_TRANSPORT(transport
));
5494 /* Reconfig T4 timer and transport. */
5495 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5497 /* ADDIP 4.1 B2) Increment the association error counters and perform
5498 * endpoint failure detection on the association as defined in
5499 * RFC2960 [5] section 8.1 and 8.2.
5500 * association error counter is incremented in SCTP_CMD_STRIKE.
5502 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5503 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5504 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5505 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5506 SCTP_ERROR(ETIMEDOUT
));
5507 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5508 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5509 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
5510 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
5511 return SCTP_DISPOSITION_ABORT
;
5514 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
5515 * the ASCONF chunk was sent by doubling the RTO timer value.
5516 * This is done in SCTP_CMD_STRIKE.
5519 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
5520 * choose an alternate destination address (please refer to RFC2960
5521 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
5522 * chunk, it MUST be the same (including its serial number) as the last
5525 sctp_chunk_hold(asoc
->addip_last_asconf
);
5526 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5527 SCTP_CHUNK(asoc
->addip_last_asconf
));
5529 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
5530 * destination is selected, then the RTO used will be that of the new
5531 * destination address.
5533 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5534 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5536 return SCTP_DISPOSITION_CONSUME
;
5539 /* sctpimpguide-05 Section 2.12.2
5540 * The sender of the SHUTDOWN MAY also start an overall guard timer
5541 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5542 * At the expiration of this timer the sender SHOULD abort the association
5543 * by sending an ABORT chunk.
5545 sctp_disposition_t
sctp_sf_t5_timer_expire(const struct sctp_endpoint
*ep
,
5546 const struct sctp_association
*asoc
,
5547 const sctp_subtype_t type
,
5549 sctp_cmd_seq_t
*commands
)
5551 struct sctp_chunk
*reply
= NULL
;
5553 SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
5554 SCTP_INC_STATS(SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS
);
5556 reply
= sctp_make_abort(asoc
, NULL
, 0);
5560 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5561 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5562 SCTP_ERROR(ETIMEDOUT
));
5563 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5564 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5566 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
5567 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
5569 return SCTP_DISPOSITION_DELETE_TCB
;
5571 return SCTP_DISPOSITION_NOMEM
;
5574 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
5575 * the association is automatically closed by starting the shutdown process.
5576 * The work that needs to be done is same as when SHUTDOWN is initiated by
5577 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
5579 sctp_disposition_t
sctp_sf_autoclose_timer_expire(
5580 const struct sctp_endpoint
*ep
,
5581 const struct sctp_association
*asoc
,
5582 const sctp_subtype_t type
,
5584 sctp_cmd_seq_t
*commands
)
5588 SCTP_INC_STATS(SCTP_MIB_AUTOCLOSE_EXPIREDS
);
5590 /* From 9.2 Shutdown of an Association
5591 * Upon receipt of the SHUTDOWN primitive from its upper
5592 * layer, the endpoint enters SHUTDOWN-PENDING state and
5593 * remains there until all outstanding data has been
5594 * acknowledged by its peer. The endpoint accepts no new data
5595 * from its upper layer, but retransmits data to the far end
5596 * if necessary to fill gaps.
5598 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5599 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
5601 disposition
= SCTP_DISPOSITION_CONSUME
;
5602 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
5603 disposition
= sctp_sf_do_9_2_start_shutdown(ep
, asoc
, type
,
5609 /*****************************************************************************
5610 * These are sa state functions which could apply to all types of events.
5611 ****************************************************************************/
5614 * This table entry is not implemented.
5617 * (endpoint, asoc, chunk)
5619 * The return value is the disposition of the chunk.
5621 sctp_disposition_t
sctp_sf_not_impl(const struct sctp_endpoint
*ep
,
5622 const struct sctp_association
*asoc
,
5623 const sctp_subtype_t type
,
5625 sctp_cmd_seq_t
*commands
)
5627 return SCTP_DISPOSITION_NOT_IMPL
;
5631 * This table entry represents a bug.
5634 * (endpoint, asoc, chunk)
5636 * The return value is the disposition of the chunk.
5638 sctp_disposition_t
sctp_sf_bug(const struct sctp_endpoint
*ep
,
5639 const struct sctp_association
*asoc
,
5640 const sctp_subtype_t type
,
5642 sctp_cmd_seq_t
*commands
)
5644 return SCTP_DISPOSITION_BUG
;
5648 * This table entry represents the firing of a timer in the wrong state.
5649 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
5650 * when the association is in the wrong state. This event should
5651 * be ignored, so as to prevent any rearming of the timer.
5654 * (endpoint, asoc, chunk)
5656 * The return value is the disposition of the chunk.
5658 sctp_disposition_t
sctp_sf_timer_ignore(const struct sctp_endpoint
*ep
,
5659 const struct sctp_association
*asoc
,
5660 const sctp_subtype_t type
,
5662 sctp_cmd_seq_t
*commands
)
5664 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type
.chunk
);
5665 return SCTP_DISPOSITION_CONSUME
;
5668 /********************************************************************
5669 * 2nd Level Abstractions
5670 ********************************************************************/
5672 /* Pull the SACK chunk based on the SACK header. */
5673 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
)
5675 struct sctp_sackhdr
*sack
;
5680 /* Protect ourselves from reading too far into
5681 * the skb from a bogus sender.
5683 sack
= (struct sctp_sackhdr
*) chunk
->skb
->data
;
5685 num_blocks
= ntohs(sack
->num_gap_ack_blocks
);
5686 num_dup_tsns
= ntohs(sack
->num_dup_tsns
);
5687 len
= sizeof(struct sctp_sackhdr
);
5688 len
+= (num_blocks
+ num_dup_tsns
) * sizeof(__u32
);
5689 if (len
> chunk
->skb
->len
)
5692 skb_pull(chunk
->skb
, len
);
5697 /* Create an ABORT packet to be sent as a response, with the specified
5700 static struct sctp_packet
*sctp_abort_pkt_new(const struct sctp_endpoint
*ep
,
5701 const struct sctp_association
*asoc
,
5702 struct sctp_chunk
*chunk
,
5703 const void *payload
,
5706 struct sctp_packet
*packet
;
5707 struct sctp_chunk
*abort
;
5709 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
5713 * The T bit will be set if the asoc is NULL.
5715 abort
= sctp_make_abort(asoc
, chunk
, paylen
);
5717 sctp_ootb_pkt_free(packet
);
5721 /* Reflect vtag if T-Bit is set */
5722 if (sctp_test_T_bit(abort
))
5723 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
5725 /* Add specified error causes, i.e., payload, to the
5728 sctp_addto_chunk(abort
, paylen
, payload
);
5730 /* Set the skb to the belonging sock for accounting. */
5731 abort
->skb
->sk
= ep
->base
.sk
;
5733 sctp_packet_append_chunk(packet
, abort
);
5740 /* Allocate a packet for responding in the OOTB conditions. */
5741 static struct sctp_packet
*sctp_ootb_pkt_new(const struct sctp_association
*asoc
,
5742 const struct sctp_chunk
*chunk
)
5744 struct sctp_packet
*packet
;
5745 struct sctp_transport
*transport
;
5750 /* Get the source and destination port from the inbound packet. */
5751 sport
= ntohs(chunk
->sctp_hdr
->dest
);
5752 dport
= ntohs(chunk
->sctp_hdr
->source
);
5754 /* The V-tag is going to be the same as the inbound packet if no
5755 * association exists, otherwise, use the peer's vtag.
5758 /* Special case the INIT-ACK as there is no peer's vtag
5761 switch(chunk
->chunk_hdr
->type
) {
5762 case SCTP_CID_INIT_ACK
:
5764 sctp_initack_chunk_t
*initack
;
5766 initack
= (sctp_initack_chunk_t
*)chunk
->chunk_hdr
;
5767 vtag
= ntohl(initack
->init_hdr
.init_tag
);
5771 vtag
= asoc
->peer
.i
.init_tag
;
5775 /* Special case the INIT and stale COOKIE_ECHO as there is no
5778 switch(chunk
->chunk_hdr
->type
) {
5781 sctp_init_chunk_t
*init
;
5783 init
= (sctp_init_chunk_t
*)chunk
->chunk_hdr
;
5784 vtag
= ntohl(init
->init_hdr
.init_tag
);
5788 vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
5793 /* Make a transport for the bucket, Eliza... */
5794 transport
= sctp_transport_new(sctp_source(chunk
), GFP_ATOMIC
);
5798 /* Cache a route for the transport with the chunk's destination as
5799 * the source address.
5801 sctp_transport_route(transport
, (union sctp_addr
*)&chunk
->dest
,
5802 sctp_sk(sctp_get_ctl_sock()));
5804 packet
= sctp_packet_init(&transport
->packet
, transport
, sport
, dport
);
5805 packet
= sctp_packet_config(packet
, vtag
, 0);
5813 /* Free the packet allocated earlier for responding in the OOTB condition. */
5814 void sctp_ootb_pkt_free(struct sctp_packet
*packet
)
5816 sctp_transport_free(packet
->transport
);
5819 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
5820 static void sctp_send_stale_cookie_err(const struct sctp_endpoint
*ep
,
5821 const struct sctp_association
*asoc
,
5822 const struct sctp_chunk
*chunk
,
5823 sctp_cmd_seq_t
*commands
,
5824 struct sctp_chunk
*err_chunk
)
5826 struct sctp_packet
*packet
;
5829 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
5831 struct sctp_signed_cookie
*cookie
;
5833 /* Override the OOTB vtag from the cookie. */
5834 cookie
= chunk
->subh
.cookie_hdr
;
5835 packet
->vtag
= cookie
->c
.peer_vtag
;
5837 /* Set the skb to the belonging sock for accounting. */
5838 err_chunk
->skb
->sk
= ep
->base
.sk
;
5839 sctp_packet_append_chunk(packet
, err_chunk
);
5840 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
5841 SCTP_PACKET(packet
));
5842 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
5844 sctp_chunk_free (err_chunk
);
5849 /* Process a data chunk */
5850 static int sctp_eat_data(const struct sctp_association
*asoc
,
5851 struct sctp_chunk
*chunk
,
5852 sctp_cmd_seq_t
*commands
)
5854 sctp_datahdr_t
*data_hdr
;
5855 struct sctp_chunk
*err
;
5857 sctp_verb_t deliver
;
5860 struct sctp_tsnmap
*map
= (struct sctp_tsnmap
*)&asoc
->peer
.tsn_map
;
5861 struct sock
*sk
= asoc
->base
.sk
;
5866 data_hdr
= chunk
->subh
.data_hdr
= (sctp_datahdr_t
*)chunk
->skb
->data
;
5867 skb_pull(chunk
->skb
, sizeof(sctp_datahdr_t
));
5869 tsn
= ntohl(data_hdr
->tsn
);
5870 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn
);
5872 /* ASSERT: Now skb->data is really the user data. */
5874 /* Process ECN based congestion.
5876 * Since the chunk structure is reused for all chunks within
5877 * a packet, we use ecn_ce_done to track if we've already
5878 * done CE processing for this packet.
5880 * We need to do ECN processing even if we plan to discard the
5884 if (!chunk
->ecn_ce_done
) {
5886 chunk
->ecn_ce_done
= 1;
5888 af
= sctp_get_af_specific(
5889 ipver2af(ip_hdr(chunk
->skb
)->version
));
5891 if (af
&& af
->is_ce(chunk
->skb
) && asoc
->peer
.ecn_capable
) {
5892 /* Do real work as sideffect. */
5893 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_CE
,
5898 tmp
= sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
);
5900 /* The TSN is too high--silently discard the chunk and
5901 * count on it getting retransmitted later.
5903 return SCTP_IERROR_HIGH_TSN
;
5904 } else if (tmp
> 0) {
5905 /* This is a duplicate. Record it. */
5906 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_DUP
, SCTP_U32(tsn
));
5907 return SCTP_IERROR_DUP_TSN
;
5910 /* This is a new TSN. */
5912 /* Discard if there is no room in the receive window.
5913 * Actually, allow a little bit of overflow (up to a MTU).
5915 datalen
= ntohs(chunk
->chunk_hdr
->length
);
5916 datalen
-= sizeof(sctp_data_chunk_t
);
5918 deliver
= SCTP_CMD_CHUNK_ULP
;
5920 /* Think about partial delivery. */
5921 if ((datalen
>= asoc
->rwnd
) && (!asoc
->ulpq
.pd_mode
)) {
5923 /* Even if we don't accept this chunk there is
5926 sctp_add_cmd_sf(commands
, SCTP_CMD_PART_DELIVER
, SCTP_NULL());
5929 /* Spill over rwnd a little bit. Note: While allowed, this spill over
5930 * seems a bit troublesome in that frag_point varies based on
5931 * PMTU. In cases, such as loopback, this might be a rather
5934 if ((!chunk
->data_accepted
) && (!asoc
->rwnd
|| asoc
->rwnd_over
||
5935 (datalen
> asoc
->rwnd
+ asoc
->frag_point
))) {
5937 /* If this is the next TSN, consider reneging to make
5938 * room. Note: Playing nice with a confused sender. A
5939 * malicious sender can still eat up all our buffer
5940 * space and in the future we may want to detect and
5941 * do more drastic reneging.
5943 if (sctp_tsnmap_has_gap(map
) &&
5944 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
5945 SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn
);
5946 deliver
= SCTP_CMD_RENEGE
;
5948 SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
5949 "rwnd: %d\n", tsn
, datalen
,
5951 return SCTP_IERROR_IGNORE_TSN
;
5956 * Also try to renege to limit our memory usage in the event that
5957 * we are under memory pressure
5958 * If we can't renege, don't worry about it, the sk_rmem_schedule
5959 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
5960 * memory usage too much
5962 if (*sk
->sk_prot_creator
->memory_pressure
) {
5963 if (sctp_tsnmap_has_gap(map
) &&
5964 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
5965 SCTP_DEBUG_PRINTK("Under Pressure! Reneging for tsn:%u\n", tsn
);
5966 deliver
= SCTP_CMD_RENEGE
;
5971 * Section 3.3.10.9 No User Data (9)
5975 * No User Data: This error cause is returned to the originator of a
5976 * DATA chunk if a received DATA chunk has no user data.
5978 if (unlikely(0 == datalen
)) {
5979 err
= sctp_make_abort_no_data(asoc
, chunk
, tsn
);
5981 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5984 /* We are going to ABORT, so we might as well stop
5985 * processing the rest of the chunks in the packet.
5987 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
5988 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5989 SCTP_ERROR(ECONNABORTED
));
5990 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5991 SCTP_PERR(SCTP_ERROR_NO_DATA
));
5992 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
5993 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
5994 return SCTP_IERROR_NO_DATA
;
5997 chunk
->data_accepted
= 1;
5999 /* Note: Some chunks may get overcounted (if we drop) or overcounted
6000 * if we renege and the chunk arrives again.
6002 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_UNORDERED
)
6003 SCTP_INC_STATS(SCTP_MIB_INUNORDERCHUNKS
);
6005 SCTP_INC_STATS(SCTP_MIB_INORDERCHUNKS
);
6009 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
6011 * If an endpoint receive a DATA chunk with an invalid stream
6012 * identifier, it shall acknowledge the reception of the DATA chunk
6013 * following the normal procedure, immediately send an ERROR chunk
6014 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
6015 * and discard the DATA chunk.
6017 sid
= ntohs(data_hdr
->stream
);
6018 if (sid
>= asoc
->c
.sinit_max_instreams
) {
6019 /* Mark tsn as received even though we drop it */
6020 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_TSN
, SCTP_U32(tsn
));
6022 err
= sctp_make_op_error(asoc
, chunk
, SCTP_ERROR_INV_STRM
,
6024 sizeof(data_hdr
->stream
),
6027 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6029 return SCTP_IERROR_BAD_STREAM
;
6032 /* Check to see if the SSN is possible for this TSN.
6033 * The biggest gap we can record is 4K wide. Since SSNs wrap
6034 * at an unsigned short, there is no way that an SSN can
6035 * wrap and for a valid TSN. We can simply check if the current
6036 * SSN is smaller then the next expected one. If it is, it wrapped
6039 ssn
= ntohs(data_hdr
->ssn
);
6040 if (ordered
&& SSN_lt(ssn
, sctp_ssn_peek(&asoc
->ssnmap
->in
, sid
))) {
6041 return SCTP_IERROR_PROTO_VIOLATION
;
6044 /* Send the data up to the user. Note: Schedule the
6045 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
6046 * chunk needs the updated rwnd.
6048 sctp_add_cmd_sf(commands
, deliver
, SCTP_CHUNK(chunk
));
6050 return SCTP_IERROR_NO_ERROR
;