1 /* SCTP kernel reference 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 file is part of the SCTP kernel reference Implementation
10 * This is part of the SCTP Linux Kernel Reference Implementation.
12 * These are the state functions for the state machine.
14 * The SCTP reference implementation is free software;
15 * you can redistribute it and/or modify it under the terms of
16 * the GNU General Public License as published by
17 * the Free Software Foundation; either version 2, or (at your option)
20 * The SCTP reference implementation is distributed in the hope that it
21 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
22 * ************************
23 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 * See the GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with GNU CC; see the file COPYING. If not, write to
28 * the Free Software Foundation, 59 Temple Place - Suite 330,
29 * Boston, MA 02111-1307, USA.
31 * Please send any bug reports or fixes you make to the
33 * lksctp developers <lksctp-developers@lists.sourceforge.net>
35 * Or submit a bug report through the following website:
36 * http://www.sf.net/projects/lksctp
38 * Written or modified by:
39 * La Monte H.P. Yarroll <piggy@acm.org>
40 * Karl Knutson <karl@athena.chicago.il.us>
41 * Mathew Kotowsky <kotowsky@sctp.org>
42 * Sridhar Samudrala <samudrala@us.ibm.com>
43 * Jon Grimm <jgrimm@us.ibm.com>
44 * Hui Huang <hui.huang@nokia.com>
45 * Dajiang Zhang <dajiang.zhang@nokia.com>
46 * Daisy Chang <daisyc@us.ibm.com>
47 * Ardelle Fan <ardelle.fan@intel.com>
48 * Ryan Layer <rmlayer@us.ibm.com>
49 * Kevin Gao <kevin.gao@intel.com>
51 * Any bugs reported given to us we will try to fix... any fixes shared will
52 * be incorporated into the next SCTP release.
55 #include <linux/types.h>
56 #include <linux/kernel.h>
58 #include <linux/ipv6.h>
59 #include <linux/net.h>
60 #include <linux/inet.h>
62 #include <net/inet_ecn.h>
63 #include <linux/skbuff.h>
64 #include <net/sctp/sctp.h>
65 #include <net/sctp/sm.h>
66 #include <net/sctp/structs.h>
68 static struct sctp_packet
*sctp_abort_pkt_new(const struct sctp_endpoint
*ep
,
69 const struct sctp_association
*asoc
,
70 struct sctp_chunk
*chunk
,
73 static int sctp_eat_data(const struct sctp_association
*asoc
,
74 struct sctp_chunk
*chunk
,
75 sctp_cmd_seq_t
*commands
);
76 static struct sctp_packet
*sctp_ootb_pkt_new(const struct sctp_association
*asoc
,
77 const struct sctp_chunk
*chunk
);
78 static void sctp_send_stale_cookie_err(const struct sctp_endpoint
*ep
,
79 const struct sctp_association
*asoc
,
80 const struct sctp_chunk
*chunk
,
81 sctp_cmd_seq_t
*commands
,
82 struct sctp_chunk
*err_chunk
);
83 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(const struct sctp_endpoint
*ep
,
84 const struct sctp_association
*asoc
,
85 const sctp_subtype_t type
,
87 sctp_cmd_seq_t
*commands
);
88 static sctp_disposition_t
sctp_sf_shut_8_4_5(const struct sctp_endpoint
*ep
,
89 const struct sctp_association
*asoc
,
90 const sctp_subtype_t type
,
92 sctp_cmd_seq_t
*commands
);
93 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
);
95 static sctp_disposition_t
sctp_stop_t1_and_abort(sctp_cmd_seq_t
*commands
,
97 const struct sctp_association
*asoc
,
98 struct sctp_transport
*transport
);
100 static sctp_disposition_t
sctp_sf_violation_chunklen(
101 const struct sctp_endpoint
*ep
,
102 const struct sctp_association
*asoc
,
103 const sctp_subtype_t type
,
105 sctp_cmd_seq_t
*commands
);
107 /* Small helper function that checks if the chunk length
108 * is of the appropriate length. The 'required_length' argument
109 * is set to be the size of a specific chunk we are testing.
110 * Return Values: 1 = Valid length
115 sctp_chunk_length_valid(struct sctp_chunk
*chunk
,
116 __u16 required_length
)
118 __u16 chunk_length
= ntohs(chunk
->chunk_hdr
->length
);
120 if (unlikely(chunk_length
< required_length
))
126 /**********************************************************
127 * These are the state functions for handling chunk events.
128 **********************************************************/
131 * Process the final SHUTDOWN COMPLETE.
133 * Section: 4 (C) (diagram), 9.2
134 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
135 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
136 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
137 * should stop the T2-shutdown timer and remove all knowledge of the
138 * association (and thus the association enters the CLOSED state).
140 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
141 * C) Rules for packet carrying SHUTDOWN COMPLETE:
143 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
144 * if the Verification Tag field of the packet matches its own tag and
145 * the T bit is not set
147 * it is set to its peer's tag and the T bit is set in the Chunk
149 * Otherwise, the receiver MUST silently discard the packet
150 * and take no further action. An endpoint MUST ignore the
151 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
154 * (endpoint, asoc, chunk)
157 * (asoc, reply_msg, msg_up, timers, counters)
159 * The return value is the disposition of the chunk.
161 sctp_disposition_t
sctp_sf_do_4_C(const struct sctp_endpoint
*ep
,
162 const struct sctp_association
*asoc
,
163 const sctp_subtype_t type
,
165 sctp_cmd_seq_t
*commands
)
167 struct sctp_chunk
*chunk
= arg
;
168 struct sctp_ulpevent
*ev
;
170 /* RFC 2960 6.10 Bundling
172 * An endpoint MUST NOT bundle INIT, INIT ACK or
173 * SHUTDOWN COMPLETE with any other chunks.
175 if (!chunk
->singleton
)
176 return SCTP_DISPOSITION_VIOLATION
;
178 if (!sctp_vtag_verify_either(chunk
, asoc
))
179 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
181 /* RFC 2960 10.2 SCTP-to-ULP
183 * H) SHUTDOWN COMPLETE notification
185 * When SCTP completes the shutdown procedures (section 9.2) this
186 * notification is passed to the upper layer.
188 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
189 0, 0, 0, GFP_ATOMIC
);
193 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
195 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
196 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
197 * not the chunk should be discarded. If the endpoint is in
198 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
199 * T2-shutdown timer and remove all knowledge of the
200 * association (and thus the association enters the CLOSED
203 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
204 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
206 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
207 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
209 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
210 SCTP_STATE(SCTP_STATE_CLOSED
));
212 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS
);
213 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
215 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
217 return SCTP_DISPOSITION_DELETE_TCB
;
220 return SCTP_DISPOSITION_NOMEM
;
224 * Respond to a normal INIT chunk.
225 * We are the side that is being asked for an association.
227 * Section: 5.1 Normal Establishment of an Association, B
228 * B) "Z" shall respond immediately with an INIT ACK chunk. The
229 * destination IP address of the INIT ACK MUST be set to the source
230 * IP address of the INIT to which this INIT ACK is responding. In
231 * the response, besides filling in other parameters, "Z" must set the
232 * Verification Tag field to Tag_A, and also provide its own
233 * Verification Tag (Tag_Z) in the Initiate Tag field.
235 * Verification Tag: Must be 0.
238 * (endpoint, asoc, chunk)
241 * (asoc, reply_msg, msg_up, timers, counters)
243 * The return value is the disposition of the chunk.
245 sctp_disposition_t
sctp_sf_do_5_1B_init(const struct sctp_endpoint
*ep
,
246 const struct sctp_association
*asoc
,
247 const sctp_subtype_t type
,
249 sctp_cmd_seq_t
*commands
)
251 struct sctp_chunk
*chunk
= arg
;
252 struct sctp_chunk
*repl
;
253 struct sctp_association
*new_asoc
;
254 struct sctp_chunk
*err_chunk
;
255 struct sctp_packet
*packet
;
256 sctp_unrecognized_param_t
*unk_param
;
261 * An endpoint MUST NOT bundle INIT, INIT ACK or
262 * SHUTDOWN COMPLETE with any other chunks.
265 * Furthermore, we require that the receiver of an INIT chunk MUST
266 * enforce these rules by silently discarding an arriving packet
267 * with an INIT chunk that is bundled with other chunks.
269 if (!chunk
->singleton
)
270 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
272 /* If the packet is an OOTB packet which is temporarily on the
273 * control endpoint, respond with an ABORT.
275 if (ep
== sctp_sk((sctp_get_ctl_sock()))->ep
)
276 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
279 /* If the endpoint is not listening or if the number of associations
280 * on the TCP-style socket exceed the max backlog, respond with an
283 if (!sctp_sstate(sk
, LISTENING
) ||
284 (sctp_style(sk
, TCP
) &&
285 sk_acceptq_is_full(sk
)))
286 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
288 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
291 if (chunk
->sctp_hdr
->vtag
!= 0)
292 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
294 /* Make sure that the INIT chunk has a valid length.
295 * Normally, this would cause an ABORT with a Protocol Violation
296 * error, but since we don't have an association, we'll
297 * just discard the packet.
299 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_init_chunk_t
)))
300 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
302 /* Verify the INIT chunk before processing it. */
304 if (!sctp_verify_init(asoc
, chunk
->chunk_hdr
->type
,
305 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
307 /* This chunk contains fatal error. It is to be discarded.
308 * Send an ABORT, with causes if there is any.
311 packet
= sctp_abort_pkt_new(ep
, asoc
, arg
,
312 (__u8
*)(err_chunk
->chunk_hdr
) +
313 sizeof(sctp_chunkhdr_t
),
314 ntohs(err_chunk
->chunk_hdr
->length
) -
315 sizeof(sctp_chunkhdr_t
));
317 sctp_chunk_free(err_chunk
);
320 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
321 SCTP_PACKET(packet
));
322 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
323 return SCTP_DISPOSITION_CONSUME
;
325 return SCTP_DISPOSITION_NOMEM
;
328 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
,
333 /* Grab the INIT header. */
334 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*)chunk
->skb
->data
;
336 /* Tag the variable length parameters. */
337 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
339 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
343 /* The call, sctp_process_init(), can fail on memory allocation. */
344 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
346 (sctp_init_chunk_t
*)chunk
->chunk_hdr
,
350 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
352 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
354 /* If there are errors need to be reported for unknown parameters,
355 * make sure to reserve enough room in the INIT ACK for them.
359 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
360 sizeof(sctp_chunkhdr_t
);
362 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
, GFP_ATOMIC
) < 0)
365 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
369 /* If there are errors need to be reported for unknown parameters,
370 * include them in the outgoing INIT ACK as "Unrecognized parameter"
374 /* Get the "Unrecognized parameter" parameter(s) out of the
375 * ERROR chunk generated by sctp_verify_init(). Since the
376 * error cause code for "unknown parameter" and the
377 * "Unrecognized parameter" type is the same, we can
378 * construct the parameters in INIT ACK by copying the
381 unk_param
= (sctp_unrecognized_param_t
*)
382 ((__u8
*)(err_chunk
->chunk_hdr
) +
383 sizeof(sctp_chunkhdr_t
));
384 /* Replace the cause code with the "Unrecognized parameter"
387 sctp_addto_chunk(repl
, len
, unk_param
);
388 sctp_chunk_free(err_chunk
);
391 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
394 * Note: After sending out INIT ACK with the State Cookie parameter,
395 * "Z" MUST NOT allocate any resources, nor keep any states for the
396 * new association. Otherwise, "Z" will be vulnerable to resource
399 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
401 return SCTP_DISPOSITION_DELETE_TCB
;
405 sctp_chunk_free(err_chunk
);
407 sctp_association_free(new_asoc
);
409 return SCTP_DISPOSITION_NOMEM
;
413 * Respond to a normal INIT ACK chunk.
414 * We are the side that is initiating the association.
416 * Section: 5.1 Normal Establishment of an Association, C
417 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
418 * timer and leave COOKIE-WAIT state. "A" shall then send the State
419 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
420 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
422 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
423 * DATA chunks, but it MUST be the first chunk in the packet and
424 * until the COOKIE ACK is returned the sender MUST NOT send any
425 * other packets to the peer.
427 * Verification Tag: 3.3.3
428 * If the value of the Initiate Tag in a received INIT ACK chunk is
429 * found to be 0, the receiver MUST treat it as an error and close the
430 * association by transmitting an ABORT.
433 * (endpoint, asoc, chunk)
436 * (asoc, reply_msg, msg_up, timers, counters)
438 * The return value is the disposition of the chunk.
440 sctp_disposition_t
sctp_sf_do_5_1C_ack(const struct sctp_endpoint
*ep
,
441 const struct sctp_association
*asoc
,
442 const sctp_subtype_t type
,
444 sctp_cmd_seq_t
*commands
)
446 struct sctp_chunk
*chunk
= arg
;
447 sctp_init_chunk_t
*initchunk
;
449 struct sctp_chunk
*err_chunk
;
450 struct sctp_packet
*packet
;
451 sctp_disposition_t ret
;
453 if (!sctp_vtag_verify(chunk
, asoc
))
454 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
456 /* Make sure that the INIT-ACK chunk has a valid length */
457 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_initack_chunk_t
)))
458 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
461 * An endpoint MUST NOT bundle INIT, INIT ACK or
462 * SHUTDOWN COMPLETE with any other chunks.
464 if (!chunk
->singleton
)
465 return SCTP_DISPOSITION_VIOLATION
;
467 /* Grab the INIT header. */
468 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
470 init_tag
= ntohl(chunk
->subh
.init_hdr
->init_tag
);
472 /* Verification Tag: 3.3.3
473 * If the value of the Initiate Tag in a received INIT ACK
474 * chunk is found to be 0, the receiver MUST treat it as an
475 * error and close the association by transmitting an ABORT.
478 struct sctp_chunk
*reply
= sctp_make_abort(asoc
, chunk
, 0);
482 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
483 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
484 SCTP_STATE(SCTP_STATE_CLOSED
));
485 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
486 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
487 return SCTP_DISPOSITION_DELETE_TCB
;
490 /* Verify the INIT chunk before processing it. */
492 if (!sctp_verify_init(asoc
, chunk
->chunk_hdr
->type
,
493 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
496 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
498 /* This chunk contains fatal error. It is to be discarded.
499 * Send an ABORT, with causes if there is any.
502 packet
= sctp_abort_pkt_new(ep
, asoc
, arg
,
503 (__u8
*)(err_chunk
->chunk_hdr
) +
504 sizeof(sctp_chunkhdr_t
),
505 ntohs(err_chunk
->chunk_hdr
->length
) -
506 sizeof(sctp_chunkhdr_t
));
508 sctp_chunk_free(err_chunk
);
511 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
512 SCTP_PACKET(packet
));
513 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
514 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
515 SCTP_STATE(SCTP_STATE_CLOSED
));
516 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
,
518 return SCTP_DISPOSITION_CONSUME
;
520 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
521 SCTP_STATE(SCTP_STATE_CLOSED
));
522 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
,
524 return SCTP_DISPOSITION_NOMEM
;
527 ret
= sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
,
529 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
530 SCTP_STATE(SCTP_STATE_CLOSED
));
531 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
,
537 /* Tag the variable length parameters. Note that we never
538 * convert the parameters in an INIT chunk.
540 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
542 initchunk
= (sctp_init_chunk_t
*) chunk
->chunk_hdr
;
544 sctp_add_cmd_sf(commands
, SCTP_CMD_PEER_INIT
,
545 SCTP_PEER_INIT(initchunk
));
547 /* Reset init error count upon receipt of INIT-ACK. */
548 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
550 /* 5.1 C) "A" shall stop the T1-init timer and leave
551 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
552 * timer, and enter the COOKIE-ECHOED state.
554 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
555 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
556 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
557 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
558 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
559 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED
));
561 /* 5.1 C) "A" shall then send the State Cookie received in the
562 * INIT ACK chunk in a COOKIE ECHO chunk, ...
564 /* If there is any errors to report, send the ERROR chunk generated
565 * for unknown parameters as well.
567 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_COOKIE_ECHO
,
568 SCTP_CHUNK(err_chunk
));
570 return SCTP_DISPOSITION_CONSUME
;
573 return SCTP_DISPOSITION_NOMEM
;
577 * Respond to a normal COOKIE ECHO chunk.
578 * We are the side that is being asked for an association.
580 * Section: 5.1 Normal Establishment of an Association, D
581 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
582 * with a COOKIE ACK chunk after building a TCB and moving to
583 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
584 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
585 * chunk MUST be the first chunk in the packet.
587 * IMPLEMENTATION NOTE: An implementation may choose to send the
588 * Communication Up notification to the SCTP user upon reception
589 * of a valid COOKIE ECHO chunk.
591 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
592 * D) Rules for packet carrying a COOKIE ECHO
594 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
595 * Initial Tag received in the INIT ACK.
597 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
600 * (endpoint, asoc, chunk)
603 * (asoc, reply_msg, msg_up, timers, counters)
605 * The return value is the disposition of the chunk.
607 sctp_disposition_t
sctp_sf_do_5_1D_ce(const struct sctp_endpoint
*ep
,
608 const struct sctp_association
*asoc
,
609 const sctp_subtype_t type
, void *arg
,
610 sctp_cmd_seq_t
*commands
)
612 struct sctp_chunk
*chunk
= arg
;
613 struct sctp_association
*new_asoc
;
614 sctp_init_chunk_t
*peer_init
;
615 struct sctp_chunk
*repl
;
616 struct sctp_ulpevent
*ev
;
618 struct sctp_chunk
*err_chk_p
;
620 /* If the packet is an OOTB packet which is temporarily on the
621 * control endpoint, respond with an ABORT.
623 if (ep
== sctp_sk((sctp_get_ctl_sock()))->ep
)
624 return sctp_sf_ootb(ep
, asoc
, type
, arg
, commands
);
626 /* Make sure that the COOKIE_ECHO chunk has a valid length.
627 * In this case, we check that we have enough for at least a
628 * chunk header. More detailed verification is done
629 * in sctp_unpack_cookie().
631 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
632 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
634 /* "Decode" the chunk. We have no optional parameters so we
637 chunk
->subh
.cookie_hdr
=
638 (struct sctp_signed_cookie
*)chunk
->skb
->data
;
639 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
640 sizeof(sctp_chunkhdr_t
)))
643 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
644 * "Z" will reply with a COOKIE ACK chunk after building a TCB
645 * and moving to the ESTABLISHED state.
647 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
651 * If the re-build failed, what is the proper error path
654 * [We should abort the association. --piggy]
657 /* FIXME: Several errors are possible. A bad cookie should
658 * be silently discarded, but think about logging it too.
661 case -SCTP_IERROR_NOMEM
:
664 case -SCTP_IERROR_STALE_COOKIE
:
665 sctp_send_stale_cookie_err(ep
, asoc
, chunk
, commands
,
667 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
669 case -SCTP_IERROR_BAD_SIG
:
671 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
675 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
676 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
677 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
678 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
679 SCTP_INC_STATS(SCTP_MIB_PASSIVEESTABS
);
680 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
682 if (new_asoc
->autoclose
)
683 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
684 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
686 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSMIT
, SCTP_NULL());
688 /* Re-build the bind address for the association is done in
689 * the sctp_unpack_cookie() already.
691 /* This is a brand-new association, so these are not yet side
692 * effects--it is safe to run them here.
694 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
696 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
697 &chunk
->subh
.cookie_hdr
->c
.peer_addr
,
698 peer_init
, GFP_ATOMIC
))
701 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
705 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
707 /* RFC 2960 5.1 Normal Establishment of an Association
709 * D) IMPLEMENTATION NOTE: An implementation may choose to
710 * send the Communication Up notification to the SCTP user
711 * upon reception of a valid COOKIE ECHO chunk.
713 ev
= sctp_ulpevent_make_assoc_change(new_asoc
, 0, SCTP_COMM_UP
, 0,
714 new_asoc
->c
.sinit_num_ostreams
,
715 new_asoc
->c
.sinit_max_instreams
,
720 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
722 /* Sockets API Draft Section 5.3.1.6
723 * When a peer sends a Adaption Layer Indication parameter , SCTP
724 * delivers this notification to inform the application that of the
725 * peers requested adaption layer.
727 if (new_asoc
->peer
.adaption_ind
) {
728 ev
= sctp_ulpevent_make_adaption_indication(new_asoc
,
733 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
737 return SCTP_DISPOSITION_CONSUME
;
740 sctp_chunk_free(repl
);
743 sctp_association_free(new_asoc
);
745 return SCTP_DISPOSITION_NOMEM
;
749 * Respond to a normal COOKIE ACK chunk.
750 * We are the side that is being asked for an association.
752 * RFC 2960 5.1 Normal Establishment of an Association
754 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
755 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
756 * timer. It may also notify its ULP about the successful
757 * establishment of the association with a Communication Up
758 * notification (see Section 10).
762 * (endpoint, asoc, chunk)
765 * (asoc, reply_msg, msg_up, timers, counters)
767 * The return value is the disposition of the chunk.
769 sctp_disposition_t
sctp_sf_do_5_1E_ca(const struct sctp_endpoint
*ep
,
770 const struct sctp_association
*asoc
,
771 const sctp_subtype_t type
, void *arg
,
772 sctp_cmd_seq_t
*commands
)
774 struct sctp_chunk
*chunk
= arg
;
775 struct sctp_ulpevent
*ev
;
777 if (!sctp_vtag_verify(chunk
, asoc
))
778 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
780 /* Verify that the chunk length for the COOKIE-ACK is OK.
781 * If we don't do this, any bundled chunks may be junked.
783 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
784 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
787 /* Reset init error count upon receipt of COOKIE-ACK,
788 * to avoid problems with the managemement of this
789 * counter in stale cookie situations when a transition back
790 * from the COOKIE-ECHOED state to the COOKIE-WAIT
791 * state is performed.
793 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
795 /* RFC 2960 5.1 Normal Establishment of an Association
797 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
798 * from the COOKIE-ECHOED state to the ESTABLISHED state,
799 * stopping the T1-cookie timer.
801 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
802 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
803 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
804 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
805 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
806 SCTP_INC_STATS(SCTP_MIB_ACTIVEESTABS
);
807 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
809 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
810 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
811 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSMIT
, SCTP_NULL());
813 /* It may also notify its ULP about the successful
814 * establishment of the association with a Communication Up
815 * notification (see Section 10).
817 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_COMM_UP
,
818 0, asoc
->c
.sinit_num_ostreams
,
819 asoc
->c
.sinit_max_instreams
,
825 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
827 /* Sockets API Draft Section 5.3.1.6
828 * When a peer sends a Adaption Layer Indication parameter , SCTP
829 * delivers this notification to inform the application that of the
830 * peers requested adaption layer.
832 if (asoc
->peer
.adaption_ind
) {
833 ev
= sctp_ulpevent_make_adaption_indication(asoc
, GFP_ATOMIC
);
837 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
841 return SCTP_DISPOSITION_CONSUME
;
843 return SCTP_DISPOSITION_NOMEM
;
846 /* Generate and sendout a heartbeat packet. */
847 static sctp_disposition_t
sctp_sf_heartbeat(const struct sctp_endpoint
*ep
,
848 const struct sctp_association
*asoc
,
849 const sctp_subtype_t type
,
851 sctp_cmd_seq_t
*commands
)
853 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
854 struct sctp_chunk
*reply
;
855 sctp_sender_hb_info_t hbinfo
;
858 hbinfo
.param_hdr
.type
= SCTP_PARAM_HEARTBEAT_INFO
;
859 hbinfo
.param_hdr
.length
= htons(sizeof(sctp_sender_hb_info_t
));
860 hbinfo
.daddr
= transport
->ipaddr
;
861 hbinfo
.sent_at
= jiffies
;
863 /* Send a heartbeat to our peer. */
864 paylen
= sizeof(sctp_sender_hb_info_t
);
865 reply
= sctp_make_heartbeat(asoc
, transport
, &hbinfo
, paylen
);
867 return SCTP_DISPOSITION_NOMEM
;
869 /* Set rto_pending indicating that an RTT measurement
870 * is started with this heartbeat chunk.
872 sctp_add_cmd_sf(commands
, SCTP_CMD_RTO_PENDING
,
873 SCTP_TRANSPORT(transport
));
875 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
876 return SCTP_DISPOSITION_CONSUME
;
879 /* Generate a HEARTBEAT packet on the given transport. */
880 sctp_disposition_t
sctp_sf_sendbeat_8_3(const struct sctp_endpoint
*ep
,
881 const struct sctp_association
*asoc
,
882 const sctp_subtype_t type
,
884 sctp_cmd_seq_t
*commands
)
886 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
888 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
889 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
890 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
891 SCTP_U32(SCTP_ERROR_NO_ERROR
));
892 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
893 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
894 return SCTP_DISPOSITION_DELETE_TCB
;
898 * The Sender-specific Heartbeat Info field should normally include
899 * information about the sender's current time when this HEARTBEAT
900 * chunk is sent and the destination transport address to which this
901 * HEARTBEAT is sent (see Section 8.3).
904 if (transport
->param_flags
& SPP_HB_ENABLE
) {
905 if (SCTP_DISPOSITION_NOMEM
==
906 sctp_sf_heartbeat(ep
, asoc
, type
, arg
,
908 return SCTP_DISPOSITION_NOMEM
;
909 /* Set transport error counter and association error counter
910 * when sending heartbeat.
912 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_RESET
,
913 SCTP_TRANSPORT(transport
));
915 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMER_UPDATE
,
916 SCTP_TRANSPORT(transport
));
918 return SCTP_DISPOSITION_CONSUME
;
922 * Process an heartbeat request.
924 * Section: 8.3 Path Heartbeat
925 * The receiver of the HEARTBEAT should immediately respond with a
926 * HEARTBEAT ACK that contains the Heartbeat Information field copied
927 * from the received HEARTBEAT chunk.
929 * Verification Tag: 8.5 Verification Tag [Normal verification]
930 * When receiving an SCTP packet, the endpoint MUST ensure that the
931 * value in the Verification Tag field of the received SCTP packet
932 * matches its own Tag. If the received Verification Tag value does not
933 * match the receiver's own tag value, the receiver shall silently
934 * discard the packet and shall not process it any further except for
935 * those cases listed in Section 8.5.1 below.
938 * (endpoint, asoc, chunk)
941 * (asoc, reply_msg, msg_up, timers, counters)
943 * The return value is the disposition of the chunk.
945 sctp_disposition_t
sctp_sf_beat_8_3(const struct sctp_endpoint
*ep
,
946 const struct sctp_association
*asoc
,
947 const sctp_subtype_t type
,
949 sctp_cmd_seq_t
*commands
)
951 struct sctp_chunk
*chunk
= arg
;
952 struct sctp_chunk
*reply
;
955 if (!sctp_vtag_verify(chunk
, asoc
))
956 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
958 /* Make sure that the HEARTBEAT chunk has a valid length. */
959 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_heartbeat_chunk_t
)))
960 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
963 /* 8.3 The receiver of the HEARTBEAT should immediately
964 * respond with a HEARTBEAT ACK that contains the Heartbeat
965 * Information field copied from the received HEARTBEAT chunk.
967 chunk
->subh
.hb_hdr
= (sctp_heartbeathdr_t
*) chunk
->skb
->data
;
968 paylen
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(sctp_chunkhdr_t
);
969 if (!pskb_pull(chunk
->skb
, paylen
))
972 reply
= sctp_make_heartbeat_ack(asoc
, chunk
,
973 chunk
->subh
.hb_hdr
, paylen
);
977 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
978 return SCTP_DISPOSITION_CONSUME
;
981 return SCTP_DISPOSITION_NOMEM
;
985 * Process the returning HEARTBEAT ACK.
987 * Section: 8.3 Path Heartbeat
988 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
989 * should clear the error counter of the destination transport
990 * address to which the HEARTBEAT was sent, and mark the destination
991 * transport address as active if it is not so marked. The endpoint may
992 * optionally report to the upper layer when an inactive destination
993 * address is marked as active due to the reception of the latest
994 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
995 * clear the association overall error count as well (as defined
998 * The receiver of the HEARTBEAT ACK should also perform an RTT
999 * measurement for that destination transport address using the time
1000 * value carried in the HEARTBEAT ACK chunk.
1002 * Verification Tag: 8.5 Verification Tag [Normal verification]
1005 * (endpoint, asoc, chunk)
1008 * (asoc, reply_msg, msg_up, timers, counters)
1010 * The return value is the disposition of the chunk.
1012 sctp_disposition_t
sctp_sf_backbeat_8_3(const struct sctp_endpoint
*ep
,
1013 const struct sctp_association
*asoc
,
1014 const sctp_subtype_t type
,
1016 sctp_cmd_seq_t
*commands
)
1018 struct sctp_chunk
*chunk
= arg
;
1019 union sctp_addr from_addr
;
1020 struct sctp_transport
*link
;
1021 sctp_sender_hb_info_t
*hbinfo
;
1022 unsigned long max_interval
;
1024 if (!sctp_vtag_verify(chunk
, asoc
))
1025 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1027 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1028 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_heartbeat_chunk_t
)))
1029 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1032 hbinfo
= (sctp_sender_hb_info_t
*) chunk
->skb
->data
;
1033 from_addr
= hbinfo
->daddr
;
1034 link
= sctp_assoc_lookup_paddr(asoc
, &from_addr
);
1036 /* This should never happen, but lets log it if so. */
1037 if (unlikely(!link
)) {
1038 if (from_addr
.sa
.sa_family
== AF_INET6
) {
1040 "%s association %p could not find address "
1044 NIP6(from_addr
.v6
.sin6_addr
));
1047 "%s association %p could not find address "
1051 NIPQUAD(from_addr
.v4
.sin_addr
.s_addr
));
1053 return SCTP_DISPOSITION_DISCARD
;
1056 max_interval
= link
->hbinterval
+ link
->rto
;
1058 /* Check if the timestamp looks valid. */
1059 if (time_after(hbinfo
->sent_at
, jiffies
) ||
1060 time_after(jiffies
, hbinfo
->sent_at
+ max_interval
)) {
1061 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp"
1062 "received for transport: %p\n",
1063 __FUNCTION__
, link
);
1064 return SCTP_DISPOSITION_DISCARD
;
1067 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1068 * the HEARTBEAT should clear the error counter of the
1069 * destination transport address to which the HEARTBEAT was
1070 * sent and mark the destination transport address as active if
1071 * it is not so marked.
1073 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_ON
, SCTP_TRANSPORT(link
));
1075 return SCTP_DISPOSITION_CONSUME
;
1078 /* Helper function to send out an abort for the restart
1081 static int sctp_sf_send_restart_abort(union sctp_addr
*ssa
,
1082 struct sctp_chunk
*init
,
1083 sctp_cmd_seq_t
*commands
)
1086 struct sctp_packet
*pkt
;
1087 union sctp_addr_param
*addrparm
;
1088 struct sctp_errhdr
*errhdr
;
1089 struct sctp_endpoint
*ep
;
1090 char buffer
[sizeof(struct sctp_errhdr
)+sizeof(union sctp_addr_param
)];
1091 struct sctp_af
*af
= sctp_get_af_specific(ssa
->v4
.sin_family
);
1093 /* Build the error on the stack. We are way to malloc crazy
1094 * throughout the code today.
1096 errhdr
= (struct sctp_errhdr
*)buffer
;
1097 addrparm
= (union sctp_addr_param
*)errhdr
->variable
;
1099 /* Copy into a parm format. */
1100 len
= af
->to_addr_param(ssa
, addrparm
);
1101 len
+= sizeof(sctp_errhdr_t
);
1103 errhdr
->cause
= SCTP_ERROR_RESTART
;
1104 errhdr
->length
= htons(len
);
1106 /* Assign to the control socket. */
1107 ep
= sctp_sk((sctp_get_ctl_sock()))->ep
;
1109 /* Association is NULL since this may be a restart attack and we
1110 * want to send back the attacker's vtag.
1112 pkt
= sctp_abort_pkt_new(ep
, NULL
, init
, errhdr
, len
);
1116 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
, SCTP_PACKET(pkt
));
1118 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
1120 /* Discard the rest of the inbound packet. */
1121 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
1124 /* Even if there is no memory, treat as a failure so
1125 * the packet will get dropped.
1130 /* A restart is occurring, check to make sure no new addresses
1131 * are being added as we may be under a takeover attack.
1133 static int sctp_sf_check_restart_addrs(const struct sctp_association
*new_asoc
,
1134 const struct sctp_association
*asoc
,
1135 struct sctp_chunk
*init
,
1136 sctp_cmd_seq_t
*commands
)
1138 struct sctp_transport
*new_addr
, *addr
;
1139 struct list_head
*pos
, *pos2
;
1142 /* Implementor's Guide - Sectin 5.2.2
1144 * Before responding the endpoint MUST check to see if the
1145 * unexpected INIT adds new addresses to the association. If new
1146 * addresses are added to the association, the endpoint MUST respond
1150 /* Search through all current addresses and make sure
1151 * we aren't adding any new ones.
1156 list_for_each(pos
, &new_asoc
->peer
.transport_addr_list
) {
1157 new_addr
= list_entry(pos
, struct sctp_transport
, transports
);
1159 list_for_each(pos2
, &asoc
->peer
.transport_addr_list
) {
1160 addr
= list_entry(pos2
, struct sctp_transport
,
1162 if (sctp_cmp_addr_exact(&new_addr
->ipaddr
,
1172 /* If a new address was added, ABORT the sender. */
1173 if (!found
&& new_addr
) {
1174 sctp_sf_send_restart_abort(&new_addr
->ipaddr
, init
, commands
);
1177 /* Return success if all addresses were found. */
1181 /* Populate the verification/tie tags based on overlapping INIT
1184 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1186 static void sctp_tietags_populate(struct sctp_association
*new_asoc
,
1187 const struct sctp_association
*asoc
)
1189 switch (asoc
->state
) {
1191 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1193 case SCTP_STATE_COOKIE_WAIT
:
1194 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1195 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1196 new_asoc
->c
.peer_ttag
= 0;
1199 case SCTP_STATE_COOKIE_ECHOED
:
1200 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1201 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1202 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1205 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1206 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1209 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1210 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1214 /* Other parameters for the endpoint SHOULD be copied from the
1215 * existing parameters of the association (e.g. number of
1216 * outbound streams) into the INIT ACK and cookie.
1218 new_asoc
->rwnd
= asoc
->rwnd
;
1219 new_asoc
->c
.sinit_num_ostreams
= asoc
->c
.sinit_num_ostreams
;
1220 new_asoc
->c
.sinit_max_instreams
= asoc
->c
.sinit_max_instreams
;
1221 new_asoc
->c
.initial_tsn
= asoc
->c
.initial_tsn
;
1225 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1228 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1230 * Returns value representing action to be taken. These action values
1231 * correspond to Action/Description values in RFC 2960, Table 2.
1233 static char sctp_tietags_compare(struct sctp_association
*new_asoc
,
1234 const struct sctp_association
*asoc
)
1236 /* In this case, the peer may have restarted. */
1237 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1238 (asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) &&
1239 (asoc
->c
.my_vtag
== new_asoc
->c
.my_ttag
) &&
1240 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_ttag
))
1243 /* Collision case B. */
1244 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1245 ((asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) ||
1246 (0 == asoc
->c
.peer_vtag
))) {
1250 /* Collision case D. */
1251 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1252 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
))
1255 /* Collision case C. */
1256 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1257 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
) &&
1258 (0 == new_asoc
->c
.my_ttag
) &&
1259 (0 == new_asoc
->c
.peer_ttag
))
1262 /* No match to any of the special cases; discard this packet. */
1266 /* Common helper routine for both duplicate and simulataneous INIT
1269 static sctp_disposition_t
sctp_sf_do_unexpected_init(
1270 const struct sctp_endpoint
*ep
,
1271 const struct sctp_association
*asoc
,
1272 const sctp_subtype_t type
,
1273 void *arg
, sctp_cmd_seq_t
*commands
)
1275 sctp_disposition_t retval
;
1276 struct sctp_chunk
*chunk
= arg
;
1277 struct sctp_chunk
*repl
;
1278 struct sctp_association
*new_asoc
;
1279 struct sctp_chunk
*err_chunk
;
1280 struct sctp_packet
*packet
;
1281 sctp_unrecognized_param_t
*unk_param
;
1285 * An endpoint MUST NOT bundle INIT, INIT ACK or
1286 * SHUTDOWN COMPLETE with any other chunks.
1289 * Furthermore, we require that the receiver of an INIT chunk MUST
1290 * enforce these rules by silently discarding an arriving packet
1291 * with an INIT chunk that is bundled with other chunks.
1293 if (!chunk
->singleton
)
1294 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1296 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1299 if (chunk
->sctp_hdr
->vtag
!= 0)
1300 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
1302 /* Make sure that the INIT chunk has a valid length.
1303 * In this case, we generate a protocol violation since we have
1304 * an association established.
1306 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_init_chunk_t
)))
1307 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1309 /* Grab the INIT header. */
1310 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
1312 /* Tag the variable length parameters. */
1313 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
1315 /* Verify the INIT chunk before processing it. */
1317 if (!sctp_verify_init(asoc
, chunk
->chunk_hdr
->type
,
1318 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
1320 /* This chunk contains fatal error. It is to be discarded.
1321 * Send an ABORT, with causes if there is any.
1324 packet
= sctp_abort_pkt_new(ep
, asoc
, arg
,
1325 (__u8
*)(err_chunk
->chunk_hdr
) +
1326 sizeof(sctp_chunkhdr_t
),
1327 ntohs(err_chunk
->chunk_hdr
->length
) -
1328 sizeof(sctp_chunkhdr_t
));
1331 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
1332 SCTP_PACKET(packet
));
1333 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
1334 retval
= SCTP_DISPOSITION_CONSUME
;
1336 retval
= SCTP_DISPOSITION_NOMEM
;
1340 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
,
1346 * Other parameters for the endpoint SHOULD be copied from the
1347 * existing parameters of the association (e.g. number of
1348 * outbound streams) into the INIT ACK and cookie.
1349 * FIXME: We are copying parameters from the endpoint not the
1352 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
1356 /* In the outbound INIT ACK the endpoint MUST copy its current
1357 * Verification Tag and Peers Verification tag into a reserved
1358 * place (local tie-tag and per tie-tag) within the state cookie.
1360 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
1362 (sctp_init_chunk_t
*)chunk
->chunk_hdr
,
1364 retval
= SCTP_DISPOSITION_NOMEM
;
1368 /* Make sure no new addresses are being added during the
1369 * restart. Do not do this check for COOKIE-WAIT state,
1370 * since there are no peer addresses to check against.
1371 * Upon return an ABORT will have been sent if needed.
1373 if (!sctp_state(asoc
, COOKIE_WAIT
)) {
1374 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
,
1376 retval
= SCTP_DISPOSITION_CONSUME
;
1381 sctp_tietags_populate(new_asoc
, asoc
);
1383 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1385 /* If there are errors need to be reported for unknown parameters,
1386 * make sure to reserve enough room in the INIT ACK for them.
1390 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
1391 sizeof(sctp_chunkhdr_t
);
1394 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
, GFP_ATOMIC
) < 0)
1397 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
1401 /* If there are errors need to be reported for unknown parameters,
1402 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1406 /* Get the "Unrecognized parameter" parameter(s) out of the
1407 * ERROR chunk generated by sctp_verify_init(). Since the
1408 * error cause code for "unknown parameter" and the
1409 * "Unrecognized parameter" type is the same, we can
1410 * construct the parameters in INIT ACK by copying the
1411 * ERROR causes over.
1413 unk_param
= (sctp_unrecognized_param_t
*)
1414 ((__u8
*)(err_chunk
->chunk_hdr
) +
1415 sizeof(sctp_chunkhdr_t
));
1416 /* Replace the cause code with the "Unrecognized parameter"
1419 sctp_addto_chunk(repl
, len
, unk_param
);
1422 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
1423 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1426 * Note: After sending out INIT ACK with the State Cookie parameter,
1427 * "Z" MUST NOT allocate any resources for this new association.
1428 * Otherwise, "Z" will be vulnerable to resource attacks.
1430 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
1431 retval
= SCTP_DISPOSITION_CONSUME
;
1435 sctp_chunk_free(err_chunk
);
1438 retval
= SCTP_DISPOSITION_NOMEM
;
1442 sctp_association_free(new_asoc
);
1447 * Handle simultanous INIT.
1448 * This means we started an INIT and then we got an INIT request from
1451 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1452 * This usually indicates an initialization collision, i.e., each
1453 * endpoint is attempting, at about the same time, to establish an
1454 * association with the other endpoint.
1456 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1457 * endpoint MUST respond with an INIT ACK using the same parameters it
1458 * sent in its original INIT chunk (including its Verification Tag,
1459 * unchanged). These original parameters are combined with those from the
1460 * newly received INIT chunk. The endpoint shall also generate a State
1461 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1462 * INIT to calculate the State Cookie.
1464 * After that, the endpoint MUST NOT change its state, the T1-init
1465 * timer shall be left running and the corresponding TCB MUST NOT be
1466 * destroyed. The normal procedures for handling State Cookies when
1467 * a TCB exists will resolve the duplicate INITs to a single association.
1469 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1470 * its Tie-Tags with the Tag information of itself and its peer (see
1471 * section 5.2.2 for a description of the Tie-Tags).
1473 * Verification Tag: Not explicit, but an INIT can not have a valid
1474 * verification tag, so we skip the check.
1477 * (endpoint, asoc, chunk)
1480 * (asoc, reply_msg, msg_up, timers, counters)
1482 * The return value is the disposition of the chunk.
1484 sctp_disposition_t
sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint
*ep
,
1485 const struct sctp_association
*asoc
,
1486 const sctp_subtype_t type
,
1488 sctp_cmd_seq_t
*commands
)
1490 /* Call helper to do the real work for both simulataneous and
1491 * duplicate INIT chunk handling.
1493 return sctp_sf_do_unexpected_init(ep
, asoc
, type
, arg
, commands
);
1497 * Handle duplicated INIT messages. These are usually delayed
1500 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1501 * COOKIE-ECHOED and COOKIE-WAIT
1503 * Unless otherwise stated, upon reception of an unexpected INIT for
1504 * this association, the endpoint shall generate an INIT ACK with a
1505 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1506 * current Verification Tag and peer's Verification Tag into a reserved
1507 * place within the state cookie. We shall refer to these locations as
1508 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1509 * containing this INIT ACK MUST carry a Verification Tag value equal to
1510 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1511 * MUST contain a new Initiation Tag (randomly generated see Section
1512 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1513 * existing parameters of the association (e.g. number of outbound
1514 * streams) into the INIT ACK and cookie.
1516 * After sending out the INIT ACK, the endpoint shall take no further
1517 * actions, i.e., the existing association, including its current state,
1518 * and the corresponding TCB MUST NOT be changed.
1520 * Note: Only when a TCB exists and the association is not in a COOKIE-
1521 * WAIT state are the Tie-Tags populated. For a normal association INIT
1522 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1523 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1524 * State Cookie are populated as specified in section 5.2.1.
1526 * Verification Tag: Not specified, but an INIT has no way of knowing
1527 * what the verification tag could be, so we ignore it.
1530 * (endpoint, asoc, chunk)
1533 * (asoc, reply_msg, msg_up, timers, counters)
1535 * The return value is the disposition of the chunk.
1537 sctp_disposition_t
sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint
*ep
,
1538 const struct sctp_association
*asoc
,
1539 const sctp_subtype_t type
,
1541 sctp_cmd_seq_t
*commands
)
1543 /* Call helper to do the real work for both simulataneous and
1544 * duplicate INIT chunk handling.
1546 return sctp_sf_do_unexpected_init(ep
, asoc
, type
, arg
, commands
);
1551 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1554 * A) In this case, the peer may have restarted.
1556 static sctp_disposition_t
sctp_sf_do_dupcook_a(const struct sctp_endpoint
*ep
,
1557 const struct sctp_association
*asoc
,
1558 struct sctp_chunk
*chunk
,
1559 sctp_cmd_seq_t
*commands
,
1560 struct sctp_association
*new_asoc
)
1562 sctp_init_chunk_t
*peer_init
;
1563 struct sctp_ulpevent
*ev
;
1564 struct sctp_chunk
*repl
;
1565 struct sctp_chunk
*err
;
1566 sctp_disposition_t disposition
;
1568 /* new_asoc is a brand-new association, so these are not yet
1569 * side effects--it is safe to run them here.
1571 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1573 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
1574 sctp_source(chunk
), peer_init
,
1578 /* Make sure no new addresses are being added during the
1579 * restart. Though this is a pretty complicated attack
1580 * since you'd have to get inside the cookie.
1582 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
, commands
)) {
1583 return SCTP_DISPOSITION_CONSUME
;
1586 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1587 * the peer has restarted (Action A), it MUST NOT setup a new
1588 * association but instead resend the SHUTDOWN ACK and send an ERROR
1589 * chunk with a "Cookie Received while Shutting Down" error cause to
1592 if (sctp_state(asoc
, SHUTDOWN_ACK_SENT
)) {
1593 disposition
= sctp_sf_do_9_2_reshutack(ep
, asoc
,
1594 SCTP_ST_CHUNK(chunk
->chunk_hdr
->type
),
1596 if (SCTP_DISPOSITION_NOMEM
== disposition
)
1599 err
= sctp_make_op_error(asoc
, chunk
,
1600 SCTP_ERROR_COOKIE_IN_SHUTDOWN
,
1603 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1606 return SCTP_DISPOSITION_CONSUME
;
1609 /* For now, fail any unsent/unacked data. Consider the optional
1610 * choice of resending of this data.
1612 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_OUTQUEUE
, SCTP_NULL());
1614 /* Update the content of current association. */
1615 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1617 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1621 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1623 /* Report association restart to upper layer. */
1624 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_RESTART
, 0,
1625 new_asoc
->c
.sinit_num_ostreams
,
1626 new_asoc
->c
.sinit_max_instreams
,
1631 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
1632 return SCTP_DISPOSITION_CONSUME
;
1635 sctp_chunk_free(repl
);
1637 return SCTP_DISPOSITION_NOMEM
;
1640 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1643 * B) In this case, both sides may be attempting to start an association
1644 * at about the same time but the peer endpoint started its INIT
1645 * after responding to the local endpoint's INIT
1647 /* This case represents an initialization collision. */
1648 static sctp_disposition_t
sctp_sf_do_dupcook_b(const struct sctp_endpoint
*ep
,
1649 const struct sctp_association
*asoc
,
1650 struct sctp_chunk
*chunk
,
1651 sctp_cmd_seq_t
*commands
,
1652 struct sctp_association
*new_asoc
)
1654 sctp_init_chunk_t
*peer_init
;
1655 struct sctp_ulpevent
*ev
;
1656 struct sctp_chunk
*repl
;
1658 /* new_asoc is a brand-new association, so these are not yet
1659 * side effects--it is safe to run them here.
1661 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1662 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
1663 sctp_source(chunk
), peer_init
,
1667 /* Update the content of current association. */
1668 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1669 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1670 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1671 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
1672 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
1674 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1678 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1679 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSMIT
, SCTP_NULL());
1681 /* RFC 2960 5.1 Normal Establishment of an Association
1683 * D) IMPLEMENTATION NOTE: An implementation may choose to
1684 * send the Communication Up notification to the SCTP user
1685 * upon reception of a valid COOKIE ECHO chunk.
1687 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_COMM_UP
, 0,
1688 new_asoc
->c
.sinit_num_ostreams
,
1689 new_asoc
->c
.sinit_max_instreams
,
1694 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
1696 /* Sockets API Draft Section 5.3.1.6
1697 * When a peer sends a Adaption Layer Indication parameter , SCTP
1698 * delivers this notification to inform the application that of the
1699 * peers requested adaption layer.
1701 if (asoc
->peer
.adaption_ind
) {
1702 ev
= sctp_ulpevent_make_adaption_indication(asoc
, GFP_ATOMIC
);
1706 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1710 return SCTP_DISPOSITION_CONSUME
;
1713 sctp_chunk_free(repl
);
1715 return SCTP_DISPOSITION_NOMEM
;
1718 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1721 * C) In this case, the local endpoint's cookie has arrived late.
1722 * Before it arrived, the local endpoint sent an INIT and received an
1723 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1724 * but a new tag of its own.
1726 /* This case represents an initialization collision. */
1727 static sctp_disposition_t
sctp_sf_do_dupcook_c(const struct sctp_endpoint
*ep
,
1728 const struct sctp_association
*asoc
,
1729 struct sctp_chunk
*chunk
,
1730 sctp_cmd_seq_t
*commands
,
1731 struct sctp_association
*new_asoc
)
1733 /* The cookie should be silently discarded.
1734 * The endpoint SHOULD NOT change states and should leave
1735 * any timers running.
1737 return SCTP_DISPOSITION_DISCARD
;
1740 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1744 * D) When both local and remote tags match the endpoint should always
1745 * enter the ESTABLISHED state, if it has not already done so.
1747 /* This case represents an initialization collision. */
1748 static sctp_disposition_t
sctp_sf_do_dupcook_d(const struct sctp_endpoint
*ep
,
1749 const struct sctp_association
*asoc
,
1750 struct sctp_chunk
*chunk
,
1751 sctp_cmd_seq_t
*commands
,
1752 struct sctp_association
*new_asoc
)
1754 struct sctp_ulpevent
*ev
= NULL
;
1755 struct sctp_chunk
*repl
;
1757 /* Clarification from Implementor's Guide:
1758 * D) When both local and remote tags match the endpoint should
1759 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1760 * It should stop any cookie timer that may be running and send
1764 /* Don't accidentally move back into established state. */
1765 if (asoc
->state
< SCTP_STATE_ESTABLISHED
) {
1766 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1767 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
1768 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1769 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1770 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
1771 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
,
1774 /* RFC 2960 5.1 Normal Establishment of an Association
1776 * D) IMPLEMENTATION NOTE: An implementation may choose
1777 * to send the Communication Up notification to the
1778 * SCTP user upon reception of a valid COOKIE
1781 ev
= sctp_ulpevent_make_assoc_change(new_asoc
, 0,
1783 new_asoc
->c
.sinit_num_ostreams
,
1784 new_asoc
->c
.sinit_max_instreams
,
1788 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1791 /* Sockets API Draft Section 5.3.1.6
1792 * When a peer sends a Adaption Layer Indication parameter,
1793 * SCTP delivers this notification to inform the application
1794 * that of the peers requested adaption layer.
1796 if (new_asoc
->peer
.adaption_ind
) {
1797 ev
= sctp_ulpevent_make_adaption_indication(new_asoc
,
1802 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1806 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSMIT
, SCTP_NULL());
1808 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1812 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1813 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSMIT
, SCTP_NULL());
1815 return SCTP_DISPOSITION_CONSUME
;
1819 sctp_ulpevent_free(ev
);
1820 return SCTP_DISPOSITION_NOMEM
;
1824 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1825 * chunk was retransmitted and then delayed in the network.
1827 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1829 * Verification Tag: None. Do cookie validation.
1832 * (endpoint, asoc, chunk)
1835 * (asoc, reply_msg, msg_up, timers, counters)
1837 * The return value is the disposition of the chunk.
1839 sctp_disposition_t
sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint
*ep
,
1840 const struct sctp_association
*asoc
,
1841 const sctp_subtype_t type
,
1843 sctp_cmd_seq_t
*commands
)
1845 sctp_disposition_t retval
;
1846 struct sctp_chunk
*chunk
= arg
;
1847 struct sctp_association
*new_asoc
;
1850 struct sctp_chunk
*err_chk_p
;
1852 /* Make sure that the chunk has a valid length from the protocol
1853 * perspective. In this case check to make sure we have at least
1854 * enough for the chunk header. Cookie length verification is
1857 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
1858 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1861 /* "Decode" the chunk. We have no optional parameters so we
1862 * are in good shape.
1864 chunk
->subh
.cookie_hdr
= (struct sctp_signed_cookie
*)chunk
->skb
->data
;
1865 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
1866 sizeof(sctp_chunkhdr_t
)))
1869 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
1870 * of a duplicate COOKIE ECHO match the Verification Tags of the
1871 * current association, consider the State Cookie valid even if
1872 * the lifespan is exceeded.
1874 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
1878 * If the re-build failed, what is the proper error path
1881 * [We should abort the association. --piggy]
1884 /* FIXME: Several errors are possible. A bad cookie should
1885 * be silently discarded, but think about logging it too.
1888 case -SCTP_IERROR_NOMEM
:
1891 case -SCTP_IERROR_STALE_COOKIE
:
1892 sctp_send_stale_cookie_err(ep
, asoc
, chunk
, commands
,
1894 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1895 case -SCTP_IERROR_BAD_SIG
:
1897 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1901 /* Compare the tie_tag in cookie with the verification tag of
1902 * current association.
1904 action
= sctp_tietags_compare(new_asoc
, asoc
);
1907 case 'A': /* Association restart. */
1908 retval
= sctp_sf_do_dupcook_a(ep
, asoc
, chunk
, commands
,
1912 case 'B': /* Collision case B. */
1913 retval
= sctp_sf_do_dupcook_b(ep
, asoc
, chunk
, commands
,
1917 case 'C': /* Collision case C. */
1918 retval
= sctp_sf_do_dupcook_c(ep
, asoc
, chunk
, commands
,
1922 case 'D': /* Collision case D. */
1923 retval
= sctp_sf_do_dupcook_d(ep
, asoc
, chunk
, commands
,
1927 default: /* Discard packet for all others. */
1928 retval
= sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1932 /* Delete the tempory new association. */
1933 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
1934 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
1939 return SCTP_DISPOSITION_NOMEM
;
1943 * Process an ABORT. (SHUTDOWN-PENDING state)
1945 * See sctp_sf_do_9_1_abort().
1947 sctp_disposition_t
sctp_sf_shutdown_pending_abort(
1948 const struct sctp_endpoint
*ep
,
1949 const struct sctp_association
*asoc
,
1950 const sctp_subtype_t type
,
1952 sctp_cmd_seq_t
*commands
)
1954 struct sctp_chunk
*chunk
= arg
;
1956 if (!sctp_vtag_verify_either(chunk
, asoc
))
1957 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1959 /* Make sure that the ABORT chunk has a valid length.
1960 * Since this is an ABORT chunk, we have to discard it
1961 * because of the following text:
1962 * RFC 2960, Section 3.3.7
1963 * If an endpoint receives an ABORT with a format error or for an
1964 * association that doesn't exist, it MUST silently discard it.
1965 * Becasue the length is "invalid", we can't really discard just
1966 * as we do not know its true length. So, to be safe, discard the
1969 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
1970 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1972 /* Stop the T5-shutdown guard timer. */
1973 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1974 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
1976 return sctp_sf_do_9_1_abort(ep
, asoc
, type
, arg
, commands
);
1980 * Process an ABORT. (SHUTDOWN-SENT state)
1982 * See sctp_sf_do_9_1_abort().
1984 sctp_disposition_t
sctp_sf_shutdown_sent_abort(const struct sctp_endpoint
*ep
,
1985 const struct sctp_association
*asoc
,
1986 const sctp_subtype_t type
,
1988 sctp_cmd_seq_t
*commands
)
1990 struct sctp_chunk
*chunk
= arg
;
1992 if (!sctp_vtag_verify_either(chunk
, asoc
))
1993 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1995 /* Make sure that the ABORT chunk has a valid length.
1996 * Since this is an ABORT chunk, we have to discard it
1997 * because of the following text:
1998 * RFC 2960, Section 3.3.7
1999 * If an endpoint receives an ABORT with a format error or for an
2000 * association that doesn't exist, it MUST silently discard it.
2001 * Becasue the length is "invalid", we can't really discard just
2002 * as we do not know its true length. So, to be safe, discard the
2005 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2006 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2008 /* Stop the T2-shutdown timer. */
2009 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2010 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2012 /* Stop the T5-shutdown guard timer. */
2013 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2014 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
2016 return sctp_sf_do_9_1_abort(ep
, asoc
, type
, arg
, commands
);
2020 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2022 * See sctp_sf_do_9_1_abort().
2024 sctp_disposition_t
sctp_sf_shutdown_ack_sent_abort(
2025 const struct sctp_endpoint
*ep
,
2026 const struct sctp_association
*asoc
,
2027 const sctp_subtype_t type
,
2029 sctp_cmd_seq_t
*commands
)
2031 /* The same T2 timer, so we should be able to use
2032 * common function with the SHUTDOWN-SENT state.
2034 return sctp_sf_shutdown_sent_abort(ep
, asoc
, type
, arg
, commands
);
2038 * Handle an Error received in COOKIE_ECHOED state.
2040 * Only handle the error type of stale COOKIE Error, the other errors will
2044 * (endpoint, asoc, chunk)
2047 * (asoc, reply_msg, msg_up, timers, counters)
2049 * The return value is the disposition of the chunk.
2051 sctp_disposition_t
sctp_sf_cookie_echoed_err(const struct sctp_endpoint
*ep
,
2052 const struct sctp_association
*asoc
,
2053 const sctp_subtype_t type
,
2055 sctp_cmd_seq_t
*commands
)
2057 struct sctp_chunk
*chunk
= arg
;
2060 if (!sctp_vtag_verify(chunk
, asoc
))
2061 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2063 /* Make sure that the ERROR chunk has a valid length.
2064 * The parameter walking depends on this as well.
2066 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
2067 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2070 /* Process the error here */
2071 /* FUTURE FIXME: When PR-SCTP related and other optional
2072 * parms are emitted, this will have to change to handle multiple
2075 sctp_walk_errors(err
, chunk
->chunk_hdr
) {
2076 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
)
2077 return sctp_sf_do_5_2_6_stale(ep
, asoc
, type
,
2081 /* It is possible to have malformed error causes, and that
2082 * will cause us to end the walk early. However, since
2083 * we are discarding the packet, there should be no adverse
2086 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2090 * Handle a Stale COOKIE Error
2092 * Section: 5.2.6 Handle Stale COOKIE Error
2093 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2094 * one of the following three alternatives.
2096 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2097 * Preservative parameter requesting an extension to the lifetime of
2098 * the State Cookie. When calculating the time extension, an
2099 * implementation SHOULD use the RTT information measured based on the
2100 * previous COOKIE ECHO / ERROR exchange, and should add no more
2101 * than 1 second beyond the measured RTT, due to long State Cookie
2102 * lifetimes making the endpoint more subject to a replay attack.
2104 * Verification Tag: Not explicit, but safe to ignore.
2107 * (endpoint, asoc, chunk)
2110 * (asoc, reply_msg, msg_up, timers, counters)
2112 * The return value is the disposition of the chunk.
2114 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(const struct sctp_endpoint
*ep
,
2115 const struct sctp_association
*asoc
,
2116 const sctp_subtype_t type
,
2118 sctp_cmd_seq_t
*commands
)
2120 struct sctp_chunk
*chunk
= arg
;
2122 sctp_cookie_preserve_param_t bht
;
2124 struct sctp_chunk
*reply
;
2125 struct sctp_bind_addr
*bp
;
2126 int attempts
= asoc
->init_err_counter
+ 1;
2128 if (attempts
> asoc
->max_init_attempts
) {
2129 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2130 SCTP_U32(SCTP_ERROR_STALE_COOKIE
));
2131 return SCTP_DISPOSITION_DELETE_TCB
;
2134 err
= (sctp_errhdr_t
*)(chunk
->skb
->data
);
2136 /* When calculating the time extension, an implementation
2137 * SHOULD use the RTT information measured based on the
2138 * previous COOKIE ECHO / ERROR exchange, and should add no
2139 * more than 1 second beyond the measured RTT, due to long
2140 * State Cookie lifetimes making the endpoint more subject to
2142 * Measure of Staleness's unit is usec. (1/1000000 sec)
2143 * Suggested Cookie Life-span Increment's unit is msec.
2145 * In general, if you use the suggested cookie life, the value
2146 * found in the field of measure of staleness should be doubled
2147 * to give ample time to retransmit the new cookie and thus
2148 * yield a higher probability of success on the reattempt.
2150 stale
= ntohl(*(suseconds_t
*)((u8
*)err
+ sizeof(sctp_errhdr_t
)));
2151 stale
= (stale
* 2) / 1000;
2153 bht
.param_hdr
.type
= SCTP_PARAM_COOKIE_PRESERVATIVE
;
2154 bht
.param_hdr
.length
= htons(sizeof(bht
));
2155 bht
.lifespan_increment
= htonl(stale
);
2157 /* Build that new INIT chunk. */
2158 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
2159 reply
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, sizeof(bht
));
2163 sctp_addto_chunk(reply
, sizeof(bht
), &bht
);
2165 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2166 sctp_add_cmd_sf(commands
, SCTP_CMD_CLEAR_INIT_TAG
, SCTP_NULL());
2168 /* Stop pending T3-rtx and heartbeat timers */
2169 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
2170 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
2172 /* Delete non-primary peer ip addresses since we are transitioning
2173 * back to the COOKIE-WAIT state
2175 sctp_add_cmd_sf(commands
, SCTP_CMD_DEL_NON_PRIMARY
, SCTP_NULL());
2177 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2180 sctp_add_cmd_sf(commands
, SCTP_CMD_RETRAN
,
2181 SCTP_TRANSPORT(asoc
->peer
.primary_path
));
2183 /* Cast away the const modifier, as we want to just
2184 * rerun it through as a sideffect.
2186 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_INC
, SCTP_NULL());
2188 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2189 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
2190 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2191 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
2192 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
2193 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2195 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2197 return SCTP_DISPOSITION_CONSUME
;
2200 return SCTP_DISPOSITION_NOMEM
;
2207 * After checking the Verification Tag, the receiving endpoint shall
2208 * remove the association from its record, and shall report the
2209 * termination to its upper layer.
2211 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2212 * B) Rules for packet carrying ABORT:
2214 * - The endpoint shall always fill in the Verification Tag field of the
2215 * outbound packet with the destination endpoint's tag value if it
2218 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2219 * MUST follow the procedure described in Section 8.4.
2221 * - The receiver MUST accept the packet if the Verification Tag
2222 * matches either its own tag, OR the tag of its peer. Otherwise, the
2223 * receiver MUST silently discard the packet and take no further
2227 * (endpoint, asoc, chunk)
2230 * (asoc, reply_msg, msg_up, timers, counters)
2232 * The return value is the disposition of the chunk.
2234 sctp_disposition_t
sctp_sf_do_9_1_abort(const struct sctp_endpoint
*ep
,
2235 const struct sctp_association
*asoc
,
2236 const sctp_subtype_t type
,
2238 sctp_cmd_seq_t
*commands
)
2240 struct sctp_chunk
*chunk
= arg
;
2242 __u16 error
= SCTP_ERROR_NO_ERROR
;
2244 if (!sctp_vtag_verify_either(chunk
, asoc
))
2245 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2247 /* Make sure that the ABORT chunk has a valid length.
2248 * Since this is an ABORT chunk, we have to discard it
2249 * because of the following text:
2250 * RFC 2960, Section 3.3.7
2251 * If an endpoint receives an ABORT with a format error or for an
2252 * association that doesn't exist, it MUST silently discard it.
2253 * Becasue the length is "invalid", we can't really discard just
2254 * as we do not know its true length. So, to be safe, discard the
2257 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2258 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2260 /* See if we have an error cause code in the chunk. */
2261 len
= ntohs(chunk
->chunk_hdr
->length
);
2262 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2263 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2265 /* ASSOC_FAILED will DELETE_TCB. */
2266 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
, SCTP_U32(error
));
2267 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
2268 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
2270 return SCTP_DISPOSITION_ABORT
;
2274 * Process an ABORT. (COOKIE-WAIT state)
2276 * See sctp_sf_do_9_1_abort() above.
2278 sctp_disposition_t
sctp_sf_cookie_wait_abort(const struct sctp_endpoint
*ep
,
2279 const struct sctp_association
*asoc
,
2280 const sctp_subtype_t type
,
2282 sctp_cmd_seq_t
*commands
)
2284 struct sctp_chunk
*chunk
= arg
;
2286 __u16 error
= SCTP_ERROR_NO_ERROR
;
2288 if (!sctp_vtag_verify_either(chunk
, asoc
))
2289 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2291 /* Make sure that the ABORT chunk has a valid length.
2292 * Since this is an ABORT chunk, we have to discard it
2293 * because of the following text:
2294 * RFC 2960, Section 3.3.7
2295 * If an endpoint receives an ABORT with a format error or for an
2296 * association that doesn't exist, it MUST silently discard it.
2297 * Becasue the length is "invalid", we can't really discard just
2298 * as we do not know its true length. So, to be safe, discard the
2301 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2302 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2304 /* See if we have an error cause code in the chunk. */
2305 len
= ntohs(chunk
->chunk_hdr
->length
);
2306 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2307 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2309 return sctp_stop_t1_and_abort(commands
, error
, asoc
, chunk
->transport
);
2313 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2315 sctp_disposition_t
sctp_sf_cookie_wait_icmp_abort(const struct sctp_endpoint
*ep
,
2316 const struct sctp_association
*asoc
,
2317 const sctp_subtype_t type
,
2319 sctp_cmd_seq_t
*commands
)
2321 return sctp_stop_t1_and_abort(commands
, SCTP_ERROR_NO_ERROR
, asoc
,
2322 (struct sctp_transport
*)arg
);
2326 * Process an ABORT. (COOKIE-ECHOED state)
2328 sctp_disposition_t
sctp_sf_cookie_echoed_abort(const struct sctp_endpoint
*ep
,
2329 const struct sctp_association
*asoc
,
2330 const sctp_subtype_t type
,
2332 sctp_cmd_seq_t
*commands
)
2334 /* There is a single T1 timer, so we should be able to use
2335 * common function with the COOKIE-WAIT state.
2337 return sctp_sf_cookie_wait_abort(ep
, asoc
, type
, arg
, commands
);
2341 * Stop T1 timer and abort association with "INIT failed".
2343 * This is common code called by several sctp_sf_*_abort() functions above.
2345 static sctp_disposition_t
sctp_stop_t1_and_abort(sctp_cmd_seq_t
*commands
,
2347 const struct sctp_association
*asoc
,
2348 struct sctp_transport
*transport
)
2350 SCTP_DEBUG_PRINTK("ABORT received (INIT).\n");
2351 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2352 SCTP_STATE(SCTP_STATE_CLOSED
));
2353 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
2354 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2355 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2356 /* CMD_INIT_FAILED will DELETE_TCB. */
2357 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2359 return SCTP_DISPOSITION_ABORT
;
2363 * sctp_sf_do_9_2_shut
2366 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2367 * - enter the SHUTDOWN-RECEIVED state,
2369 * - stop accepting new data from its SCTP user
2371 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2372 * that all its outstanding DATA chunks have been received by the
2375 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2376 * send a SHUTDOWN in response to a ULP request. And should discard
2377 * subsequent SHUTDOWN chunks.
2379 * If there are still outstanding DATA chunks left, the SHUTDOWN
2380 * receiver shall continue to follow normal data transmission
2381 * procedures defined in Section 6 until all outstanding DATA chunks
2382 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2383 * new data from its SCTP user.
2385 * Verification Tag: 8.5 Verification Tag [Normal verification]
2388 * (endpoint, asoc, chunk)
2391 * (asoc, reply_msg, msg_up, timers, counters)
2393 * The return value is the disposition of the chunk.
2395 sctp_disposition_t
sctp_sf_do_9_2_shutdown(const struct sctp_endpoint
*ep
,
2396 const struct sctp_association
*asoc
,
2397 const sctp_subtype_t type
,
2399 sctp_cmd_seq_t
*commands
)
2401 struct sctp_chunk
*chunk
= arg
;
2402 sctp_shutdownhdr_t
*sdh
;
2403 sctp_disposition_t disposition
;
2404 struct sctp_ulpevent
*ev
;
2406 if (!sctp_vtag_verify(chunk
, asoc
))
2407 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2409 /* Make sure that the SHUTDOWN chunk has a valid length. */
2410 if (!sctp_chunk_length_valid(chunk
,
2411 sizeof(struct sctp_shutdown_chunk_t
)))
2412 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2415 /* Convert the elaborate header. */
2416 sdh
= (sctp_shutdownhdr_t
*)chunk
->skb
->data
;
2417 skb_pull(chunk
->skb
, sizeof(sctp_shutdownhdr_t
));
2418 chunk
->subh
.shutdown_hdr
= sdh
;
2420 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2421 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2422 * inform the application that it should cease sending data.
2424 ev
= sctp_ulpevent_make_shutdown_event(asoc
, 0, GFP_ATOMIC
);
2426 disposition
= SCTP_DISPOSITION_NOMEM
;
2429 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
2431 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2432 * - enter the SHUTDOWN-RECEIVED state,
2433 * - stop accepting new data from its SCTP user
2435 * [This is implicit in the new state.]
2437 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2438 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED
));
2439 disposition
= SCTP_DISPOSITION_CONSUME
;
2441 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
2442 disposition
= sctp_sf_do_9_2_shutdown_ack(ep
, asoc
, type
,
2446 if (SCTP_DISPOSITION_NOMEM
== disposition
)
2449 /* - verify, by checking the Cumulative TSN Ack field of the
2450 * chunk, that all its outstanding DATA chunks have been
2451 * received by the SHUTDOWN sender.
2453 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2454 SCTP_U32(chunk
->subh
.shutdown_hdr
->cum_tsn_ack
));
2461 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2462 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2463 * transport addresses (either in the IP addresses or in the INIT chunk)
2464 * that belong to this association, it should discard the INIT chunk and
2465 * retransmit the SHUTDOWN ACK chunk.
2467 sctp_disposition_t
sctp_sf_do_9_2_reshutack(const struct sctp_endpoint
*ep
,
2468 const struct sctp_association
*asoc
,
2469 const sctp_subtype_t type
,
2471 sctp_cmd_seq_t
*commands
)
2473 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
2474 struct sctp_chunk
*reply
;
2476 /* Since we are not going to really process this INIT, there
2477 * is no point in verifying chunk boundries. Just generate
2480 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
2484 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2485 * the T2-SHUTDOWN timer.
2487 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
2489 /* and restart the T2-shutdown timer. */
2490 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2491 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2493 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2495 return SCTP_DISPOSITION_CONSUME
;
2497 return SCTP_DISPOSITION_NOMEM
;
2501 * sctp_sf_do_ecn_cwr
2503 * Section: Appendix A: Explicit Congestion Notification
2507 * RFC 2481 details a specific bit for a sender to send in the header of
2508 * its next outbound TCP segment to indicate to its peer that it has
2509 * reduced its congestion window. This is termed the CWR bit. For
2510 * SCTP the same indication is made by including the CWR chunk.
2511 * This chunk contains one data element, i.e. the TSN number that
2512 * was sent in the ECNE chunk. This element represents the lowest
2513 * TSN number in the datagram that was originally marked with the
2516 * Verification Tag: 8.5 Verification Tag [Normal verification]
2518 * (endpoint, asoc, chunk)
2521 * (asoc, reply_msg, msg_up, timers, counters)
2523 * The return value is the disposition of the chunk.
2525 sctp_disposition_t
sctp_sf_do_ecn_cwr(const struct sctp_endpoint
*ep
,
2526 const struct sctp_association
*asoc
,
2527 const sctp_subtype_t type
,
2529 sctp_cmd_seq_t
*commands
)
2532 struct sctp_chunk
*chunk
= arg
;
2534 if (!sctp_vtag_verify(chunk
, asoc
))
2535 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2537 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2538 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2541 cwr
= (sctp_cwrhdr_t
*) chunk
->skb
->data
;
2542 skb_pull(chunk
->skb
, sizeof(sctp_cwrhdr_t
));
2544 cwr
->lowest_tsn
= ntohl(cwr
->lowest_tsn
);
2546 /* Does this CWR ack the last sent congestion notification? */
2547 if (TSN_lte(asoc
->last_ecne_tsn
, cwr
->lowest_tsn
)) {
2548 /* Stop sending ECNE. */
2549 sctp_add_cmd_sf(commands
,
2551 SCTP_U32(cwr
->lowest_tsn
));
2553 return SCTP_DISPOSITION_CONSUME
;
2559 * Section: Appendix A: Explicit Congestion Notification
2563 * RFC 2481 details a specific bit for a receiver to send back in its
2564 * TCP acknowledgements to notify the sender of the Congestion
2565 * Experienced (CE) bit having arrived from the network. For SCTP this
2566 * same indication is made by including the ECNE chunk. This chunk
2567 * contains one data element, i.e. the lowest TSN associated with the IP
2568 * datagram marked with the CE bit.....
2570 * Verification Tag: 8.5 Verification Tag [Normal verification]
2572 * (endpoint, asoc, chunk)
2575 * (asoc, reply_msg, msg_up, timers, counters)
2577 * The return value is the disposition of the chunk.
2579 sctp_disposition_t
sctp_sf_do_ecne(const struct sctp_endpoint
*ep
,
2580 const struct sctp_association
*asoc
,
2581 const sctp_subtype_t type
,
2583 sctp_cmd_seq_t
*commands
)
2585 sctp_ecnehdr_t
*ecne
;
2586 struct sctp_chunk
*chunk
= arg
;
2588 if (!sctp_vtag_verify(chunk
, asoc
))
2589 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2591 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2592 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2595 ecne
= (sctp_ecnehdr_t
*) chunk
->skb
->data
;
2596 skb_pull(chunk
->skb
, sizeof(sctp_ecnehdr_t
));
2598 /* If this is a newer ECNE than the last CWR packet we sent out */
2599 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_ECNE
,
2600 SCTP_U32(ntohl(ecne
->lowest_tsn
)));
2602 return SCTP_DISPOSITION_CONSUME
;
2606 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2608 * The SCTP endpoint MUST always acknowledge the reception of each valid
2611 * The guidelines on delayed acknowledgement algorithm specified in
2612 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2613 * acknowledgement SHOULD be generated for at least every second packet
2614 * (not every second DATA chunk) received, and SHOULD be generated within
2615 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2616 * situations it may be beneficial for an SCTP transmitter to be more
2617 * conservative than the algorithms detailed in this document allow.
2618 * However, an SCTP transmitter MUST NOT be more aggressive than the
2619 * following algorithms allow.
2621 * A SCTP receiver MUST NOT generate more than one SACK for every
2622 * incoming packet, other than to update the offered window as the
2623 * receiving application consumes new data.
2625 * Verification Tag: 8.5 Verification Tag [Normal verification]
2628 * (endpoint, asoc, chunk)
2631 * (asoc, reply_msg, msg_up, timers, counters)
2633 * The return value is the disposition of the chunk.
2635 sctp_disposition_t
sctp_sf_eat_data_6_2(const struct sctp_endpoint
*ep
,
2636 const struct sctp_association
*asoc
,
2637 const sctp_subtype_t type
,
2639 sctp_cmd_seq_t
*commands
)
2641 struct sctp_chunk
*chunk
= arg
;
2644 if (!sctp_vtag_verify(chunk
, asoc
)) {
2645 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
2647 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2650 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
2651 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2654 error
= sctp_eat_data(asoc
, chunk
, commands
);
2656 case SCTP_IERROR_NO_ERROR
:
2658 case SCTP_IERROR_HIGH_TSN
:
2659 case SCTP_IERROR_BAD_STREAM
:
2660 goto discard_noforce
;
2661 case SCTP_IERROR_DUP_TSN
:
2662 case SCTP_IERROR_IGNORE_TSN
:
2664 case SCTP_IERROR_NO_DATA
:
2670 if (asoc
->autoclose
) {
2671 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2672 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
2675 /* If this is the last chunk in a packet, we need to count it
2676 * toward sack generation. Note that we need to SACK every
2677 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2678 * THEM. We elect to NOT generate SACK's if the chunk fails
2679 * the verification tag test.
2681 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2683 * The SCTP endpoint MUST always acknowledge the reception of
2684 * each valid DATA chunk.
2686 * The guidelines on delayed acknowledgement algorithm
2687 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2688 * Specifically, an acknowledgement SHOULD be generated for at
2689 * least every second packet (not every second DATA chunk)
2690 * received, and SHOULD be generated within 200 ms of the
2691 * arrival of any unacknowledged DATA chunk. In some
2692 * situations it may be beneficial for an SCTP transmitter to
2693 * be more conservative than the algorithms detailed in this
2694 * document allow. However, an SCTP transmitter MUST NOT be
2695 * more aggressive than the following algorithms allow.
2697 if (chunk
->end_of_packet
)
2698 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
2700 return SCTP_DISPOSITION_CONSUME
;
2703 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2705 * When a packet arrives with duplicate DATA chunk(s) and with
2706 * no new DATA chunk(s), the endpoint MUST immediately send a
2707 * SACK with no delay. If a packet arrives with duplicate
2708 * DATA chunk(s) bundled with new DATA chunks, the endpoint
2709 * MAY immediately send a SACK. Normally receipt of duplicate
2710 * DATA chunks will occur when the original SACK chunk was lost
2711 * and the peer's RTO has expired. The duplicate TSN number(s)
2712 * SHOULD be reported in the SACK as duplicate.
2714 /* In our case, we split the MAY SACK advice up whether or not
2715 * the last chunk is a duplicate.'
2717 if (chunk
->end_of_packet
)
2718 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
2719 return SCTP_DISPOSITION_DISCARD
;
2722 if (chunk
->end_of_packet
)
2723 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
2725 return SCTP_DISPOSITION_DISCARD
;
2727 return SCTP_DISPOSITION_CONSUME
;
2732 * sctp_sf_eat_data_fast_4_4
2735 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
2736 * DATA chunks without delay.
2738 * Verification Tag: 8.5 Verification Tag [Normal verification]
2740 * (endpoint, asoc, chunk)
2743 * (asoc, reply_msg, msg_up, timers, counters)
2745 * The return value is the disposition of the chunk.
2747 sctp_disposition_t
sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint
*ep
,
2748 const struct sctp_association
*asoc
,
2749 const sctp_subtype_t type
,
2751 sctp_cmd_seq_t
*commands
)
2753 struct sctp_chunk
*chunk
= arg
;
2756 if (!sctp_vtag_verify(chunk
, asoc
)) {
2757 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
2759 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2762 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
2763 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2766 error
= sctp_eat_data(asoc
, chunk
, commands
);
2768 case SCTP_IERROR_NO_ERROR
:
2769 case SCTP_IERROR_HIGH_TSN
:
2770 case SCTP_IERROR_DUP_TSN
:
2771 case SCTP_IERROR_IGNORE_TSN
:
2772 case SCTP_IERROR_BAD_STREAM
:
2774 case SCTP_IERROR_NO_DATA
:
2780 /* Go a head and force a SACK, since we are shutting down. */
2782 /* Implementor's Guide.
2784 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
2785 * respond to each received packet containing one or more DATA chunk(s)
2786 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
2788 if (chunk
->end_of_packet
) {
2789 /* We must delay the chunk creation since the cumulative
2790 * TSN has not been updated yet.
2792 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
2793 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
2794 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2795 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2799 return SCTP_DISPOSITION_CONSUME
;
2803 * Section: 6.2 Processing a Received SACK
2804 * D) Any time a SACK arrives, the endpoint performs the following:
2806 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
2807 * then drop the SACK. Since Cumulative TSN Ack is monotonically
2808 * increasing, a SACK whose Cumulative TSN Ack is less than the
2809 * Cumulative TSN Ack Point indicates an out-of-order SACK.
2811 * ii) Set rwnd equal to the newly received a_rwnd minus the number
2812 * of bytes still outstanding after processing the Cumulative TSN Ack
2813 * and the Gap Ack Blocks.
2815 * iii) If the SACK is missing a TSN that was previously
2816 * acknowledged via a Gap Ack Block (e.g., the data receiver
2817 * reneged on the data), then mark the corresponding DATA chunk
2818 * as available for retransmit: Mark it as missing for fast
2819 * retransmit as described in Section 7.2.4 and if no retransmit
2820 * timer is running for the destination address to which the DATA
2821 * chunk was originally transmitted, then T3-rtx is started for
2822 * that destination address.
2824 * Verification Tag: 8.5 Verification Tag [Normal verification]
2827 * (endpoint, asoc, chunk)
2830 * (asoc, reply_msg, msg_up, timers, counters)
2832 * The return value is the disposition of the chunk.
2834 sctp_disposition_t
sctp_sf_eat_sack_6_2(const struct sctp_endpoint
*ep
,
2835 const struct sctp_association
*asoc
,
2836 const sctp_subtype_t type
,
2838 sctp_cmd_seq_t
*commands
)
2840 struct sctp_chunk
*chunk
= arg
;
2841 sctp_sackhdr_t
*sackh
;
2844 if (!sctp_vtag_verify(chunk
, asoc
))
2845 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2847 /* Make sure that the SACK chunk has a valid length. */
2848 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_sack_chunk_t
)))
2849 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2852 /* Pull the SACK chunk from the data buffer */
2853 sackh
= sctp_sm_pull_sack(chunk
);
2854 /* Was this a bogus SACK? */
2856 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2857 chunk
->subh
.sack_hdr
= sackh
;
2858 ctsn
= ntohl(sackh
->cum_tsn_ack
);
2860 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
2861 * Ack Point, then drop the SACK. Since Cumulative TSN
2862 * Ack is monotonically increasing, a SACK whose
2863 * Cumulative TSN Ack is less than the Cumulative TSN Ack
2864 * Point indicates an out-of-order SACK.
2866 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2867 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn
);
2868 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc
->ctsn_ack_point
);
2869 return SCTP_DISPOSITION_DISCARD
;
2872 /* Return this SACK for further processing. */
2873 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_SACK
, SCTP_SACKH(sackh
));
2875 /* Note: We do the rest of the work on the PROCESS_SACK
2878 return SCTP_DISPOSITION_CONSUME
;
2882 * Generate an ABORT in response to a packet.
2884 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
2886 * 8) The receiver should respond to the sender of the OOTB packet with
2887 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
2888 * MUST fill in the Verification Tag field of the outbound packet
2889 * with the value found in the Verification Tag field of the OOTB
2890 * packet and set the T-bit in the Chunk Flags to indicate that the
2891 * Verification Tag is reflected. After sending this ABORT, the
2892 * receiver of the OOTB packet shall discard the OOTB packet and take
2893 * no further action.
2897 * The return value is the disposition of the chunk.
2899 sctp_disposition_t
sctp_sf_tabort_8_4_8(const struct sctp_endpoint
*ep
,
2900 const struct sctp_association
*asoc
,
2901 const sctp_subtype_t type
,
2903 sctp_cmd_seq_t
*commands
)
2905 struct sctp_packet
*packet
= NULL
;
2906 struct sctp_chunk
*chunk
= arg
;
2907 struct sctp_chunk
*abort
;
2909 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
2912 /* Make an ABORT. The T bit will be set if the asoc
2915 abort
= sctp_make_abort(asoc
, chunk
, 0);
2917 sctp_ootb_pkt_free(packet
);
2918 return SCTP_DISPOSITION_NOMEM
;
2921 /* Reflect vtag if T-Bit is set */
2922 if (sctp_test_T_bit(abort
))
2923 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
2925 /* Set the skb to the belonging sock for accounting. */
2926 abort
->skb
->sk
= ep
->base
.sk
;
2928 sctp_packet_append_chunk(packet
, abort
);
2930 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
2931 SCTP_PACKET(packet
));
2933 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
2935 return SCTP_DISPOSITION_CONSUME
;
2938 return SCTP_DISPOSITION_NOMEM
;
2942 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
2943 * event as ULP notification for each cause included in the chunk.
2945 * API 5.3.1.3 - SCTP_REMOTE_ERROR
2947 * The return value is the disposition of the chunk.
2949 sctp_disposition_t
sctp_sf_operr_notify(const struct sctp_endpoint
*ep
,
2950 const struct sctp_association
*asoc
,
2951 const sctp_subtype_t type
,
2953 sctp_cmd_seq_t
*commands
)
2955 struct sctp_chunk
*chunk
= arg
;
2956 struct sctp_ulpevent
*ev
;
2958 if (!sctp_vtag_verify(chunk
, asoc
))
2959 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2961 /* Make sure that the ERROR chunk has a valid length. */
2962 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
2963 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2966 while (chunk
->chunk_end
> chunk
->skb
->data
) {
2967 ev
= sctp_ulpevent_make_remote_error(asoc
, chunk
, 0,
2972 if (!sctp_add_cmd(commands
, SCTP_CMD_EVENT_ULP
,
2973 SCTP_ULPEVENT(ev
))) {
2974 sctp_ulpevent_free(ev
);
2978 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_OPERR
,
2981 return SCTP_DISPOSITION_CONSUME
;
2984 return SCTP_DISPOSITION_NOMEM
;
2988 * Process an inbound SHUTDOWN ACK.
2991 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
2992 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
2993 * peer, and remove all record of the association.
2995 * The return value is the disposition.
2997 sctp_disposition_t
sctp_sf_do_9_2_final(const struct sctp_endpoint
*ep
,
2998 const struct sctp_association
*asoc
,
2999 const sctp_subtype_t type
,
3001 sctp_cmd_seq_t
*commands
)
3003 struct sctp_chunk
*chunk
= arg
;
3004 struct sctp_chunk
*reply
;
3005 struct sctp_ulpevent
*ev
;
3007 if (!sctp_vtag_verify(chunk
, asoc
))
3008 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3010 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3011 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3012 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3015 /* 10.2 H) SHUTDOWN COMPLETE notification
3017 * When SCTP completes the shutdown procedures (section 9.2) this
3018 * notification is passed to the upper layer.
3020 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
3021 0, 0, 0, GFP_ATOMIC
);
3025 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
3027 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3028 * stop the T2-shutdown timer,
3030 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3031 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3033 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3034 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
3036 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3037 reply
= sctp_make_shutdown_complete(asoc
, chunk
);
3041 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
3042 SCTP_STATE(SCTP_STATE_CLOSED
));
3043 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS
);
3044 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3045 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
3047 /* ...and remove all record of the association. */
3048 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
3049 return SCTP_DISPOSITION_DELETE_TCB
;
3052 return SCTP_DISPOSITION_NOMEM
;
3056 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3058 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3059 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3060 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3061 * packet must fill in the Verification Tag field of the outbound
3062 * packet with the Verification Tag received in the SHUTDOWN ACK and
3063 * set the T-bit in the Chunk Flags to indicate that the Verification
3066 * 8) The receiver should respond to the sender of the OOTB packet with
3067 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3068 * MUST fill in the Verification Tag field of the outbound packet
3069 * with the value found in the Verification Tag field of the OOTB
3070 * packet and set the T-bit in the Chunk Flags to indicate that the
3071 * Verification Tag is reflected. After sending this ABORT, the
3072 * receiver of the OOTB packet shall discard the OOTB packet and take
3073 * no further action.
3075 sctp_disposition_t
sctp_sf_ootb(const struct sctp_endpoint
*ep
,
3076 const struct sctp_association
*asoc
,
3077 const sctp_subtype_t type
,
3079 sctp_cmd_seq_t
*commands
)
3081 struct sctp_chunk
*chunk
= arg
;
3082 struct sk_buff
*skb
= chunk
->skb
;
3083 sctp_chunkhdr_t
*ch
;
3085 int ootb_shut_ack
= 0;
3087 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES
);
3089 ch
= (sctp_chunkhdr_t
*) chunk
->chunk_hdr
;
3091 /* Break out if chunk length is less then minimal. */
3092 if (ntohs(ch
->length
) < sizeof(sctp_chunkhdr_t
))
3095 ch_end
= ((__u8
*)ch
) + WORD_ROUND(ntohs(ch
->length
));
3096 if (ch_end
> skb
->tail
)
3099 if (SCTP_CID_SHUTDOWN_ACK
== ch
->type
)
3102 /* RFC 2960, Section 3.3.7
3103 * Moreover, under any circumstances, an endpoint that
3104 * receives an ABORT MUST NOT respond to that ABORT by
3105 * sending an ABORT of its own.
3107 if (SCTP_CID_ABORT
== ch
->type
)
3108 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3110 ch
= (sctp_chunkhdr_t
*) ch_end
;
3111 } while (ch_end
< skb
->tail
);
3114 sctp_sf_shut_8_4_5(ep
, asoc
, type
, arg
, commands
);
3116 sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
3118 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3122 * Handle an "Out of the blue" SHUTDOWN ACK.
3124 * Section: 8.4 5, sctpimpguide 2.41.
3126 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3127 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3128 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3129 * packet must fill in the Verification Tag field of the outbound
3130 * packet with the Verification Tag received in the SHUTDOWN ACK and
3131 * set the T-bit in the Chunk Flags to indicate that the Verification
3135 * (endpoint, asoc, type, arg, commands)
3138 * (sctp_disposition_t)
3140 * The return value is the disposition of the chunk.
3142 static sctp_disposition_t
sctp_sf_shut_8_4_5(const struct sctp_endpoint
*ep
,
3143 const struct sctp_association
*asoc
,
3144 const sctp_subtype_t type
,
3146 sctp_cmd_seq_t
*commands
)
3148 struct sctp_packet
*packet
= NULL
;
3149 struct sctp_chunk
*chunk
= arg
;
3150 struct sctp_chunk
*shut
;
3152 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
3155 /* Make an SHUTDOWN_COMPLETE.
3156 * The T bit will be set if the asoc is NULL.
3158 shut
= sctp_make_shutdown_complete(asoc
, chunk
);
3160 sctp_ootb_pkt_free(packet
);
3161 return SCTP_DISPOSITION_NOMEM
;
3164 /* Reflect vtag if T-Bit is set */
3165 if (sctp_test_T_bit(shut
))
3166 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3168 /* Set the skb to the belonging sock for accounting. */
3169 shut
->skb
->sk
= ep
->base
.sk
;
3171 sctp_packet_append_chunk(packet
, shut
);
3173 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3174 SCTP_PACKET(packet
));
3176 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
3178 /* If the chunk length is invalid, we don't want to process
3179 * the reset of the packet.
3181 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3182 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3184 return SCTP_DISPOSITION_CONSUME
;
3187 return SCTP_DISPOSITION_NOMEM
;
3191 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3193 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3194 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3195 * procedures in section 8.4 SHOULD be followed, in other words it
3196 * should be treated as an Out Of The Blue packet.
3197 * [This means that we do NOT check the Verification Tag on these
3201 sctp_disposition_t
sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint
*ep
,
3202 const struct sctp_association
*asoc
,
3203 const sctp_subtype_t type
,
3205 sctp_cmd_seq_t
*commands
)
3207 /* Although we do have an association in this case, it corresponds
3208 * to a restarted association. So the packet is treated as an OOTB
3209 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3210 * called with a NULL association.
3212 return sctp_sf_shut_8_4_5(ep
, NULL
, type
, arg
, commands
);
3215 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3216 sctp_disposition_t
sctp_sf_do_asconf(const struct sctp_endpoint
*ep
,
3217 const struct sctp_association
*asoc
,
3218 const sctp_subtype_t type
, void *arg
,
3219 sctp_cmd_seq_t
*commands
)
3221 struct sctp_chunk
*chunk
= arg
;
3222 struct sctp_chunk
*asconf_ack
= NULL
;
3223 sctp_addiphdr_t
*hdr
;
3226 if (!sctp_vtag_verify(chunk
, asoc
)) {
3227 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3229 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3232 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3233 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_addip_chunk_t
)))
3234 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3237 hdr
= (sctp_addiphdr_t
*)chunk
->skb
->data
;
3238 serial
= ntohl(hdr
->serial
);
3240 /* ADDIP 4.2 C1) Compare the value of the serial number to the value
3241 * the endpoint stored in a new association variable
3242 * 'Peer-Serial-Number'.
3244 if (serial
== asoc
->peer
.addip_serial
+ 1) {
3245 /* ADDIP 4.2 C2) If the value found in the serial number is
3246 * equal to the ('Peer-Serial-Number' + 1), the endpoint MUST
3249 asconf_ack
= sctp_process_asconf((struct sctp_association
*)
3252 return SCTP_DISPOSITION_NOMEM
;
3253 } else if (serial
== asoc
->peer
.addip_serial
) {
3254 /* ADDIP 4.2 C3) If the value found in the serial number is
3255 * equal to the value stored in the 'Peer-Serial-Number'
3256 * IMPLEMENTATION NOTE: As an optimization a receiver may wish
3257 * to save the last ASCONF-ACK for some predetermined period of
3258 * time and instead of re-processing the ASCONF (with the same
3259 * serial number) it may just re-transmit the ASCONF-ACK.
3261 if (asoc
->addip_last_asconf_ack
)
3262 asconf_ack
= asoc
->addip_last_asconf_ack
;
3264 return SCTP_DISPOSITION_DISCARD
;
3266 /* ADDIP 4.2 C4) Otherwise, the ASCONF Chunk is discarded since
3267 * it must be either a stale packet or from an attacker.
3269 return SCTP_DISPOSITION_DISCARD
;
3272 /* ADDIP 4.2 C5) In both cases C2 and C3 the ASCONF-ACK MUST be sent
3273 * back to the source address contained in the IP header of the ASCONF
3274 * being responded to.
3276 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(asconf_ack
));
3278 return SCTP_DISPOSITION_CONSUME
;
3282 * ADDIP Section 4.3 General rules for address manipulation
3283 * When building TLV parameters for the ASCONF Chunk that will add or
3284 * delete IP addresses the D0 to D13 rules should be applied:
3286 sctp_disposition_t
sctp_sf_do_asconf_ack(const struct sctp_endpoint
*ep
,
3287 const struct sctp_association
*asoc
,
3288 const sctp_subtype_t type
, void *arg
,
3289 sctp_cmd_seq_t
*commands
)
3291 struct sctp_chunk
*asconf_ack
= arg
;
3292 struct sctp_chunk
*last_asconf
= asoc
->addip_last_asconf
;
3293 struct sctp_chunk
*abort
;
3294 sctp_addiphdr_t
*addip_hdr
;
3295 __u32 sent_serial
, rcvd_serial
;
3297 if (!sctp_vtag_verify(asconf_ack
, asoc
)) {
3298 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3300 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3303 /* Make sure that the ADDIP chunk has a valid length. */
3304 if (!sctp_chunk_length_valid(asconf_ack
, sizeof(sctp_addip_chunk_t
)))
3305 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3308 addip_hdr
= (sctp_addiphdr_t
*)asconf_ack
->skb
->data
;
3309 rcvd_serial
= ntohl(addip_hdr
->serial
);
3312 addip_hdr
= (sctp_addiphdr_t
*)last_asconf
->subh
.addip_hdr
;
3313 sent_serial
= ntohl(addip_hdr
->serial
);
3315 sent_serial
= asoc
->addip_serial
- 1;
3318 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3319 * equal to the next serial number to be used but no ASCONF chunk is
3320 * outstanding the endpoint MUST ABORT the association. Note that a
3321 * sequence number is greater than if it is no more than 2^^31-1
3322 * larger than the current sequence number (using serial arithmetic).
3324 if (ADDIP_SERIAL_gte(rcvd_serial
, sent_serial
+ 1) &&
3325 !(asoc
->addip_last_asconf
)) {
3326 abort
= sctp_make_abort(asoc
, asconf_ack
,
3327 sizeof(sctp_errhdr_t
));
3329 sctp_init_cause(abort
, SCTP_ERROR_ASCONF_ACK
, NULL
, 0);
3330 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3333 /* We are going to ABORT, so we might as well stop
3334 * processing the rest of the chunks in the packet.
3336 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3337 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3338 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
3339 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3340 SCTP_U32(SCTP_ERROR_ASCONF_ACK
));
3341 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
3342 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3343 return SCTP_DISPOSITION_ABORT
;
3346 if ((rcvd_serial
== sent_serial
) && asoc
->addip_last_asconf
) {
3347 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3348 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3350 if (!sctp_process_asconf_ack((struct sctp_association
*)asoc
,
3352 return SCTP_DISPOSITION_CONSUME
;
3354 abort
= sctp_make_abort(asoc
, asconf_ack
,
3355 sizeof(sctp_errhdr_t
));
3357 sctp_init_cause(abort
, SCTP_ERROR_RSRC_LOW
, NULL
, 0);
3358 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3361 /* We are going to ABORT, so we might as well stop
3362 * processing the rest of the chunks in the packet.
3364 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
3365 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3366 SCTP_U32(SCTP_ERROR_ASCONF_ACK
));
3367 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
3368 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3369 return SCTP_DISPOSITION_ABORT
;
3372 return SCTP_DISPOSITION_DISCARD
;
3376 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3378 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3379 * its cumulative TSN point to the value carried in the FORWARD TSN
3380 * chunk, and then MUST further advance its cumulative TSN point locally
3382 * After the above processing, the data receiver MUST stop reporting any
3383 * missing TSNs earlier than or equal to the new cumulative TSN point.
3385 * Verification Tag: 8.5 Verification Tag [Normal verification]
3387 * The return value is the disposition of the chunk.
3389 sctp_disposition_t
sctp_sf_eat_fwd_tsn(const struct sctp_endpoint
*ep
,
3390 const struct sctp_association
*asoc
,
3391 const sctp_subtype_t type
,
3393 sctp_cmd_seq_t
*commands
)
3395 struct sctp_chunk
*chunk
= arg
;
3396 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3400 if (!sctp_vtag_verify(chunk
, asoc
)) {
3401 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3403 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3406 /* Make sure that the FORWARD_TSN chunk has valid length. */
3407 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3408 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3411 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3412 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3413 len
= ntohs(chunk
->chunk_hdr
->length
);
3414 len
-= sizeof(struct sctp_chunkhdr
);
3415 skb_pull(chunk
->skb
, len
);
3417 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3418 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__
, tsn
);
3420 /* The TSN is too high--silently discard the chunk and count on it
3421 * getting retransmitted later.
3423 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3424 goto discard_noforce
;
3426 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3427 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3428 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3431 /* Count this as receiving DATA. */
3432 if (asoc
->autoclose
) {
3433 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3434 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
3437 /* FIXME: For now send a SACK, but DATA processing may
3440 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
3442 return SCTP_DISPOSITION_CONSUME
;
3445 return SCTP_DISPOSITION_DISCARD
;
3448 sctp_disposition_t
sctp_sf_eat_fwd_tsn_fast(
3449 const struct sctp_endpoint
*ep
,
3450 const struct sctp_association
*asoc
,
3451 const sctp_subtype_t type
,
3453 sctp_cmd_seq_t
*commands
)
3455 struct sctp_chunk
*chunk
= arg
;
3456 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3460 if (!sctp_vtag_verify(chunk
, asoc
)) {
3461 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3463 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3466 /* Make sure that the FORWARD_TSN chunk has a valid length. */
3467 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3468 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3471 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3472 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3473 len
= ntohs(chunk
->chunk_hdr
->length
);
3474 len
-= sizeof(struct sctp_chunkhdr
);
3475 skb_pull(chunk
->skb
, len
);
3477 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3478 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__
, tsn
);
3480 /* The TSN is too high--silently discard the chunk and count on it
3481 * getting retransmitted later.
3483 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3486 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3487 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3488 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3491 /* Go a head and force a SACK, since we are shutting down. */
3493 /* Implementor's Guide.
3495 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3496 * respond to each received packet containing one or more DATA chunk(s)
3497 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3499 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3500 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3501 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3502 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3504 return SCTP_DISPOSITION_CONSUME
;
3508 * Process an unknown chunk.
3510 * Section: 3.2. Also, 2.1 in the implementor's guide.
3512 * Chunk Types are encoded such that the highest-order two bits specify
3513 * the action that must be taken if the processing endpoint does not
3514 * recognize the Chunk Type.
3516 * 00 - Stop processing this SCTP packet and discard it, do not process
3517 * any further chunks within it.
3519 * 01 - Stop processing this SCTP packet and discard it, do not process
3520 * any further chunks within it, and report the unrecognized
3521 * chunk in an 'Unrecognized Chunk Type'.
3523 * 10 - Skip this chunk and continue processing.
3525 * 11 - Skip this chunk and continue processing, but report in an ERROR
3526 * Chunk using the 'Unrecognized Chunk Type' cause of error.
3528 * The return value is the disposition of the chunk.
3530 sctp_disposition_t
sctp_sf_unk_chunk(const struct sctp_endpoint
*ep
,
3531 const struct sctp_association
*asoc
,
3532 const sctp_subtype_t type
,
3534 sctp_cmd_seq_t
*commands
)
3536 struct sctp_chunk
*unk_chunk
= arg
;
3537 struct sctp_chunk
*err_chunk
;
3538 sctp_chunkhdr_t
*hdr
;
3540 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type
.chunk
);
3542 if (!sctp_vtag_verify(unk_chunk
, asoc
))
3543 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3545 /* Make sure that the chunk has a valid length.
3546 * Since we don't know the chunk type, we use a general
3547 * chunkhdr structure to make a comparison.
3549 if (!sctp_chunk_length_valid(unk_chunk
, sizeof(sctp_chunkhdr_t
)))
3550 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3553 switch (type
.chunk
& SCTP_CID_ACTION_MASK
) {
3554 case SCTP_CID_ACTION_DISCARD
:
3555 /* Discard the packet. */
3556 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3558 case SCTP_CID_ACTION_DISCARD_ERR
:
3559 /* Discard the packet. */
3560 sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3562 /* Generate an ERROR chunk as response. */
3563 hdr
= unk_chunk
->chunk_hdr
;
3564 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
3565 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
3566 WORD_ROUND(ntohs(hdr
->length
)));
3568 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3569 SCTP_CHUNK(err_chunk
));
3571 return SCTP_DISPOSITION_CONSUME
;
3573 case SCTP_CID_ACTION_SKIP
:
3574 /* Skip the chunk. */
3575 return SCTP_DISPOSITION_DISCARD
;
3577 case SCTP_CID_ACTION_SKIP_ERR
:
3578 /* Generate an ERROR chunk as response. */
3579 hdr
= unk_chunk
->chunk_hdr
;
3580 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
3581 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
3582 WORD_ROUND(ntohs(hdr
->length
)));
3584 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3585 SCTP_CHUNK(err_chunk
));
3587 /* Skip the chunk. */
3588 return SCTP_DISPOSITION_CONSUME
;
3594 return SCTP_DISPOSITION_DISCARD
;
3598 * Discard the chunk.
3600 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
3601 * [Too numerous to mention...]
3602 * Verification Tag: No verification needed.
3604 * (endpoint, asoc, chunk)
3607 * (asoc, reply_msg, msg_up, timers, counters)
3609 * The return value is the disposition of the chunk.
3611 sctp_disposition_t
sctp_sf_discard_chunk(const struct sctp_endpoint
*ep
,
3612 const struct sctp_association
*asoc
,
3613 const sctp_subtype_t type
,
3615 sctp_cmd_seq_t
*commands
)
3617 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type
.chunk
);
3618 return SCTP_DISPOSITION_DISCARD
;
3622 * Discard the whole packet.
3626 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
3627 * silently discard the OOTB packet and take no further action.
3629 * Verification Tag: No verification necessary
3632 * (endpoint, asoc, chunk)
3635 * (asoc, reply_msg, msg_up, timers, counters)
3637 * The return value is the disposition of the chunk.
3639 sctp_disposition_t
sctp_sf_pdiscard(const struct sctp_endpoint
*ep
,
3640 const struct sctp_association
*asoc
,
3641 const sctp_subtype_t type
,
3643 sctp_cmd_seq_t
*commands
)
3645 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
3647 return SCTP_DISPOSITION_CONSUME
;
3652 * The other end is violating protocol.
3654 * Section: Not specified
3655 * Verification Tag: Not specified
3657 * (endpoint, asoc, chunk)
3660 * (asoc, reply_msg, msg_up, timers, counters)
3662 * We simply tag the chunk as a violation. The state machine will log
3663 * the violation and continue.
3665 sctp_disposition_t
sctp_sf_violation(const struct sctp_endpoint
*ep
,
3666 const struct sctp_association
*asoc
,
3667 const sctp_subtype_t type
,
3669 sctp_cmd_seq_t
*commands
)
3671 return SCTP_DISPOSITION_VIOLATION
;
3676 * Handle a protocol violation when the chunk length is invalid.
3677 * "Invalid" length is identified as smaller then the minimal length a
3678 * given chunk can be. For example, a SACK chunk has invalid length
3679 * if it's length is set to be smaller then the size of sctp_sack_chunk_t.
3681 * We inform the other end by sending an ABORT with a Protocol Violation
3684 * Section: Not specified
3685 * Verification Tag: Nothing to do
3687 * (endpoint, asoc, chunk)
3690 * (reply_msg, msg_up, counters)
3692 * Generate an ABORT chunk and terminate the association.
3694 static sctp_disposition_t
sctp_sf_violation_chunklen(
3695 const struct sctp_endpoint
*ep
,
3696 const struct sctp_association
*asoc
,
3697 const sctp_subtype_t type
,
3699 sctp_cmd_seq_t
*commands
)
3701 struct sctp_chunk
*chunk
= arg
;
3702 struct sctp_chunk
*abort
= NULL
;
3703 char err_str
[]="The following chunk had invalid length:";
3705 /* Make the abort chunk. */
3706 abort
= sctp_make_abort_violation(asoc
, chunk
, err_str
,
3711 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
3712 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
3714 if (asoc
->state
<= SCTP_STATE_COOKIE_ECHOED
) {
3715 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3716 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
3717 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
3718 SCTP_U32(SCTP_ERROR_PROTO_VIOLATION
));
3720 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3721 SCTP_U32(SCTP_ERROR_PROTO_VIOLATION
));
3722 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3725 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
3727 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
3729 return SCTP_DISPOSITION_ABORT
;
3732 return SCTP_DISPOSITION_NOMEM
;
3735 /***************************************************************************
3736 * These are the state functions for handling primitive (Section 10) events.
3737 ***************************************************************************/
3739 * sctp_sf_do_prm_asoc
3741 * Section: 10.1 ULP-to-SCTP
3744 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
3745 * outbound stream count)
3746 * -> association id [,destination transport addr list] [,outbound stream
3749 * This primitive allows the upper layer to initiate an association to a
3750 * specific peer endpoint.
3752 * The peer endpoint shall be specified by one of the transport addresses
3753 * which defines the endpoint (see Section 1.4). If the local SCTP
3754 * instance has not been initialized, the ASSOCIATE is considered an
3756 * [This is not relevant for the kernel implementation since we do all
3757 * initialization at boot time. It we hadn't initialized we wouldn't
3758 * get anywhere near this code.]
3760 * An association id, which is a local handle to the SCTP association,
3761 * will be returned on successful establishment of the association. If
3762 * SCTP is not able to open an SCTP association with the peer endpoint,
3763 * an error is returned.
3764 * [In the kernel implementation, the struct sctp_association needs to
3765 * be created BEFORE causing this primitive to run.]
3767 * Other association parameters may be returned, including the
3768 * complete destination transport addresses of the peer as well as the
3769 * outbound stream count of the local endpoint. One of the transport
3770 * address from the returned destination addresses will be selected by
3771 * the local endpoint as default primary path for sending SCTP packets
3772 * to this peer. The returned "destination transport addr list" can
3773 * be used by the ULP to change the default primary path or to force
3774 * sending a packet to a specific transport address. [All of this
3775 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
3778 * Mandatory attributes:
3780 * o local SCTP instance name - obtained from the INITIALIZE operation.
3781 * [This is the argument asoc.]
3782 * o destination transport addr - specified as one of the transport
3783 * addresses of the peer endpoint with which the association is to be
3785 * [This is asoc->peer.active_path.]
3786 * o outbound stream count - the number of outbound streams the ULP
3787 * would like to open towards this peer endpoint.
3788 * [BUG: This is not currently implemented.]
3789 * Optional attributes:
3793 * The return value is a disposition.
3795 sctp_disposition_t
sctp_sf_do_prm_asoc(const struct sctp_endpoint
*ep
,
3796 const struct sctp_association
*asoc
,
3797 const sctp_subtype_t type
,
3799 sctp_cmd_seq_t
*commands
)
3801 struct sctp_chunk
*repl
;
3803 /* The comment below says that we enter COOKIE-WAIT AFTER
3804 * sending the INIT, but that doesn't actually work in our
3807 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
3808 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
3810 /* RFC 2960 5.1 Normal Establishment of an Association
3812 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
3813 * must provide its Verification Tag (Tag_A) in the Initiate
3814 * Tag field. Tag_A SHOULD be a random number in the range of
3815 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
3818 repl
= sctp_make_init(asoc
, &asoc
->base
.bind_addr
, GFP_ATOMIC
, 0);
3822 /* Cast away the const modifier, as we want to just
3823 * rerun it through as a sideffect.
3825 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
,
3826 SCTP_ASOC((struct sctp_association
*) asoc
));
3828 /* Choose transport for INIT. */
3829 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
3832 /* After sending the INIT, "A" starts the T1-init timer and
3833 * enters the COOKIE-WAIT state.
3835 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
3836 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
3837 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
3838 return SCTP_DISPOSITION_CONSUME
;
3841 return SCTP_DISPOSITION_NOMEM
;
3845 * Process the SEND primitive.
3847 * Section: 10.1 ULP-to-SCTP
3850 * Format: SEND(association id, buffer address, byte count [,context]
3851 * [,stream id] [,life time] [,destination transport address]
3852 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
3855 * This is the main method to send user data via SCTP.
3857 * Mandatory attributes:
3859 * o association id - local handle to the SCTP association
3861 * o buffer address - the location where the user message to be
3862 * transmitted is stored;
3864 * o byte count - The size of the user data in number of bytes;
3866 * Optional attributes:
3868 * o context - an optional 32 bit integer that will be carried in the
3869 * sending failure notification to the ULP if the transportation of
3870 * this User Message fails.
3872 * o stream id - to indicate which stream to send the data on. If not
3873 * specified, stream 0 will be used.
3875 * o life time - specifies the life time of the user data. The user data
3876 * will not be sent by SCTP after the life time expires. This
3877 * parameter can be used to avoid efforts to transmit stale
3878 * user messages. SCTP notifies the ULP if the data cannot be
3879 * initiated to transport (i.e. sent to the destination via SCTP's
3880 * send primitive) within the life time variable. However, the
3881 * user data will be transmitted if SCTP has attempted to transmit a
3882 * chunk before the life time expired.
3884 * o destination transport address - specified as one of the destination
3885 * transport addresses of the peer endpoint to which this packet
3886 * should be sent. Whenever possible, SCTP should use this destination
3887 * transport address for sending the packets, instead of the current
3890 * o unorder flag - this flag, if present, indicates that the user
3891 * would like the data delivered in an unordered fashion to the peer
3892 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
3895 * o no-bundle flag - instructs SCTP not to bundle this user data with
3896 * other outbound DATA chunks. SCTP MAY still bundle even when
3897 * this flag is present, when faced with network congestion.
3899 * o payload protocol-id - A 32 bit unsigned integer that is to be
3900 * passed to the peer indicating the type of payload protocol data
3901 * being transmitted. This value is passed as opaque data by SCTP.
3903 * The return value is the disposition.
3905 sctp_disposition_t
sctp_sf_do_prm_send(const struct sctp_endpoint
*ep
,
3906 const struct sctp_association
*asoc
,
3907 const sctp_subtype_t type
,
3909 sctp_cmd_seq_t
*commands
)
3911 struct sctp_chunk
*chunk
= arg
;
3913 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
3914 return SCTP_DISPOSITION_CONSUME
;
3918 * Process the SHUTDOWN primitive.
3923 * Format: SHUTDOWN(association id)
3926 * Gracefully closes an association. Any locally queued user data
3927 * will be delivered to the peer. The association will be terminated only
3928 * after the peer acknowledges all the SCTP packets sent. A success code
3929 * will be returned on successful termination of the association. If
3930 * attempting to terminate the association results in a failure, an error
3931 * code shall be returned.
3933 * Mandatory attributes:
3935 * o association id - local handle to the SCTP association
3937 * Optional attributes:
3941 * The return value is the disposition.
3943 sctp_disposition_t
sctp_sf_do_9_2_prm_shutdown(
3944 const struct sctp_endpoint
*ep
,
3945 const struct sctp_association
*asoc
,
3946 const sctp_subtype_t type
,
3948 sctp_cmd_seq_t
*commands
)
3952 /* From 9.2 Shutdown of an Association
3953 * Upon receipt of the SHUTDOWN primitive from its upper
3954 * layer, the endpoint enters SHUTDOWN-PENDING state and
3955 * remains there until all outstanding data has been
3956 * acknowledged by its peer. The endpoint accepts no new data
3957 * from its upper layer, but retransmits data to the far end
3958 * if necessary to fill gaps.
3960 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
3961 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
3963 /* sctpimpguide-05 Section 2.12.2
3964 * The sender of the SHUTDOWN MAY also start an overall guard timer
3965 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
3967 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
3968 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
3970 disposition
= SCTP_DISPOSITION_CONSUME
;
3971 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
3972 disposition
= sctp_sf_do_9_2_start_shutdown(ep
, asoc
, type
,
3979 * Process the ABORT primitive.
3984 * Format: Abort(association id [, cause code])
3987 * Ungracefully closes an association. Any locally queued user data
3988 * will be discarded and an ABORT chunk is sent to the peer. A success code
3989 * will be returned on successful abortion of the association. If
3990 * attempting to abort the association results in a failure, an error
3991 * code shall be returned.
3993 * Mandatory attributes:
3995 * o association id - local handle to the SCTP association
3997 * Optional attributes:
3999 * o cause code - reason of the abort to be passed to the peer
4003 * The return value is the disposition.
4005 sctp_disposition_t
sctp_sf_do_9_1_prm_abort(
4006 const struct sctp_endpoint
*ep
,
4007 const struct sctp_association
*asoc
,
4008 const sctp_subtype_t type
,
4010 sctp_cmd_seq_t
*commands
)
4012 /* From 9.1 Abort of an Association
4013 * Upon receipt of the ABORT primitive from its upper
4014 * layer, the endpoint enters CLOSED state and
4015 * discard all outstanding data has been
4016 * acknowledged by its peer. The endpoint accepts no new data
4017 * from its upper layer, but retransmits data to the far end
4018 * if necessary to fill gaps.
4020 struct msghdr
*msg
= arg
;
4021 struct sctp_chunk
*abort
;
4022 sctp_disposition_t retval
;
4024 retval
= SCTP_DISPOSITION_CONSUME
;
4026 /* Generate ABORT chunk to send the peer. */
4027 abort
= sctp_make_abort_user(asoc
, NULL
, msg
);
4029 retval
= SCTP_DISPOSITION_NOMEM
;
4031 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4033 /* Even if we can't send the ABORT due to low memory delete the
4034 * TCB. This is a departure from our typical NOMEM handling.
4037 /* Delete the established association. */
4038 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4039 SCTP_U32(SCTP_ERROR_USER_ABORT
));
4041 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4042 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
4047 /* We tried an illegal operation on an association which is closed. */
4048 sctp_disposition_t
sctp_sf_error_closed(const struct sctp_endpoint
*ep
,
4049 const struct sctp_association
*asoc
,
4050 const sctp_subtype_t type
,
4052 sctp_cmd_seq_t
*commands
)
4054 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
, SCTP_ERROR(-EINVAL
));
4055 return SCTP_DISPOSITION_CONSUME
;
4058 /* We tried an illegal operation on an association which is shutting
4061 sctp_disposition_t
sctp_sf_error_shutdown(const struct sctp_endpoint
*ep
,
4062 const struct sctp_association
*asoc
,
4063 const sctp_subtype_t type
,
4065 sctp_cmd_seq_t
*commands
)
4067 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
,
4068 SCTP_ERROR(-ESHUTDOWN
));
4069 return SCTP_DISPOSITION_CONSUME
;
4073 * sctp_cookie_wait_prm_shutdown
4075 * Section: 4 Note: 2
4080 * The RFC does not explicitly address this issue, but is the route through the
4081 * state table when someone issues a shutdown while in COOKIE_WAIT state.
4086 sctp_disposition_t
sctp_sf_cookie_wait_prm_shutdown(
4087 const struct sctp_endpoint
*ep
,
4088 const struct sctp_association
*asoc
,
4089 const sctp_subtype_t type
,
4091 sctp_cmd_seq_t
*commands
)
4093 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4094 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4096 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4097 SCTP_STATE(SCTP_STATE_CLOSED
));
4099 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS
);
4101 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
4103 return SCTP_DISPOSITION_DELETE_TCB
;
4107 * sctp_cookie_echoed_prm_shutdown
4109 * Section: 4 Note: 2
4114 * The RFC does not explcitly address this issue, but is the route through the
4115 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
4120 sctp_disposition_t
sctp_sf_cookie_echoed_prm_shutdown(
4121 const struct sctp_endpoint
*ep
,
4122 const struct sctp_association
*asoc
,
4123 const sctp_subtype_t type
,
4124 void *arg
, sctp_cmd_seq_t
*commands
)
4126 /* There is a single T1 timer, so we should be able to use
4127 * common function with the COOKIE-WAIT state.
4129 return sctp_sf_cookie_wait_prm_shutdown(ep
, asoc
, type
, arg
, commands
);
4133 * sctp_sf_cookie_wait_prm_abort
4135 * Section: 4 Note: 2
4140 * The RFC does not explicitly address this issue, but is the route through the
4141 * state table when someone issues an abort while in COOKIE_WAIT state.
4146 sctp_disposition_t
sctp_sf_cookie_wait_prm_abort(
4147 const struct sctp_endpoint
*ep
,
4148 const struct sctp_association
*asoc
,
4149 const sctp_subtype_t type
,
4151 sctp_cmd_seq_t
*commands
)
4153 struct msghdr
*msg
= arg
;
4154 struct sctp_chunk
*abort
;
4155 sctp_disposition_t retval
;
4157 /* Stop T1-init timer */
4158 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4159 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4160 retval
= SCTP_DISPOSITION_CONSUME
;
4162 /* Generate ABORT chunk to send the peer */
4163 abort
= sctp_make_abort_user(asoc
, NULL
, msg
);
4165 retval
= SCTP_DISPOSITION_NOMEM
;
4167 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4169 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4170 SCTP_STATE(SCTP_STATE_CLOSED
));
4172 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4174 /* Even if we can't send the ABORT due to low memory delete the
4175 * TCB. This is a departure from our typical NOMEM handling.
4178 /* Delete the established association. */
4179 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4180 SCTP_U32(SCTP_ERROR_USER_ABORT
));
4186 * sctp_sf_cookie_echoed_prm_abort
4188 * Section: 4 Note: 3
4193 * The RFC does not explcitly address this issue, but is the route through the
4194 * state table when someone issues an abort while in COOKIE_ECHOED state.
4199 sctp_disposition_t
sctp_sf_cookie_echoed_prm_abort(
4200 const struct sctp_endpoint
*ep
,
4201 const struct sctp_association
*asoc
,
4202 const sctp_subtype_t type
,
4204 sctp_cmd_seq_t
*commands
)
4206 /* There is a single T1 timer, so we should be able to use
4207 * common function with the COOKIE-WAIT state.
4209 return sctp_sf_cookie_wait_prm_abort(ep
, asoc
, type
, arg
, commands
);
4213 * sctp_sf_shutdown_pending_prm_abort
4218 * The RFC does not explicitly address this issue, but is the route through the
4219 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
4224 sctp_disposition_t
sctp_sf_shutdown_pending_prm_abort(
4225 const struct sctp_endpoint
*ep
,
4226 const struct sctp_association
*asoc
,
4227 const sctp_subtype_t type
,
4229 sctp_cmd_seq_t
*commands
)
4231 /* Stop the T5-shutdown guard timer. */
4232 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4233 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
4235 return sctp_sf_do_9_1_prm_abort(ep
, asoc
, type
, arg
, commands
);
4239 * sctp_sf_shutdown_sent_prm_abort
4244 * The RFC does not explicitly address this issue, but is the route through the
4245 * state table when someone issues an abort while in SHUTDOWN-SENT state.
4250 sctp_disposition_t
sctp_sf_shutdown_sent_prm_abort(
4251 const struct sctp_endpoint
*ep
,
4252 const struct sctp_association
*asoc
,
4253 const sctp_subtype_t type
,
4255 sctp_cmd_seq_t
*commands
)
4257 /* Stop the T2-shutdown timer. */
4258 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4259 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
4261 /* Stop the T5-shutdown guard timer. */
4262 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4263 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
4265 return sctp_sf_do_9_1_prm_abort(ep
, asoc
, type
, arg
, commands
);
4269 * sctp_sf_cookie_echoed_prm_abort
4274 * The RFC does not explcitly address this issue, but is the route through the
4275 * state table when someone issues an abort while in COOKIE_ECHOED state.
4280 sctp_disposition_t
sctp_sf_shutdown_ack_sent_prm_abort(
4281 const struct sctp_endpoint
*ep
,
4282 const struct sctp_association
*asoc
,
4283 const sctp_subtype_t type
,
4285 sctp_cmd_seq_t
*commands
)
4287 /* The same T2 timer, so we should be able to use
4288 * common function with the SHUTDOWN-SENT state.
4290 return sctp_sf_shutdown_sent_prm_abort(ep
, asoc
, type
, arg
, commands
);
4294 * Process the REQUESTHEARTBEAT primitive
4297 * J) Request Heartbeat
4299 * Format: REQUESTHEARTBEAT(association id, destination transport address)
4303 * Instructs the local endpoint to perform a HeartBeat on the specified
4304 * destination transport address of the given association. The returned
4305 * result should indicate whether the transmission of the HEARTBEAT
4306 * chunk to the destination address is successful.
4308 * Mandatory attributes:
4310 * o association id - local handle to the SCTP association
4312 * o destination transport address - the transport address of the
4313 * association on which a heartbeat should be issued.
4315 sctp_disposition_t
sctp_sf_do_prm_requestheartbeat(
4316 const struct sctp_endpoint
*ep
,
4317 const struct sctp_association
*asoc
,
4318 const sctp_subtype_t type
,
4320 sctp_cmd_seq_t
*commands
)
4322 return sctp_sf_heartbeat(ep
, asoc
, type
, (struct sctp_transport
*)arg
,
4327 * ADDIP Section 4.1 ASCONF Chunk Procedures
4328 * When an endpoint has an ASCONF signaled change to be sent to the
4329 * remote endpoint it should do A1 to A9
4331 sctp_disposition_t
sctp_sf_do_prm_asconf(const struct sctp_endpoint
*ep
,
4332 const struct sctp_association
*asoc
,
4333 const sctp_subtype_t type
,
4335 sctp_cmd_seq_t
*commands
)
4337 struct sctp_chunk
*chunk
= arg
;
4339 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
4340 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4341 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
4342 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
4343 return SCTP_DISPOSITION_CONSUME
;
4347 * Ignore the primitive event
4349 * The return value is the disposition of the primitive.
4351 sctp_disposition_t
sctp_sf_ignore_primitive(
4352 const struct sctp_endpoint
*ep
,
4353 const struct sctp_association
*asoc
,
4354 const sctp_subtype_t type
,
4356 sctp_cmd_seq_t
*commands
)
4358 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type
.primitive
);
4359 return SCTP_DISPOSITION_DISCARD
;
4362 /***************************************************************************
4363 * These are the state functions for the OTHER events.
4364 ***************************************************************************/
4367 * Start the shutdown negotiation.
4370 * Once all its outstanding data has been acknowledged, the endpoint
4371 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
4372 * TSN Ack field the last sequential TSN it has received from the peer.
4373 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
4374 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
4375 * with the updated last sequential TSN received from its peer.
4377 * The return value is the disposition.
4379 sctp_disposition_t
sctp_sf_do_9_2_start_shutdown(
4380 const struct sctp_endpoint
*ep
,
4381 const struct sctp_association
*asoc
,
4382 const sctp_subtype_t type
,
4384 sctp_cmd_seq_t
*commands
)
4386 struct sctp_chunk
*reply
;
4388 /* Once all its outstanding data has been acknowledged, the
4389 * endpoint shall send a SHUTDOWN chunk to its peer including
4390 * in the Cumulative TSN Ack field the last sequential TSN it
4391 * has received from the peer.
4393 reply
= sctp_make_shutdown(asoc
, NULL
);
4397 /* Set the transport for the SHUTDOWN chunk and the timeout for the
4398 * T2-shutdown timer.
4400 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
4402 /* It shall then start the T2-shutdown timer */
4403 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4404 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
4406 if (asoc
->autoclose
)
4407 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4408 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
4410 /* and enter the SHUTDOWN-SENT state. */
4411 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4412 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT
));
4414 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4416 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4419 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
4421 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
4423 return SCTP_DISPOSITION_CONSUME
;
4426 return SCTP_DISPOSITION_NOMEM
;
4430 * Generate a SHUTDOWN ACK now that everything is SACK'd.
4434 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4435 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
4436 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
4437 * endpoint must re-send the SHUTDOWN ACK.
4439 * The return value is the disposition.
4441 sctp_disposition_t
sctp_sf_do_9_2_shutdown_ack(
4442 const struct sctp_endpoint
*ep
,
4443 const struct sctp_association
*asoc
,
4444 const sctp_subtype_t type
,
4446 sctp_cmd_seq_t
*commands
)
4448 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
4449 struct sctp_chunk
*reply
;
4451 /* There are 2 ways of getting here:
4452 * 1) called in response to a SHUTDOWN chunk
4453 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
4455 * For the case (2), the arg parameter is set to NULL. We need
4456 * to check that we have a chunk before accessing it's fields.
4459 if (!sctp_vtag_verify(chunk
, asoc
))
4460 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
4462 /* Make sure that the SHUTDOWN chunk has a valid length. */
4463 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_shutdown_chunk_t
)))
4464 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
4468 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4469 * shall send a SHUTDOWN ACK ...
4471 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
4475 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
4476 * the T2-shutdown timer.
4478 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
4480 /* and start/restart a T2-shutdown timer of its own, */
4481 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
4482 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
4484 if (asoc
->autoclose
)
4485 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4486 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
4488 /* Enter the SHUTDOWN-ACK-SENT state. */
4489 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4490 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT
));
4492 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4494 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4497 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
4499 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
4501 return SCTP_DISPOSITION_CONSUME
;
4504 return SCTP_DISPOSITION_NOMEM
;
4508 * Ignore the event defined as other
4510 * The return value is the disposition of the event.
4512 sctp_disposition_t
sctp_sf_ignore_other(const struct sctp_endpoint
*ep
,
4513 const struct sctp_association
*asoc
,
4514 const sctp_subtype_t type
,
4516 sctp_cmd_seq_t
*commands
)
4518 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type
.other
);
4519 return SCTP_DISPOSITION_DISCARD
;
4522 /************************************************************
4523 * These are the state functions for handling timeout events.
4524 ************************************************************/
4529 * Section: 6.3.3 Handle T3-rtx Expiration
4531 * Whenever the retransmission timer T3-rtx expires for a destination
4532 * address, do the following:
4535 * The return value is the disposition of the chunk.
4537 sctp_disposition_t
sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint
*ep
,
4538 const struct sctp_association
*asoc
,
4539 const sctp_subtype_t type
,
4541 sctp_cmd_seq_t
*commands
)
4543 struct sctp_transport
*transport
= arg
;
4545 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
4546 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
4547 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4548 SCTP_U32(SCTP_ERROR_NO_ERROR
));
4549 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4550 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
4551 return SCTP_DISPOSITION_DELETE_TCB
;
4554 /* E1) For the destination address for which the timer
4555 * expires, adjust its ssthresh with rules defined in Section
4556 * 7.2.3 and set the cwnd <- MTU.
4559 /* E2) For the destination address for which the timer
4560 * expires, set RTO <- RTO * 2 ("back off the timer"). The
4561 * maximum value discussed in rule C7 above (RTO.max) may be
4562 * used to provide an upper bound to this doubling operation.
4565 /* E3) Determine how many of the earliest (i.e., lowest TSN)
4566 * outstanding DATA chunks for the address for which the
4567 * T3-rtx has expired will fit into a single packet, subject
4568 * to the MTU constraint for the path corresponding to the
4569 * destination transport address to which the retransmission
4570 * is being sent (this may be different from the address for
4571 * which the timer expires [see Section 6.4]). Call this
4572 * value K. Bundle and retransmit those K DATA chunks in a
4573 * single packet to the destination endpoint.
4575 * Note: Any DATA chunks that were sent to the address for
4576 * which the T3-rtx timer expired but did not fit in one MTU
4577 * (rule E3 above), should be marked for retransmission and
4578 * sent as soon as cwnd allows (normally when a SACK arrives).
4581 /* NB: Rules E4 and F1 are implicit in R1. */
4582 sctp_add_cmd_sf(commands
, SCTP_CMD_RETRAN
, SCTP_TRANSPORT(transport
));
4584 /* Do some failure management (Section 8.2). */
4585 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
4587 return SCTP_DISPOSITION_CONSUME
;
4591 * Generate delayed SACK on timeout
4593 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
4595 * The guidelines on delayed acknowledgement algorithm specified in
4596 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
4597 * acknowledgement SHOULD be generated for at least every second packet
4598 * (not every second DATA chunk) received, and SHOULD be generated
4599 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
4600 * some situations it may be beneficial for an SCTP transmitter to be
4601 * more conservative than the algorithms detailed in this document
4602 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
4603 * the following algorithms allow.
4605 sctp_disposition_t
sctp_sf_do_6_2_sack(const struct sctp_endpoint
*ep
,
4606 const struct sctp_association
*asoc
,
4607 const sctp_subtype_t type
,
4609 sctp_cmd_seq_t
*commands
)
4611 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
4612 return SCTP_DISPOSITION_CONSUME
;
4616 * sctp_sf_t1_init_timer_expire
4618 * Section: 4 Note: 2
4623 * RFC 2960 Section 4 Notes
4624 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
4625 * and re-start the T1-init timer without changing state. This MUST
4626 * be repeated up to 'Max.Init.Retransmits' times. After that, the
4627 * endpoint MUST abort the initialization process and report the
4628 * error to SCTP user.
4634 sctp_disposition_t
sctp_sf_t1_init_timer_expire(const struct sctp_endpoint
*ep
,
4635 const struct sctp_association
*asoc
,
4636 const sctp_subtype_t type
,
4638 sctp_cmd_seq_t
*commands
)
4640 struct sctp_chunk
*repl
= NULL
;
4641 struct sctp_bind_addr
*bp
;
4642 int attempts
= asoc
->init_err_counter
+ 1;
4644 SCTP_DEBUG_PRINTK("Timer T1 expired (INIT).\n");
4646 if (attempts
<= asoc
->max_init_attempts
) {
4647 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
4648 repl
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, 0);
4650 return SCTP_DISPOSITION_NOMEM
;
4652 /* Choose transport for INIT. */
4653 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
4656 /* Issue a sideeffect to do the needed accounting. */
4657 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_RESTART
,
4658 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4660 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
4662 SCTP_DEBUG_PRINTK("Giving up on INIT, attempts: %d"
4663 " max_init_attempts: %d\n",
4664 attempts
, asoc
->max_init_attempts
);
4665 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4666 SCTP_U32(SCTP_ERROR_NO_ERROR
));
4667 return SCTP_DISPOSITION_DELETE_TCB
;
4670 return SCTP_DISPOSITION_CONSUME
;
4674 * sctp_sf_t1_cookie_timer_expire
4676 * Section: 4 Note: 2
4681 * RFC 2960 Section 4 Notes
4682 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
4683 * COOKIE ECHO and re-start the T1-cookie timer without changing
4684 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
4685 * After that, the endpoint MUST abort the initialization process and
4686 * report the error to SCTP user.
4692 sctp_disposition_t
sctp_sf_t1_cookie_timer_expire(const struct sctp_endpoint
*ep
,
4693 const struct sctp_association
*asoc
,
4694 const sctp_subtype_t type
,
4696 sctp_cmd_seq_t
*commands
)
4698 struct sctp_chunk
*repl
= NULL
;
4699 int attempts
= asoc
->init_err_counter
+ 1;
4701 SCTP_DEBUG_PRINTK("Timer T1 expired (COOKIE-ECHO).\n");
4703 if (attempts
<= asoc
->max_init_attempts
) {
4704 repl
= sctp_make_cookie_echo(asoc
, NULL
);
4706 return SCTP_DISPOSITION_NOMEM
;
4708 /* Issue a sideeffect to do the needed accounting. */
4709 sctp_add_cmd_sf(commands
, SCTP_CMD_COOKIEECHO_RESTART
,
4710 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
4712 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
4714 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4715 SCTP_U32(SCTP_ERROR_NO_ERROR
));
4716 return SCTP_DISPOSITION_DELETE_TCB
;
4719 return SCTP_DISPOSITION_CONSUME
;
4722 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
4723 * with the updated last sequential TSN received from its peer.
4725 * An endpoint should limit the number of retransmissions of the
4726 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
4727 * If this threshold is exceeded the endpoint should destroy the TCB and
4728 * MUST report the peer endpoint unreachable to the upper layer (and
4729 * thus the association enters the CLOSED state). The reception of any
4730 * packet from its peer (i.e. as the peer sends all of its queued DATA
4731 * chunks) should clear the endpoint's retransmission count and restart
4732 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
4733 * all of its queued DATA chunks that have not yet been sent.
4735 sctp_disposition_t
sctp_sf_t2_timer_expire(const struct sctp_endpoint
*ep
,
4736 const struct sctp_association
*asoc
,
4737 const sctp_subtype_t type
,
4739 sctp_cmd_seq_t
*commands
)
4741 struct sctp_chunk
*reply
= NULL
;
4743 SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
4744 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
4745 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
4746 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4747 SCTP_U32(SCTP_ERROR_NO_ERROR
));
4748 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4749 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
4750 return SCTP_DISPOSITION_DELETE_TCB
;
4753 switch (asoc
->state
) {
4754 case SCTP_STATE_SHUTDOWN_SENT
:
4755 reply
= sctp_make_shutdown(asoc
, NULL
);
4758 case SCTP_STATE_SHUTDOWN_ACK_SENT
:
4759 reply
= sctp_make_shutdown_ack(asoc
, NULL
);
4770 /* Do some failure management (Section 8.2). */
4771 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
4772 SCTP_TRANSPORT(asoc
->shutdown_last_sent_to
));
4774 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
4775 * the T2-shutdown timer.
4777 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
4779 /* Restart the T2-shutdown timer. */
4780 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
4781 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
4782 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
4783 return SCTP_DISPOSITION_CONSUME
;
4786 return SCTP_DISPOSITION_NOMEM
;
4790 * ADDIP Section 4.1 ASCONF CHunk Procedures
4791 * If the T4 RTO timer expires the endpoint should do B1 to B5
4793 sctp_disposition_t
sctp_sf_t4_timer_expire(
4794 const struct sctp_endpoint
*ep
,
4795 const struct sctp_association
*asoc
,
4796 const sctp_subtype_t type
,
4798 sctp_cmd_seq_t
*commands
)
4800 struct sctp_chunk
*chunk
= asoc
->addip_last_asconf
;
4801 struct sctp_transport
*transport
= chunk
->transport
;
4803 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
4804 * detection on the appropriate destination address as defined in
4805 * RFC2960 [5] section 8.1 and 8.2.
4807 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
4809 /* Reconfig T4 timer and transport. */
4810 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
4812 /* ADDIP 4.1 B2) Increment the association error counters and perform
4813 * endpoint failure detection on the association as defined in
4814 * RFC2960 [5] section 8.1 and 8.2.
4815 * association error counter is incremented in SCTP_CMD_STRIKE.
4817 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
4818 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4819 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
4820 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4821 SCTP_U32(SCTP_ERROR_NO_ERROR
));
4822 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4823 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
4824 return SCTP_DISPOSITION_ABORT
;
4827 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
4828 * the ASCONF chunk was sent by doubling the RTO timer value.
4829 * This is done in SCTP_CMD_STRIKE.
4832 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
4833 * choose an alternate destination address (please refer to RFC2960
4834 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
4835 * chunk, it MUST be the same (including its serial number) as the last
4838 sctp_chunk_hold(asoc
->addip_last_asconf
);
4839 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4840 SCTP_CHUNK(asoc
->addip_last_asconf
));
4842 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
4843 * destination is selected, then the RTO used will be that of the new
4844 * destination address.
4846 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
4847 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
4849 return SCTP_DISPOSITION_CONSUME
;
4852 /* sctpimpguide-05 Section 2.12.2
4853 * The sender of the SHUTDOWN MAY also start an overall guard timer
4854 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4855 * At the expiration of this timer the sender SHOULD abort the association
4856 * by sending an ABORT chunk.
4858 sctp_disposition_t
sctp_sf_t5_timer_expire(const struct sctp_endpoint
*ep
,
4859 const struct sctp_association
*asoc
,
4860 const sctp_subtype_t type
,
4862 sctp_cmd_seq_t
*commands
)
4864 struct sctp_chunk
*reply
= NULL
;
4866 SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
4868 reply
= sctp_make_abort(asoc
, NULL
, 0);
4872 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
4873 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4874 SCTP_U32(SCTP_ERROR_NO_ERROR
));
4876 return SCTP_DISPOSITION_DELETE_TCB
;
4878 return SCTP_DISPOSITION_NOMEM
;
4881 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
4882 * the association is automatically closed by starting the shutdown process.
4883 * The work that needs to be done is same as when SHUTDOWN is initiated by
4884 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
4886 sctp_disposition_t
sctp_sf_autoclose_timer_expire(
4887 const struct sctp_endpoint
*ep
,
4888 const struct sctp_association
*asoc
,
4889 const sctp_subtype_t type
,
4891 sctp_cmd_seq_t
*commands
)
4895 /* From 9.2 Shutdown of an Association
4896 * Upon receipt of the SHUTDOWN primitive from its upper
4897 * layer, the endpoint enters SHUTDOWN-PENDING state and
4898 * remains there until all outstanding data has been
4899 * acknowledged by its peer. The endpoint accepts no new data
4900 * from its upper layer, but retransmits data to the far end
4901 * if necessary to fill gaps.
4903 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4904 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
4906 /* sctpimpguide-05 Section 2.12.2
4907 * The sender of the SHUTDOWN MAY also start an overall guard timer
4908 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4910 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4911 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
4912 disposition
= SCTP_DISPOSITION_CONSUME
;
4913 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
4914 disposition
= sctp_sf_do_9_2_start_shutdown(ep
, asoc
, type
,
4920 /*****************************************************************************
4921 * These are sa state functions which could apply to all types of events.
4922 ****************************************************************************/
4925 * This table entry is not implemented.
4928 * (endpoint, asoc, chunk)
4930 * The return value is the disposition of the chunk.
4932 sctp_disposition_t
sctp_sf_not_impl(const struct sctp_endpoint
*ep
,
4933 const struct sctp_association
*asoc
,
4934 const sctp_subtype_t type
,
4936 sctp_cmd_seq_t
*commands
)
4938 return SCTP_DISPOSITION_NOT_IMPL
;
4942 * This table entry represents a bug.
4945 * (endpoint, asoc, chunk)
4947 * The return value is the disposition of the chunk.
4949 sctp_disposition_t
sctp_sf_bug(const struct sctp_endpoint
*ep
,
4950 const struct sctp_association
*asoc
,
4951 const sctp_subtype_t type
,
4953 sctp_cmd_seq_t
*commands
)
4955 return SCTP_DISPOSITION_BUG
;
4959 * This table entry represents the firing of a timer in the wrong state.
4960 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
4961 * when the association is in the wrong state. This event should
4962 * be ignored, so as to prevent any rearming of the timer.
4965 * (endpoint, asoc, chunk)
4967 * The return value is the disposition of the chunk.
4969 sctp_disposition_t
sctp_sf_timer_ignore(const struct sctp_endpoint
*ep
,
4970 const struct sctp_association
*asoc
,
4971 const sctp_subtype_t type
,
4973 sctp_cmd_seq_t
*commands
)
4975 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type
.chunk
);
4976 return SCTP_DISPOSITION_CONSUME
;
4979 /********************************************************************
4980 * 2nd Level Abstractions
4981 ********************************************************************/
4983 /* Pull the SACK chunk based on the SACK header. */
4984 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
)
4986 struct sctp_sackhdr
*sack
;
4991 /* Protect ourselves from reading too far into
4992 * the skb from a bogus sender.
4994 sack
= (struct sctp_sackhdr
*) chunk
->skb
->data
;
4996 num_blocks
= ntohs(sack
->num_gap_ack_blocks
);
4997 num_dup_tsns
= ntohs(sack
->num_dup_tsns
);
4998 len
= sizeof(struct sctp_sackhdr
);
4999 len
+= (num_blocks
+ num_dup_tsns
) * sizeof(__u32
);
5000 if (len
> chunk
->skb
->len
)
5003 skb_pull(chunk
->skb
, len
);
5008 /* Create an ABORT packet to be sent as a response, with the specified
5011 static struct sctp_packet
*sctp_abort_pkt_new(const struct sctp_endpoint
*ep
,
5012 const struct sctp_association
*asoc
,
5013 struct sctp_chunk
*chunk
,
5014 const void *payload
,
5017 struct sctp_packet
*packet
;
5018 struct sctp_chunk
*abort
;
5020 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
5024 * The T bit will be set if the asoc is NULL.
5026 abort
= sctp_make_abort(asoc
, chunk
, paylen
);
5028 sctp_ootb_pkt_free(packet
);
5032 /* Reflect vtag if T-Bit is set */
5033 if (sctp_test_T_bit(abort
))
5034 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
5036 /* Add specified error causes, i.e., payload, to the
5039 sctp_addto_chunk(abort
, paylen
, payload
);
5041 /* Set the skb to the belonging sock for accounting. */
5042 abort
->skb
->sk
= ep
->base
.sk
;
5044 sctp_packet_append_chunk(packet
, abort
);
5051 /* Allocate a packet for responding in the OOTB conditions. */
5052 static struct sctp_packet
*sctp_ootb_pkt_new(const struct sctp_association
*asoc
,
5053 const struct sctp_chunk
*chunk
)
5055 struct sctp_packet
*packet
;
5056 struct sctp_transport
*transport
;
5061 /* Get the source and destination port from the inbound packet. */
5062 sport
= ntohs(chunk
->sctp_hdr
->dest
);
5063 dport
= ntohs(chunk
->sctp_hdr
->source
);
5065 /* The V-tag is going to be the same as the inbound packet if no
5066 * association exists, otherwise, use the peer's vtag.
5069 vtag
= asoc
->peer
.i
.init_tag
;
5071 /* Special case the INIT and stale COOKIE_ECHO as there is no
5074 switch(chunk
->chunk_hdr
->type
) {
5077 sctp_init_chunk_t
*init
;
5079 init
= (sctp_init_chunk_t
*)chunk
->chunk_hdr
;
5080 vtag
= ntohl(init
->init_hdr
.init_tag
);
5084 vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
5089 /* Make a transport for the bucket, Eliza... */
5090 transport
= sctp_transport_new(sctp_source(chunk
), GFP_ATOMIC
);
5094 /* Cache a route for the transport with the chunk's destination as
5095 * the source address.
5097 sctp_transport_route(transport
, (union sctp_addr
*)&chunk
->dest
,
5098 sctp_sk(sctp_get_ctl_sock()));
5100 packet
= sctp_packet_init(&transport
->packet
, transport
, sport
, dport
);
5101 packet
= sctp_packet_config(packet
, vtag
, 0);
5109 /* Free the packet allocated earlier for responding in the OOTB condition. */
5110 void sctp_ootb_pkt_free(struct sctp_packet
*packet
)
5112 sctp_transport_free(packet
->transport
);
5115 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
5116 static void sctp_send_stale_cookie_err(const struct sctp_endpoint
*ep
,
5117 const struct sctp_association
*asoc
,
5118 const struct sctp_chunk
*chunk
,
5119 sctp_cmd_seq_t
*commands
,
5120 struct sctp_chunk
*err_chunk
)
5122 struct sctp_packet
*packet
;
5125 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
5127 struct sctp_signed_cookie
*cookie
;
5129 /* Override the OOTB vtag from the cookie. */
5130 cookie
= chunk
->subh
.cookie_hdr
;
5131 packet
->vtag
= cookie
->c
.peer_vtag
;
5133 /* Set the skb to the belonging sock for accounting. */
5134 err_chunk
->skb
->sk
= ep
->base
.sk
;
5135 sctp_packet_append_chunk(packet
, err_chunk
);
5136 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
5137 SCTP_PACKET(packet
));
5138 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
5140 sctp_chunk_free (err_chunk
);
5145 /* Process a data chunk */
5146 static int sctp_eat_data(const struct sctp_association
*asoc
,
5147 struct sctp_chunk
*chunk
,
5148 sctp_cmd_seq_t
*commands
)
5150 sctp_datahdr_t
*data_hdr
;
5151 struct sctp_chunk
*err
;
5153 sctp_verb_t deliver
;
5157 struct sctp_tsnmap
*map
= (struct sctp_tsnmap
*)&asoc
->peer
.tsn_map
;
5158 struct sock
*sk
= asoc
->base
.sk
;
5159 int rcvbuf_over
= 0;
5161 data_hdr
= chunk
->subh
.data_hdr
= (sctp_datahdr_t
*)chunk
->skb
->data
;
5162 skb_pull(chunk
->skb
, sizeof(sctp_datahdr_t
));
5164 tsn
= ntohl(data_hdr
->tsn
);
5165 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn
);
5167 /* ASSERT: Now skb->data is really the user data. */
5170 * If we are established, and we have used up our receive buffer
5171 * memory, think about droping the frame.
5172 * Note that we have an opportunity to improve performance here.
5173 * If we accept one chunk from an skbuff, we have to keep all the
5174 * memory of that skbuff around until the chunk is read into user
5175 * space. Therefore, once we accept 1 chunk we may as well accept all
5176 * remaining chunks in the skbuff. The data_accepted flag helps us do
5179 if ((asoc
->state
== SCTP_STATE_ESTABLISHED
) && (!chunk
->data_accepted
)) {
5181 * If the receive buffer policy is 1, then each
5182 * association can allocate up to sk_rcvbuf bytes
5183 * otherwise, all the associations in aggregate
5184 * may allocate up to sk_rcvbuf bytes
5186 if (asoc
->ep
->rcvbuf_policy
)
5187 account_value
= atomic_read(&asoc
->rmem_alloc
);
5189 account_value
= atomic_read(&sk
->sk_rmem_alloc
);
5190 if (account_value
> sk
->sk_rcvbuf
) {
5192 * We need to make forward progress, even when we are
5193 * under memory pressure, so we always allow the
5194 * next tsn after the ctsn ack point to be accepted.
5195 * This lets us avoid deadlocks in which we have to
5196 * drop frames that would otherwise let us drain the
5199 if ((sctp_tsnmap_get_ctsn(map
) + 1) != tsn
)
5200 return SCTP_IERROR_IGNORE_TSN
;
5203 * We're going to accept the frame but we should renege
5204 * to make space for it. This will send us down that
5205 * path later in this function.
5211 /* Process ECN based congestion.
5213 * Since the chunk structure is reused for all chunks within
5214 * a packet, we use ecn_ce_done to track if we've already
5215 * done CE processing for this packet.
5217 * We need to do ECN processing even if we plan to discard the
5221 if (!chunk
->ecn_ce_done
) {
5223 chunk
->ecn_ce_done
= 1;
5225 af
= sctp_get_af_specific(
5226 ipver2af(chunk
->skb
->nh
.iph
->version
));
5228 if (af
&& af
->is_ce(chunk
->skb
) && asoc
->peer
.ecn_capable
) {
5229 /* Do real work as sideffect. */
5230 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_CE
,
5235 tmp
= sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
);
5237 /* The TSN is too high--silently discard the chunk and
5238 * count on it getting retransmitted later.
5240 return SCTP_IERROR_HIGH_TSN
;
5241 } else if (tmp
> 0) {
5242 /* This is a duplicate. Record it. */
5243 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_DUP
, SCTP_U32(tsn
));
5244 return SCTP_IERROR_DUP_TSN
;
5247 /* This is a new TSN. */
5249 /* Discard if there is no room in the receive window.
5250 * Actually, allow a little bit of overflow (up to a MTU).
5252 datalen
= ntohs(chunk
->chunk_hdr
->length
);
5253 datalen
-= sizeof(sctp_data_chunk_t
);
5255 deliver
= SCTP_CMD_CHUNK_ULP
;
5256 chunk
->data_accepted
= 1;
5258 /* Think about partial delivery. */
5259 if ((datalen
>= asoc
->rwnd
) && (!asoc
->ulpq
.pd_mode
)) {
5261 /* Even if we don't accept this chunk there is
5264 sctp_add_cmd_sf(commands
, SCTP_CMD_PART_DELIVER
, SCTP_NULL());
5267 /* Spill over rwnd a little bit. Note: While allowed, this spill over
5268 * seems a bit troublesome in that frag_point varies based on
5269 * PMTU. In cases, such as loopback, this might be a rather
5272 if (!asoc
->rwnd
|| asoc
->rwnd_over
||
5273 (datalen
> asoc
->rwnd
+ asoc
->frag_point
) ||
5276 /* If this is the next TSN, consider reneging to make
5277 * room. Note: Playing nice with a confused sender. A
5278 * malicious sender can still eat up all our buffer
5279 * space and in the future we may want to detect and
5280 * do more drastic reneging.
5282 if (sctp_tsnmap_has_gap(map
) &&
5283 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
5284 SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn
);
5285 deliver
= SCTP_CMD_RENEGE
;
5287 SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
5288 "rwnd: %d\n", tsn
, datalen
,
5290 return SCTP_IERROR_IGNORE_TSN
;
5295 * Section 3.3.10.9 No User Data (9)
5299 * No User Data: This error cause is returned to the originator of a
5300 * DATA chunk if a received DATA chunk has no user data.
5302 if (unlikely(0 == datalen
)) {
5303 err
= sctp_make_abort_no_data(asoc
, chunk
, tsn
);
5305 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5308 /* We are going to ABORT, so we might as well stop
5309 * processing the rest of the chunks in the packet.
5311 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
5312 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5313 SCTP_U32(SCTP_ERROR_NO_DATA
));
5314 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
5315 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
5316 return SCTP_IERROR_NO_DATA
;
5319 /* If definately accepting the DATA chunk, record its TSN, otherwise
5320 * wait for renege processing.
5322 if (SCTP_CMD_CHUNK_ULP
== deliver
)
5323 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_TSN
, SCTP_U32(tsn
));
5325 /* Note: Some chunks may get overcounted (if we drop) or overcounted
5326 * if we renege and the chunk arrives again.
5328 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_UNORDERED
)
5329 SCTP_INC_STATS(SCTP_MIB_INUNORDERCHUNKS
);
5331 SCTP_INC_STATS(SCTP_MIB_INORDERCHUNKS
);
5333 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
5335 * If an endpoint receive a DATA chunk with an invalid stream
5336 * identifier, it shall acknowledge the reception of the DATA chunk
5337 * following the normal procedure, immediately send an ERROR chunk
5338 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
5339 * and discard the DATA chunk.
5341 if (ntohs(data_hdr
->stream
) >= asoc
->c
.sinit_max_instreams
) {
5342 err
= sctp_make_op_error(asoc
, chunk
, SCTP_ERROR_INV_STRM
,
5344 sizeof(data_hdr
->stream
));
5346 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5348 return SCTP_IERROR_BAD_STREAM
;
5351 /* Send the data up to the user. Note: Schedule the
5352 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
5353 * chunk needs the updated rwnd.
5355 sctp_add_cmd_sf(commands
, deliver
, SCTP_CHUNK(chunk
));
5357 return SCTP_IERROR_NO_ERROR
;