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,
96 __be16 error, int sk_err,
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);
191 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
194 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
195 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
196 * not the chunk should be discarded. If the endpoint is in
197 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
198 * T2-shutdown timer and remove all knowledge of the
199 * association (and thus the association enters the CLOSED
202 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
203 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
205 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
206 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
208 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
209 SCTP_STATE(SCTP_STATE_CLOSED));
211 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
212 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
214 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
216 return SCTP_DISPOSITION_DELETE_TCB;
220 * Respond to a normal INIT chunk.
221 * We are the side that is being asked for an association.
223 * Section: 5.1 Normal Establishment of an Association, B
224 * B) "Z" shall respond immediately with an INIT ACK chunk. The
225 * destination IP address of the INIT ACK MUST be set to the source
226 * IP address of the INIT to which this INIT ACK is responding. In
227 * the response, besides filling in other parameters, "Z" must set the
228 * Verification Tag field to Tag_A, and also provide its own
229 * Verification Tag (Tag_Z) in the Initiate Tag field.
231 * Verification Tag: Must be 0.
234 * (endpoint, asoc, chunk)
237 * (asoc, reply_msg, msg_up, timers, counters)
239 * The return value is the disposition of the chunk.
241 sctp_disposition_t sctp_sf_do_5_1B_init(const struct sctp_endpoint *ep,
242 const struct sctp_association *asoc,
243 const sctp_subtype_t type,
245 sctp_cmd_seq_t *commands)
247 struct sctp_chunk *chunk = arg;
248 struct sctp_chunk *repl;
249 struct sctp_association *new_asoc;
250 struct sctp_chunk *err_chunk;
251 struct sctp_packet *packet;
252 sctp_unrecognized_param_t *unk_param;
257 * An endpoint MUST NOT bundle INIT, INIT ACK or
258 * SHUTDOWN COMPLETE with any other chunks.
261 * Furthermore, we require that the receiver of an INIT chunk MUST
262 * enforce these rules by silently discarding an arriving packet
263 * with an INIT chunk that is bundled with other chunks.
265 if (!chunk->singleton)
266 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
268 /* If the packet is an OOTB packet which is temporarily on the
269 * control endpoint, respond with an ABORT.
271 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
272 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
275 /* If the endpoint is not listening or if the number of associations
276 * on the TCP-style socket exceed the max backlog, respond with an
279 if (!sctp_sstate(sk, LISTENING) ||
280 (sctp_style(sk, TCP) &&
281 sk_acceptq_is_full(sk)))
282 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
284 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
287 if (chunk->sctp_hdr->vtag != 0)
288 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
290 /* Make sure that the INIT chunk has a valid length.
291 * Normally, this would cause an ABORT with a Protocol Violation
292 * error, but since we don't have an association, we'll
293 * just discard the packet.
295 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
296 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
298 /* Verify the INIT chunk before processing it. */
300 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
301 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
303 /* This chunk contains fatal error. It is to be discarded.
304 * Send an ABORT, with causes if there is any.
307 packet = sctp_abort_pkt_new(ep, asoc, arg,
308 (__u8 *)(err_chunk->chunk_hdr) +
309 sizeof(sctp_chunkhdr_t),
310 ntohs(err_chunk->chunk_hdr->length) -
311 sizeof(sctp_chunkhdr_t));
313 sctp_chunk_free(err_chunk);
316 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
317 SCTP_PACKET(packet));
318 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
319 return SCTP_DISPOSITION_CONSUME;
321 return SCTP_DISPOSITION_NOMEM;
324 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
329 /* Grab the INIT header. */
330 chunk->subh.init_hdr = (sctp_inithdr_t *)chunk->skb->data;
332 /* Tag the variable length parameters. */
333 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
335 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
339 /* The call, sctp_process_init(), can fail on memory allocation. */
340 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
342 (sctp_init_chunk_t *)chunk->chunk_hdr,
346 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
348 /* If there are errors need to be reported for unknown parameters,
349 * make sure to reserve enough room in the INIT ACK for them.
353 len = ntohs(err_chunk->chunk_hdr->length) -
354 sizeof(sctp_chunkhdr_t);
356 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
359 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
363 /* If there are errors need to be reported for unknown parameters,
364 * include them in the outgoing INIT ACK as "Unrecognized parameter"
368 /* Get the "Unrecognized parameter" parameter(s) out of the
369 * ERROR chunk generated by sctp_verify_init(). Since the
370 * error cause code for "unknown parameter" and the
371 * "Unrecognized parameter" type is the same, we can
372 * construct the parameters in INIT ACK by copying the
375 unk_param = (sctp_unrecognized_param_t *)
376 ((__u8 *)(err_chunk->chunk_hdr) +
377 sizeof(sctp_chunkhdr_t));
378 /* Replace the cause code with the "Unrecognized parameter"
381 sctp_addto_chunk(repl, len, unk_param);
382 sctp_chunk_free(err_chunk);
385 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
387 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
390 * Note: After sending out INIT ACK with the State Cookie parameter,
391 * "Z" MUST NOT allocate any resources, nor keep any states for the
392 * new association. Otherwise, "Z" will be vulnerable to resource
395 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
397 return SCTP_DISPOSITION_DELETE_TCB;
400 sctp_association_free(new_asoc);
403 sctp_chunk_free(err_chunk);
404 return SCTP_DISPOSITION_NOMEM;
408 * Respond to a normal INIT ACK chunk.
409 * We are the side that is initiating the association.
411 * Section: 5.1 Normal Establishment of an Association, C
412 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
413 * timer and leave COOKIE-WAIT state. "A" shall then send the State
414 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
415 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
417 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
418 * DATA chunks, but it MUST be the first chunk in the packet and
419 * until the COOKIE ACK is returned the sender MUST NOT send any
420 * other packets to the peer.
422 * Verification Tag: 3.3.3
423 * If the value of the Initiate Tag in a received INIT ACK chunk is
424 * found to be 0, the receiver MUST treat it as an error and close the
425 * association by transmitting an ABORT.
428 * (endpoint, asoc, chunk)
431 * (asoc, reply_msg, msg_up, timers, counters)
433 * The return value is the disposition of the chunk.
435 sctp_disposition_t sctp_sf_do_5_1C_ack(const struct sctp_endpoint *ep,
436 const struct sctp_association *asoc,
437 const sctp_subtype_t type,
439 sctp_cmd_seq_t *commands)
441 struct sctp_chunk *chunk = arg;
442 sctp_init_chunk_t *initchunk;
443 struct sctp_chunk *err_chunk;
444 struct sctp_packet *packet;
447 if (!sctp_vtag_verify(chunk, asoc))
448 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
450 /* Make sure that the INIT-ACK chunk has a valid length */
451 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_initack_chunk_t)))
452 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
455 * An endpoint MUST NOT bundle INIT, INIT ACK or
456 * SHUTDOWN COMPLETE with any other chunks.
458 if (!chunk->singleton)
459 return SCTP_DISPOSITION_VIOLATION;
461 /* Grab the INIT header. */
462 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
464 /* Verify the INIT chunk before processing it. */
466 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
467 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
470 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
472 /* This chunk contains fatal error. It is to be discarded.
473 * Send an ABORT, with causes if there is any.
476 packet = sctp_abort_pkt_new(ep, asoc, arg,
477 (__u8 *)(err_chunk->chunk_hdr) +
478 sizeof(sctp_chunkhdr_t),
479 ntohs(err_chunk->chunk_hdr->length) -
480 sizeof(sctp_chunkhdr_t));
482 sctp_chunk_free(err_chunk);
485 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
486 SCTP_PACKET(packet));
487 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
488 error = SCTP_ERROR_INV_PARAM;
490 error = SCTP_ERROR_NO_RESOURCE;
493 sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
494 error = SCTP_ERROR_INV_PARAM;
496 return sctp_stop_t1_and_abort(commands, error, ECONNREFUSED,
497 asoc, chunk->transport);
500 /* Tag the variable length parameters. Note that we never
501 * convert the parameters in an INIT chunk.
503 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
505 initchunk = (sctp_init_chunk_t *) chunk->chunk_hdr;
507 sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT,
508 SCTP_PEER_INIT(initchunk));
510 /* Reset init error count upon receipt of INIT-ACK. */
511 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
513 /* 5.1 C) "A" shall stop the T1-init timer and leave
514 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
515 * timer, and enter the COOKIE-ECHOED state.
517 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
518 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
519 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
520 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
521 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
522 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED));
524 /* 5.1 C) "A" shall then send the State Cookie received in the
525 * INIT ACK chunk in a COOKIE ECHO chunk, ...
527 /* If there is any errors to report, send the ERROR chunk generated
528 * for unknown parameters as well.
530 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO,
531 SCTP_CHUNK(err_chunk));
533 return SCTP_DISPOSITION_CONSUME;
536 return SCTP_DISPOSITION_NOMEM;
540 * Respond to a normal COOKIE ECHO chunk.
541 * We are the side that is being asked for an association.
543 * Section: 5.1 Normal Establishment of an Association, D
544 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
545 * with a COOKIE ACK chunk after building a TCB and moving to
546 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
547 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
548 * chunk MUST be the first chunk in the packet.
550 * IMPLEMENTATION NOTE: An implementation may choose to send the
551 * Communication Up notification to the SCTP user upon reception
552 * of a valid COOKIE ECHO chunk.
554 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
555 * D) Rules for packet carrying a COOKIE ECHO
557 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
558 * Initial Tag received in the INIT ACK.
560 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
563 * (endpoint, asoc, chunk)
566 * (asoc, reply_msg, msg_up, timers, counters)
568 * The return value is the disposition of the chunk.
570 sctp_disposition_t sctp_sf_do_5_1D_ce(const struct sctp_endpoint *ep,
571 const struct sctp_association *asoc,
572 const sctp_subtype_t type, void *arg,
573 sctp_cmd_seq_t *commands)
575 struct sctp_chunk *chunk = arg;
576 struct sctp_association *new_asoc;
577 sctp_init_chunk_t *peer_init;
578 struct sctp_chunk *repl;
579 struct sctp_ulpevent *ev, *ai_ev = NULL;
581 struct sctp_chunk *err_chk_p;
583 /* If the packet is an OOTB packet which is temporarily on the
584 * control endpoint, respond with an ABORT.
586 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
587 return sctp_sf_ootb(ep, asoc, type, arg, commands);
589 /* Make sure that the COOKIE_ECHO chunk has a valid length.
590 * In this case, we check that we have enough for at least a
591 * chunk header. More detailed verification is done
592 * in sctp_unpack_cookie().
594 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
595 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
597 /* "Decode" the chunk. We have no optional parameters so we
600 chunk->subh.cookie_hdr =
601 (struct sctp_signed_cookie *)chunk->skb->data;
602 if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
603 sizeof(sctp_chunkhdr_t)))
606 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
607 * "Z" will reply with a COOKIE ACK chunk after building a TCB
608 * and moving to the ESTABLISHED state.
610 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
614 * If the re-build failed, what is the proper error path
617 * [We should abort the association. --piggy]
620 /* FIXME: Several errors are possible. A bad cookie should
621 * be silently discarded, but think about logging it too.
624 case -SCTP_IERROR_NOMEM:
627 case -SCTP_IERROR_STALE_COOKIE:
628 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
630 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
632 case -SCTP_IERROR_BAD_SIG:
634 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
639 /* Delay state machine commands until later.
641 * Re-build the bind address for the association is done in
642 * the sctp_unpack_cookie() already.
644 /* This is a brand-new association, so these are not yet side
645 * effects--it is safe to run them here.
647 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
649 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
650 &chunk->subh.cookie_hdr->c.peer_addr,
651 peer_init, GFP_ATOMIC))
654 repl = sctp_make_cookie_ack(new_asoc, chunk);
658 /* RFC 2960 5.1 Normal Establishment of an Association
660 * D) IMPLEMENTATION NOTE: An implementation may choose to
661 * send the Communication Up notification to the SCTP user
662 * upon reception of a valid COOKIE ECHO chunk.
664 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0,
665 new_asoc->c.sinit_num_ostreams,
666 new_asoc->c.sinit_max_instreams,
671 /* Sockets API Draft Section 5.3.1.6
672 * When a peer sends a Adaptation Layer Indication parameter , SCTP
673 * delivers this notification to inform the application that of the
674 * peers requested adaptation layer.
676 if (new_asoc->peer.adaptation_ind) {
677 ai_ev = sctp_ulpevent_make_adaptation_indication(new_asoc,
683 /* Add all the state machine commands now since we've created
684 * everything. This way we don't introduce memory corruptions
685 * during side-effect processing and correclty count established
688 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
689 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
690 SCTP_STATE(SCTP_STATE_ESTABLISHED));
691 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
692 SCTP_INC_STATS(SCTP_MIB_PASSIVEESTABS);
693 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
695 if (new_asoc->autoclose)
696 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
697 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
699 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
701 /* This will send the COOKIE ACK */
702 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
704 /* Queue the ASSOC_CHANGE event */
705 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
707 /* Send up the Adaptation Layer Indication event */
709 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
710 SCTP_ULPEVENT(ai_ev));
712 return SCTP_DISPOSITION_CONSUME;
715 sctp_ulpevent_free(ev);
717 sctp_chunk_free(repl);
719 sctp_association_free(new_asoc);
721 return SCTP_DISPOSITION_NOMEM;
725 * Respond to a normal COOKIE ACK chunk.
726 * We are the side that is being asked for an association.
728 * RFC 2960 5.1 Normal Establishment of an Association
730 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
731 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
732 * timer. It may also notify its ULP about the successful
733 * establishment of the association with a Communication Up
734 * notification (see Section 10).
738 * (endpoint, asoc, chunk)
741 * (asoc, reply_msg, msg_up, timers, counters)
743 * The return value is the disposition of the chunk.
745 sctp_disposition_t sctp_sf_do_5_1E_ca(const struct sctp_endpoint *ep,
746 const struct sctp_association *asoc,
747 const sctp_subtype_t type, void *arg,
748 sctp_cmd_seq_t *commands)
750 struct sctp_chunk *chunk = arg;
751 struct sctp_ulpevent *ev;
753 if (!sctp_vtag_verify(chunk, asoc))
754 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
756 /* Verify that the chunk length for the COOKIE-ACK is OK.
757 * If we don't do this, any bundled chunks may be junked.
759 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
760 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
763 /* Reset init error count upon receipt of COOKIE-ACK,
764 * to avoid problems with the managemement of this
765 * counter in stale cookie situations when a transition back
766 * from the COOKIE-ECHOED state to the COOKIE-WAIT
767 * state is performed.
769 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
771 /* RFC 2960 5.1 Normal Establishment of an Association
773 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
774 * from the COOKIE-ECHOED state to the ESTABLISHED state,
775 * stopping the T1-cookie timer.
777 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
778 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
779 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
780 SCTP_STATE(SCTP_STATE_ESTABLISHED));
781 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
782 SCTP_INC_STATS(SCTP_MIB_ACTIVEESTABS);
783 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
785 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
786 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
787 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
789 /* It may also notify its ULP about the successful
790 * establishment of the association with a Communication Up
791 * notification (see Section 10).
793 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP,
794 0, asoc->c.sinit_num_ostreams,
795 asoc->c.sinit_max_instreams,
801 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
803 /* Sockets API Draft Section 5.3.1.6
804 * When a peer sends a Adaptation Layer Indication parameter , SCTP
805 * delivers this notification to inform the application that of the
806 * peers requested adaptation layer.
808 if (asoc->peer.adaptation_ind) {
809 ev = sctp_ulpevent_make_adaptation_indication(asoc, GFP_ATOMIC);
813 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
817 return SCTP_DISPOSITION_CONSUME;
819 return SCTP_DISPOSITION_NOMEM;
822 /* Generate and sendout a heartbeat packet. */
823 static sctp_disposition_t sctp_sf_heartbeat(const struct sctp_endpoint *ep,
824 const struct sctp_association *asoc,
825 const sctp_subtype_t type,
827 sctp_cmd_seq_t *commands)
829 struct sctp_transport *transport = (struct sctp_transport *) arg;
830 struct sctp_chunk *reply;
831 sctp_sender_hb_info_t hbinfo;
834 hbinfo.param_hdr.type = SCTP_PARAM_HEARTBEAT_INFO;
835 hbinfo.param_hdr.length = htons(sizeof(sctp_sender_hb_info_t));
836 hbinfo.daddr = transport->ipaddr;
837 hbinfo.sent_at = jiffies;
838 hbinfo.hb_nonce = transport->hb_nonce;
840 /* Send a heartbeat to our peer. */
841 paylen = sizeof(sctp_sender_hb_info_t);
842 reply = sctp_make_heartbeat(asoc, transport, &hbinfo, paylen);
844 return SCTP_DISPOSITION_NOMEM;
846 /* Set rto_pending indicating that an RTT measurement
847 * is started with this heartbeat chunk.
849 sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING,
850 SCTP_TRANSPORT(transport));
852 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
853 return SCTP_DISPOSITION_CONSUME;
856 /* Generate a HEARTBEAT packet on the given transport. */
857 sctp_disposition_t sctp_sf_sendbeat_8_3(const struct sctp_endpoint *ep,
858 const struct sctp_association *asoc,
859 const sctp_subtype_t type,
861 sctp_cmd_seq_t *commands)
863 struct sctp_transport *transport = (struct sctp_transport *) arg;
865 if (asoc->overall_error_count >= asoc->max_retrans) {
866 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
867 SCTP_ERROR(ETIMEDOUT));
868 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
869 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
870 SCTP_PERR(SCTP_ERROR_NO_ERROR));
871 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
872 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
873 return SCTP_DISPOSITION_DELETE_TCB;
877 * The Sender-specific Heartbeat Info field should normally include
878 * information about the sender's current time when this HEARTBEAT
879 * chunk is sent and the destination transport address to which this
880 * HEARTBEAT is sent (see Section 8.3).
883 if (transport->param_flags & SPP_HB_ENABLE) {
884 if (SCTP_DISPOSITION_NOMEM ==
885 sctp_sf_heartbeat(ep, asoc, type, arg,
887 return SCTP_DISPOSITION_NOMEM;
888 /* Set transport error counter and association error counter
889 * when sending heartbeat.
891 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET,
892 SCTP_TRANSPORT(transport));
894 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE,
895 SCTP_TRANSPORT(transport));
897 return SCTP_DISPOSITION_CONSUME;
901 * Process an heartbeat request.
903 * Section: 8.3 Path Heartbeat
904 * The receiver of the HEARTBEAT should immediately respond with a
905 * HEARTBEAT ACK that contains the Heartbeat Information field copied
906 * from the received HEARTBEAT chunk.
908 * Verification Tag: 8.5 Verification Tag [Normal verification]
909 * When receiving an SCTP packet, the endpoint MUST ensure that the
910 * value in the Verification Tag field of the received SCTP packet
911 * matches its own Tag. If the received Verification Tag value does not
912 * match the receiver's own tag value, the receiver shall silently
913 * discard the packet and shall not process it any further except for
914 * those cases listed in Section 8.5.1 below.
917 * (endpoint, asoc, chunk)
920 * (asoc, reply_msg, msg_up, timers, counters)
922 * The return value is the disposition of the chunk.
924 sctp_disposition_t sctp_sf_beat_8_3(const struct sctp_endpoint *ep,
925 const struct sctp_association *asoc,
926 const sctp_subtype_t type,
928 sctp_cmd_seq_t *commands)
930 struct sctp_chunk *chunk = arg;
931 struct sctp_chunk *reply;
934 if (!sctp_vtag_verify(chunk, asoc))
935 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
937 /* Make sure that the HEARTBEAT chunk has a valid length. */
938 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t)))
939 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
942 /* 8.3 The receiver of the HEARTBEAT should immediately
943 * respond with a HEARTBEAT ACK that contains the Heartbeat
944 * Information field copied from the received HEARTBEAT chunk.
946 chunk->subh.hb_hdr = (sctp_heartbeathdr_t *) chunk->skb->data;
947 paylen = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t);
948 if (!pskb_pull(chunk->skb, paylen))
951 reply = sctp_make_heartbeat_ack(asoc, chunk,
952 chunk->subh.hb_hdr, paylen);
956 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
957 return SCTP_DISPOSITION_CONSUME;
960 return SCTP_DISPOSITION_NOMEM;
964 * Process the returning HEARTBEAT ACK.
966 * Section: 8.3 Path Heartbeat
967 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
968 * should clear the error counter of the destination transport
969 * address to which the HEARTBEAT was sent, and mark the destination
970 * transport address as active if it is not so marked. The endpoint may
971 * optionally report to the upper layer when an inactive destination
972 * address is marked as active due to the reception of the latest
973 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
974 * clear the association overall error count as well (as defined
977 * The receiver of the HEARTBEAT ACK should also perform an RTT
978 * measurement for that destination transport address using the time
979 * value carried in the HEARTBEAT ACK chunk.
981 * Verification Tag: 8.5 Verification Tag [Normal verification]
984 * (endpoint, asoc, chunk)
987 * (asoc, reply_msg, msg_up, timers, counters)
989 * The return value is the disposition of the chunk.
991 sctp_disposition_t sctp_sf_backbeat_8_3(const struct sctp_endpoint *ep,
992 const struct sctp_association *asoc,
993 const sctp_subtype_t type,
995 sctp_cmd_seq_t *commands)
997 struct sctp_chunk *chunk = arg;
998 union sctp_addr from_addr;
999 struct sctp_transport *link;
1000 sctp_sender_hb_info_t *hbinfo;
1001 unsigned long max_interval;
1003 if (!sctp_vtag_verify(chunk, asoc))
1004 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1006 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1007 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t)))
1008 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1011 hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data;
1012 /* Make sure that the length of the parameter is what we expect */
1013 if (ntohs(hbinfo->param_hdr.length) !=
1014 sizeof(sctp_sender_hb_info_t)) {
1015 return SCTP_DISPOSITION_DISCARD;
1018 from_addr = hbinfo->daddr;
1019 link = sctp_assoc_lookup_paddr(asoc, &from_addr);
1021 /* This should never happen, but lets log it if so. */
1022 if (unlikely(!link)) {
1023 if (from_addr.sa.sa_family == AF_INET6) {
1025 "%s association %p could not find address "
1029 NIP6(from_addr.v6.sin6_addr));
1032 "%s association %p could not find address "
1036 NIPQUAD(from_addr.v4.sin_addr.s_addr));
1038 return SCTP_DISPOSITION_DISCARD;
1041 /* Validate the 64-bit random nonce. */
1042 if (hbinfo->hb_nonce != link->hb_nonce)
1043 return SCTP_DISPOSITION_DISCARD;
1045 max_interval = link->hbinterval + link->rto;
1047 /* Check if the timestamp looks valid. */
1048 if (time_after(hbinfo->sent_at, jiffies) ||
1049 time_after(jiffies, hbinfo->sent_at + max_interval)) {
1050 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp"
1051 "received for transport: %p\n",
1052 __FUNCTION__, link);
1053 return SCTP_DISPOSITION_DISCARD;
1056 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1057 * the HEARTBEAT should clear the error counter of the
1058 * destination transport address to which the HEARTBEAT was
1059 * sent and mark the destination transport address as active if
1060 * it is not so marked.
1062 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link));
1064 return SCTP_DISPOSITION_CONSUME;
1067 /* Helper function to send out an abort for the restart
1070 static int sctp_sf_send_restart_abort(union sctp_addr *ssa,
1071 struct sctp_chunk *init,
1072 sctp_cmd_seq_t *commands)
1075 struct sctp_packet *pkt;
1076 union sctp_addr_param *addrparm;
1077 struct sctp_errhdr *errhdr;
1078 struct sctp_endpoint *ep;
1079 char buffer[sizeof(struct sctp_errhdr)+sizeof(union sctp_addr_param)];
1080 struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family);
1082 /* Build the error on the stack. We are way to malloc crazy
1083 * throughout the code today.
1085 errhdr = (struct sctp_errhdr *)buffer;
1086 addrparm = (union sctp_addr_param *)errhdr->variable;
1088 /* Copy into a parm format. */
1089 len = af->to_addr_param(ssa, addrparm);
1090 len += sizeof(sctp_errhdr_t);
1092 errhdr->cause = SCTP_ERROR_RESTART;
1093 errhdr->length = htons(len);
1095 /* Assign to the control socket. */
1096 ep = sctp_sk((sctp_get_ctl_sock()))->ep;
1098 /* Association is NULL since this may be a restart attack and we
1099 * want to send back the attacker's vtag.
1101 pkt = sctp_abort_pkt_new(ep, NULL, init, errhdr, len);
1105 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt));
1107 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1109 /* Discard the rest of the inbound packet. */
1110 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
1113 /* Even if there is no memory, treat as a failure so
1114 * the packet will get dropped.
1119 /* A restart is occurring, check to make sure no new addresses
1120 * are being added as we may be under a takeover attack.
1122 static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc,
1123 const struct sctp_association *asoc,
1124 struct sctp_chunk *init,
1125 sctp_cmd_seq_t *commands)
1127 struct sctp_transport *new_addr, *addr;
1128 struct list_head *pos, *pos2;
1131 /* Implementor's Guide - Sectin 5.2.2
1133 * Before responding the endpoint MUST check to see if the
1134 * unexpected INIT adds new addresses to the association. If new
1135 * addresses are added to the association, the endpoint MUST respond
1139 /* Search through all current addresses and make sure
1140 * we aren't adding any new ones.
1145 list_for_each(pos, &new_asoc->peer.transport_addr_list) {
1146 new_addr = list_entry(pos, struct sctp_transport, transports);
1148 list_for_each(pos2, &asoc->peer.transport_addr_list) {
1149 addr = list_entry(pos2, struct sctp_transport,
1151 if (sctp_cmp_addr_exact(&new_addr->ipaddr,
1161 /* If a new address was added, ABORT the sender. */
1162 if (!found && new_addr) {
1163 sctp_sf_send_restart_abort(&new_addr->ipaddr, init, commands);
1166 /* Return success if all addresses were found. */
1170 /* Populate the verification/tie tags based on overlapping INIT
1173 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1175 static void sctp_tietags_populate(struct sctp_association *new_asoc,
1176 const struct sctp_association *asoc)
1178 switch (asoc->state) {
1180 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1182 case SCTP_STATE_COOKIE_WAIT:
1183 new_asoc->c.my_vtag = asoc->c.my_vtag;
1184 new_asoc->c.my_ttag = asoc->c.my_vtag;
1185 new_asoc->c.peer_ttag = 0;
1188 case SCTP_STATE_COOKIE_ECHOED:
1189 new_asoc->c.my_vtag = asoc->c.my_vtag;
1190 new_asoc->c.my_ttag = asoc->c.my_vtag;
1191 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1194 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1195 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1198 new_asoc->c.my_ttag = asoc->c.my_vtag;
1199 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1203 /* Other parameters for the endpoint SHOULD be copied from the
1204 * existing parameters of the association (e.g. number of
1205 * outbound streams) into the INIT ACK and cookie.
1207 new_asoc->rwnd = asoc->rwnd;
1208 new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams;
1209 new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams;
1210 new_asoc->c.initial_tsn = asoc->c.initial_tsn;
1214 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1217 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1219 * Returns value representing action to be taken. These action values
1220 * correspond to Action/Description values in RFC 2960, Table 2.
1222 static char sctp_tietags_compare(struct sctp_association *new_asoc,
1223 const struct sctp_association *asoc)
1225 /* In this case, the peer may have restarted. */
1226 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1227 (asoc->c.peer_vtag != new_asoc->c.peer_vtag) &&
1228 (asoc->c.my_vtag == new_asoc->c.my_ttag) &&
1229 (asoc->c.peer_vtag == new_asoc->c.peer_ttag))
1232 /* Collision case B. */
1233 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1234 ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) ||
1235 (0 == asoc->c.peer_vtag))) {
1239 /* Collision case D. */
1240 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1241 (asoc->c.peer_vtag == new_asoc->c.peer_vtag))
1244 /* Collision case C. */
1245 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1246 (asoc->c.peer_vtag == new_asoc->c.peer_vtag) &&
1247 (0 == new_asoc->c.my_ttag) &&
1248 (0 == new_asoc->c.peer_ttag))
1251 /* No match to any of the special cases; discard this packet. */
1255 /* Common helper routine for both duplicate and simulataneous INIT
1258 static sctp_disposition_t sctp_sf_do_unexpected_init(
1259 const struct sctp_endpoint *ep,
1260 const struct sctp_association *asoc,
1261 const sctp_subtype_t type,
1262 void *arg, sctp_cmd_seq_t *commands)
1264 sctp_disposition_t retval;
1265 struct sctp_chunk *chunk = arg;
1266 struct sctp_chunk *repl;
1267 struct sctp_association *new_asoc;
1268 struct sctp_chunk *err_chunk;
1269 struct sctp_packet *packet;
1270 sctp_unrecognized_param_t *unk_param;
1274 * An endpoint MUST NOT bundle INIT, INIT ACK or
1275 * SHUTDOWN COMPLETE with any other chunks.
1278 * Furthermore, we require that the receiver of an INIT chunk MUST
1279 * enforce these rules by silently discarding an arriving packet
1280 * with an INIT chunk that is bundled with other chunks.
1282 if (!chunk->singleton)
1283 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1285 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1288 if (chunk->sctp_hdr->vtag != 0)
1289 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
1291 /* Make sure that the INIT chunk has a valid length.
1292 * In this case, we generate a protocol violation since we have
1293 * an association established.
1295 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
1296 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1298 /* Grab the INIT header. */
1299 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
1301 /* Tag the variable length parameters. */
1302 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
1304 /* Verify the INIT chunk before processing it. */
1306 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
1307 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
1309 /* This chunk contains fatal error. It is to be discarded.
1310 * Send an ABORT, with causes if there is any.
1313 packet = sctp_abort_pkt_new(ep, asoc, arg,
1314 (__u8 *)(err_chunk->chunk_hdr) +
1315 sizeof(sctp_chunkhdr_t),
1316 ntohs(err_chunk->chunk_hdr->length) -
1317 sizeof(sctp_chunkhdr_t));
1320 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
1321 SCTP_PACKET(packet));
1322 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1323 retval = SCTP_DISPOSITION_CONSUME;
1325 retval = SCTP_DISPOSITION_NOMEM;
1329 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
1335 * Other parameters for the endpoint SHOULD be copied from the
1336 * existing parameters of the association (e.g. number of
1337 * outbound streams) into the INIT ACK and cookie.
1338 * FIXME: We are copying parameters from the endpoint not the
1341 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
1345 /* In the outbound INIT ACK the endpoint MUST copy its current
1346 * Verification Tag and Peers Verification tag into a reserved
1347 * place (local tie-tag and per tie-tag) within the state cookie.
1349 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1351 (sctp_init_chunk_t *)chunk->chunk_hdr,
1355 /* Make sure no new addresses are being added during the
1356 * restart. Do not do this check for COOKIE-WAIT state,
1357 * since there are no peer addresses to check against.
1358 * Upon return an ABORT will have been sent if needed.
1360 if (!sctp_state(asoc, COOKIE_WAIT)) {
1361 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
1363 retval = SCTP_DISPOSITION_CONSUME;
1368 sctp_tietags_populate(new_asoc, asoc);
1370 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1372 /* If there are errors need to be reported for unknown parameters,
1373 * make sure to reserve enough room in the INIT ACK for them.
1377 len = ntohs(err_chunk->chunk_hdr->length) -
1378 sizeof(sctp_chunkhdr_t);
1381 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
1384 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
1388 /* If there are errors need to be reported for unknown parameters,
1389 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1393 /* Get the "Unrecognized parameter" parameter(s) out of the
1394 * ERROR chunk generated by sctp_verify_init(). Since the
1395 * error cause code for "unknown parameter" and the
1396 * "Unrecognized parameter" type is the same, we can
1397 * construct the parameters in INIT ACK by copying the
1398 * ERROR causes over.
1400 unk_param = (sctp_unrecognized_param_t *)
1401 ((__u8 *)(err_chunk->chunk_hdr) +
1402 sizeof(sctp_chunkhdr_t));
1403 /* Replace the cause code with the "Unrecognized parameter"
1406 sctp_addto_chunk(repl, len, unk_param);
1409 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1410 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1413 * Note: After sending out INIT ACK with the State Cookie parameter,
1414 * "Z" MUST NOT allocate any resources for this new association.
1415 * Otherwise, "Z" will be vulnerable to resource attacks.
1417 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1418 retval = SCTP_DISPOSITION_CONSUME;
1423 retval = SCTP_DISPOSITION_NOMEM;
1426 sctp_association_free(new_asoc);
1429 sctp_chunk_free(err_chunk);
1434 * Handle simultanous INIT.
1435 * This means we started an INIT and then we got an INIT request from
1438 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1439 * This usually indicates an initialization collision, i.e., each
1440 * endpoint is attempting, at about the same time, to establish an
1441 * association with the other endpoint.
1443 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1444 * endpoint MUST respond with an INIT ACK using the same parameters it
1445 * sent in its original INIT chunk (including its Verification Tag,
1446 * unchanged). These original parameters are combined with those from the
1447 * newly received INIT chunk. The endpoint shall also generate a State
1448 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1449 * INIT to calculate the State Cookie.
1451 * After that, the endpoint MUST NOT change its state, the T1-init
1452 * timer shall be left running and the corresponding TCB MUST NOT be
1453 * destroyed. The normal procedures for handling State Cookies when
1454 * a TCB exists will resolve the duplicate INITs to a single association.
1456 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1457 * its Tie-Tags with the Tag information of itself and its peer (see
1458 * section 5.2.2 for a description of the Tie-Tags).
1460 * Verification Tag: Not explicit, but an INIT can not have a valid
1461 * verification tag, so we skip the check.
1464 * (endpoint, asoc, chunk)
1467 * (asoc, reply_msg, msg_up, timers, counters)
1469 * The return value is the disposition of the chunk.
1471 sctp_disposition_t sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint *ep,
1472 const struct sctp_association *asoc,
1473 const sctp_subtype_t type,
1475 sctp_cmd_seq_t *commands)
1477 /* Call helper to do the real work for both simulataneous and
1478 * duplicate INIT chunk handling.
1480 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1484 * Handle duplicated INIT messages. These are usually delayed
1487 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1488 * COOKIE-ECHOED and COOKIE-WAIT
1490 * Unless otherwise stated, upon reception of an unexpected INIT for
1491 * this association, the endpoint shall generate an INIT ACK with a
1492 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1493 * current Verification Tag and peer's Verification Tag into a reserved
1494 * place within the state cookie. We shall refer to these locations as
1495 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1496 * containing this INIT ACK MUST carry a Verification Tag value equal to
1497 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1498 * MUST contain a new Initiation Tag (randomly generated see Section
1499 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1500 * existing parameters of the association (e.g. number of outbound
1501 * streams) into the INIT ACK and cookie.
1503 * After sending out the INIT ACK, the endpoint shall take no further
1504 * actions, i.e., the existing association, including its current state,
1505 * and the corresponding TCB MUST NOT be changed.
1507 * Note: Only when a TCB exists and the association is not in a COOKIE-
1508 * WAIT state are the Tie-Tags populated. For a normal association INIT
1509 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1510 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1511 * State Cookie are populated as specified in section 5.2.1.
1513 * Verification Tag: Not specified, but an INIT has no way of knowing
1514 * what the verification tag could be, so we ignore it.
1517 * (endpoint, asoc, chunk)
1520 * (asoc, reply_msg, msg_up, timers, counters)
1522 * The return value is the disposition of the chunk.
1524 sctp_disposition_t sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint *ep,
1525 const struct sctp_association *asoc,
1526 const sctp_subtype_t type,
1528 sctp_cmd_seq_t *commands)
1530 /* Call helper to do the real work for both simulataneous and
1531 * duplicate INIT chunk handling.
1533 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1538 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1541 * A) In this case, the peer may have restarted.
1543 static sctp_disposition_t sctp_sf_do_dupcook_a(const struct sctp_endpoint *ep,
1544 const struct sctp_association *asoc,
1545 struct sctp_chunk *chunk,
1546 sctp_cmd_seq_t *commands,
1547 struct sctp_association *new_asoc)
1549 sctp_init_chunk_t *peer_init;
1550 struct sctp_ulpevent *ev;
1551 struct sctp_chunk *repl;
1552 struct sctp_chunk *err;
1553 sctp_disposition_t disposition;
1555 /* new_asoc is a brand-new association, so these are not yet
1556 * side effects--it is safe to run them here.
1558 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1560 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1561 sctp_source(chunk), peer_init,
1565 /* Make sure no new addresses are being added during the
1566 * restart. Though this is a pretty complicated attack
1567 * since you'd have to get inside the cookie.
1569 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) {
1570 return SCTP_DISPOSITION_CONSUME;
1573 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1574 * the peer has restarted (Action A), it MUST NOT setup a new
1575 * association but instead resend the SHUTDOWN ACK and send an ERROR
1576 * chunk with a "Cookie Received while Shutting Down" error cause to
1579 if (sctp_state(asoc, SHUTDOWN_ACK_SENT)) {
1580 disposition = sctp_sf_do_9_2_reshutack(ep, asoc,
1581 SCTP_ST_CHUNK(chunk->chunk_hdr->type),
1583 if (SCTP_DISPOSITION_NOMEM == disposition)
1586 err = sctp_make_op_error(asoc, chunk,
1587 SCTP_ERROR_COOKIE_IN_SHUTDOWN,
1590 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1593 return SCTP_DISPOSITION_CONSUME;
1596 /* For now, fail any unsent/unacked data. Consider the optional
1597 * choice of resending of this data.
1599 sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL());
1601 repl = sctp_make_cookie_ack(new_asoc, chunk);
1605 /* Report association restart to upper layer. */
1606 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0,
1607 new_asoc->c.sinit_num_ostreams,
1608 new_asoc->c.sinit_max_instreams,
1613 /* Update the content of current association. */
1614 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1615 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1616 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1617 return SCTP_DISPOSITION_CONSUME;
1620 sctp_chunk_free(repl);
1622 return SCTP_DISPOSITION_NOMEM;
1625 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1628 * B) In this case, both sides may be attempting to start an association
1629 * at about the same time but the peer endpoint started its INIT
1630 * after responding to the local endpoint's INIT
1632 /* This case represents an initialization collision. */
1633 static sctp_disposition_t sctp_sf_do_dupcook_b(const struct sctp_endpoint *ep,
1634 const struct sctp_association *asoc,
1635 struct sctp_chunk *chunk,
1636 sctp_cmd_seq_t *commands,
1637 struct sctp_association *new_asoc)
1639 sctp_init_chunk_t *peer_init;
1640 struct sctp_ulpevent *ev;
1641 struct sctp_chunk *repl;
1643 /* new_asoc is a brand-new association, so these are not yet
1644 * side effects--it is safe to run them here.
1646 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1647 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1648 sctp_source(chunk), peer_init,
1652 /* Update the content of current association. */
1653 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1654 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1655 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1656 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
1657 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
1659 repl = sctp_make_cookie_ack(new_asoc, chunk);
1663 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1664 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1666 /* RFC 2960 5.1 Normal Establishment of an Association
1668 * D) IMPLEMENTATION NOTE: An implementation may choose to
1669 * send the Communication Up notification to the SCTP user
1670 * upon reception of a valid COOKIE ECHO chunk.
1672 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP, 0,
1673 new_asoc->c.sinit_num_ostreams,
1674 new_asoc->c.sinit_max_instreams,
1679 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1681 /* Sockets API Draft Section 5.3.1.6
1682 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1683 * delivers this notification to inform the application that of the
1684 * peers requested adaptation layer.
1686 if (asoc->peer.adaptation_ind) {
1687 ev = sctp_ulpevent_make_adaptation_indication(asoc, GFP_ATOMIC);
1691 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1695 return SCTP_DISPOSITION_CONSUME;
1698 sctp_chunk_free(repl);
1700 return SCTP_DISPOSITION_NOMEM;
1703 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1706 * C) In this case, the local endpoint's cookie has arrived late.
1707 * Before it arrived, the local endpoint sent an INIT and received an
1708 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1709 * but a new tag of its own.
1711 /* This case represents an initialization collision. */
1712 static sctp_disposition_t sctp_sf_do_dupcook_c(const struct sctp_endpoint *ep,
1713 const struct sctp_association *asoc,
1714 struct sctp_chunk *chunk,
1715 sctp_cmd_seq_t *commands,
1716 struct sctp_association *new_asoc)
1718 /* The cookie should be silently discarded.
1719 * The endpoint SHOULD NOT change states and should leave
1720 * any timers running.
1722 return SCTP_DISPOSITION_DISCARD;
1725 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1729 * D) When both local and remote tags match the endpoint should always
1730 * enter the ESTABLISHED state, if it has not already done so.
1732 /* This case represents an initialization collision. */
1733 static sctp_disposition_t sctp_sf_do_dupcook_d(const struct sctp_endpoint *ep,
1734 const struct sctp_association *asoc,
1735 struct sctp_chunk *chunk,
1736 sctp_cmd_seq_t *commands,
1737 struct sctp_association *new_asoc)
1739 struct sctp_ulpevent *ev = NULL, *ai_ev = NULL;
1740 struct sctp_chunk *repl;
1742 /* Clarification from Implementor's Guide:
1743 * D) When both local and remote tags match the endpoint should
1744 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1745 * It should stop any cookie timer that may be running and send
1749 /* Don't accidentally move back into established state. */
1750 if (asoc->state < SCTP_STATE_ESTABLISHED) {
1751 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1752 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
1753 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1754 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1755 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
1756 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START,
1759 /* RFC 2960 5.1 Normal Establishment of an Association
1761 * D) IMPLEMENTATION NOTE: An implementation may choose
1762 * to send the Communication Up notification to the
1763 * SCTP user upon reception of a valid COOKIE
1766 ev = sctp_ulpevent_make_assoc_change(asoc, 0,
1768 asoc->c.sinit_num_ostreams,
1769 asoc->c.sinit_max_instreams,
1774 /* Sockets API Draft Section 5.3.1.6
1775 * When a peer sends a Adaptation Layer Indication parameter,
1776 * SCTP delivers this notification to inform the application
1777 * that of the peers requested adaptation layer.
1779 if (asoc->peer.adaptation_ind) {
1780 ai_ev = sctp_ulpevent_make_adaptation_indication(asoc,
1787 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1789 repl = sctp_make_cookie_ack(new_asoc, chunk);
1794 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1797 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1798 SCTP_ULPEVENT(ai_ev));
1800 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1801 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1803 return SCTP_DISPOSITION_CONSUME;
1807 sctp_ulpevent_free(ai_ev);
1809 sctp_ulpevent_free(ev);
1810 return SCTP_DISPOSITION_NOMEM;
1814 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1815 * chunk was retransmitted and then delayed in the network.
1817 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1819 * Verification Tag: None. Do cookie validation.
1822 * (endpoint, asoc, chunk)
1825 * (asoc, reply_msg, msg_up, timers, counters)
1827 * The return value is the disposition of the chunk.
1829 sctp_disposition_t sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint *ep,
1830 const struct sctp_association *asoc,
1831 const sctp_subtype_t type,
1833 sctp_cmd_seq_t *commands)
1835 sctp_disposition_t retval;
1836 struct sctp_chunk *chunk = arg;
1837 struct sctp_association *new_asoc;
1840 struct sctp_chunk *err_chk_p;
1842 /* Make sure that the chunk has a valid length from the protocol
1843 * perspective. In this case check to make sure we have at least
1844 * enough for the chunk header. Cookie length verification is
1847 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
1848 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1851 /* "Decode" the chunk. We have no optional parameters so we
1852 * are in good shape.
1854 chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data;
1855 if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
1856 sizeof(sctp_chunkhdr_t)))
1859 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
1860 * of a duplicate COOKIE ECHO match the Verification Tags of the
1861 * current association, consider the State Cookie valid even if
1862 * the lifespan is exceeded.
1864 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
1868 * If the re-build failed, what is the proper error path
1871 * [We should abort the association. --piggy]
1874 /* FIXME: Several errors are possible. A bad cookie should
1875 * be silently discarded, but think about logging it too.
1878 case -SCTP_IERROR_NOMEM:
1881 case -SCTP_IERROR_STALE_COOKIE:
1882 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
1884 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1885 case -SCTP_IERROR_BAD_SIG:
1887 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1891 /* Compare the tie_tag in cookie with the verification tag of
1892 * current association.
1894 action = sctp_tietags_compare(new_asoc, asoc);
1897 case 'A': /* Association restart. */
1898 retval = sctp_sf_do_dupcook_a(ep, asoc, chunk, commands,
1902 case 'B': /* Collision case B. */
1903 retval = sctp_sf_do_dupcook_b(ep, asoc, chunk, commands,
1907 case 'C': /* Collision case C. */
1908 retval = sctp_sf_do_dupcook_c(ep, asoc, chunk, commands,
1912 case 'D': /* Collision case D. */
1913 retval = sctp_sf_do_dupcook_d(ep, asoc, chunk, commands,
1917 default: /* Discard packet for all others. */
1918 retval = sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1922 /* Delete the tempory new association. */
1923 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1924 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1929 return SCTP_DISPOSITION_NOMEM;
1933 * Process an ABORT. (SHUTDOWN-PENDING state)
1935 * See sctp_sf_do_9_1_abort().
1937 sctp_disposition_t sctp_sf_shutdown_pending_abort(
1938 const struct sctp_endpoint *ep,
1939 const struct sctp_association *asoc,
1940 const sctp_subtype_t type,
1942 sctp_cmd_seq_t *commands)
1944 struct sctp_chunk *chunk = arg;
1946 if (!sctp_vtag_verify_either(chunk, asoc))
1947 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1949 /* Make sure that the ABORT chunk has a valid length.
1950 * Since this is an ABORT chunk, we have to discard it
1951 * because of the following text:
1952 * RFC 2960, Section 3.3.7
1953 * If an endpoint receives an ABORT with a format error or for an
1954 * association that doesn't exist, it MUST silently discard it.
1955 * Becasue the length is "invalid", we can't really discard just
1956 * as we do not know its true length. So, to be safe, discard the
1959 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
1960 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1962 /* Stop the T5-shutdown guard timer. */
1963 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1964 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
1966 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
1970 * Process an ABORT. (SHUTDOWN-SENT state)
1972 * See sctp_sf_do_9_1_abort().
1974 sctp_disposition_t sctp_sf_shutdown_sent_abort(const struct sctp_endpoint *ep,
1975 const struct sctp_association *asoc,
1976 const sctp_subtype_t type,
1978 sctp_cmd_seq_t *commands)
1980 struct sctp_chunk *chunk = arg;
1982 if (!sctp_vtag_verify_either(chunk, asoc))
1983 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1985 /* Make sure that the ABORT chunk has a valid length.
1986 * Since this is an ABORT chunk, we have to discard it
1987 * because of the following text:
1988 * RFC 2960, Section 3.3.7
1989 * If an endpoint receives an ABORT with a format error or for an
1990 * association that doesn't exist, it MUST silently discard it.
1991 * Becasue the length is "invalid", we can't really discard just
1992 * as we do not know its true length. So, to be safe, discard the
1995 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
1996 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1998 /* Stop the T2-shutdown timer. */
1999 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2000 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2002 /* Stop the T5-shutdown guard timer. */
2003 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2004 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
2006 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
2010 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2012 * See sctp_sf_do_9_1_abort().
2014 sctp_disposition_t sctp_sf_shutdown_ack_sent_abort(
2015 const struct sctp_endpoint *ep,
2016 const struct sctp_association *asoc,
2017 const sctp_subtype_t type,
2019 sctp_cmd_seq_t *commands)
2021 /* The same T2 timer, so we should be able to use
2022 * common function with the SHUTDOWN-SENT state.
2024 return sctp_sf_shutdown_sent_abort(ep, asoc, type, arg, commands);
2028 * Handle an Error received in COOKIE_ECHOED state.
2030 * Only handle the error type of stale COOKIE Error, the other errors will
2034 * (endpoint, asoc, chunk)
2037 * (asoc, reply_msg, msg_up, timers, counters)
2039 * The return value is the disposition of the chunk.
2041 sctp_disposition_t sctp_sf_cookie_echoed_err(const struct sctp_endpoint *ep,
2042 const struct sctp_association *asoc,
2043 const sctp_subtype_t type,
2045 sctp_cmd_seq_t *commands)
2047 struct sctp_chunk *chunk = arg;
2050 if (!sctp_vtag_verify(chunk, asoc))
2051 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2053 /* Make sure that the ERROR chunk has a valid length.
2054 * The parameter walking depends on this as well.
2056 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t)))
2057 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2060 /* Process the error here */
2061 /* FUTURE FIXME: When PR-SCTP related and other optional
2062 * parms are emitted, this will have to change to handle multiple
2065 sctp_walk_errors(err, chunk->chunk_hdr) {
2066 if (SCTP_ERROR_STALE_COOKIE == err->cause)
2067 return sctp_sf_do_5_2_6_stale(ep, asoc, type,
2071 /* It is possible to have malformed error causes, and that
2072 * will cause us to end the walk early. However, since
2073 * we are discarding the packet, there should be no adverse
2076 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2080 * Handle a Stale COOKIE Error
2082 * Section: 5.2.6 Handle Stale COOKIE Error
2083 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2084 * one of the following three alternatives.
2086 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2087 * Preservative parameter requesting an extension to the lifetime of
2088 * the State Cookie. When calculating the time extension, an
2089 * implementation SHOULD use the RTT information measured based on the
2090 * previous COOKIE ECHO / ERROR exchange, and should add no more
2091 * than 1 second beyond the measured RTT, due to long State Cookie
2092 * lifetimes making the endpoint more subject to a replay attack.
2094 * Verification Tag: Not explicit, but safe to ignore.
2097 * (endpoint, asoc, chunk)
2100 * (asoc, reply_msg, msg_up, timers, counters)
2102 * The return value is the disposition of the chunk.
2104 static sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep,
2105 const struct sctp_association *asoc,
2106 const sctp_subtype_t type,
2108 sctp_cmd_seq_t *commands)
2110 struct sctp_chunk *chunk = arg;
2112 sctp_cookie_preserve_param_t bht;
2114 struct sctp_chunk *reply;
2115 struct sctp_bind_addr *bp;
2116 int attempts = asoc->init_err_counter + 1;
2118 if (attempts > asoc->max_init_attempts) {
2119 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
2120 SCTP_ERROR(ETIMEDOUT));
2121 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2122 SCTP_PERR(SCTP_ERROR_STALE_COOKIE));
2123 return SCTP_DISPOSITION_DELETE_TCB;
2126 err = (sctp_errhdr_t *)(chunk->skb->data);
2128 /* When calculating the time extension, an implementation
2129 * SHOULD use the RTT information measured based on the
2130 * previous COOKIE ECHO / ERROR exchange, and should add no
2131 * more than 1 second beyond the measured RTT, due to long
2132 * State Cookie lifetimes making the endpoint more subject to
2134 * Measure of Staleness's unit is usec. (1/1000000 sec)
2135 * Suggested Cookie Life-span Increment's unit is msec.
2137 * In general, if you use the suggested cookie life, the value
2138 * found in the field of measure of staleness should be doubled
2139 * to give ample time to retransmit the new cookie and thus
2140 * yield a higher probability of success on the reattempt.
2142 stale = ntohl(*(__be32 *)((u8 *)err + sizeof(sctp_errhdr_t)));
2143 stale = (stale * 2) / 1000;
2145 bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE;
2146 bht.param_hdr.length = htons(sizeof(bht));
2147 bht.lifespan_increment = htonl(stale);
2149 /* Build that new INIT chunk. */
2150 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
2151 reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht));
2155 sctp_addto_chunk(reply, sizeof(bht), &bht);
2157 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2158 sctp_add_cmd_sf(commands, SCTP_CMD_CLEAR_INIT_TAG, SCTP_NULL());
2160 /* Stop pending T3-rtx and heartbeat timers */
2161 sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL());
2162 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
2164 /* Delete non-primary peer ip addresses since we are transitioning
2165 * back to the COOKIE-WAIT state
2167 sctp_add_cmd_sf(commands, SCTP_CMD_DEL_NON_PRIMARY, SCTP_NULL());
2169 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2172 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN,
2173 SCTP_TRANSPORT(asoc->peer.primary_path));
2175 /* Cast away the const modifier, as we want to just
2176 * rerun it through as a sideffect.
2178 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_INC, SCTP_NULL());
2180 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2181 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
2182 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2183 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
2184 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
2185 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2187 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2189 return SCTP_DISPOSITION_CONSUME;
2192 return SCTP_DISPOSITION_NOMEM;
2199 * After checking the Verification Tag, the receiving endpoint shall
2200 * remove the association from its record, and shall report the
2201 * termination to its upper layer.
2203 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2204 * B) Rules for packet carrying ABORT:
2206 * - The endpoint shall always fill in the Verification Tag field of the
2207 * outbound packet with the destination endpoint's tag value if it
2210 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2211 * MUST follow the procedure described in Section 8.4.
2213 * - The receiver MUST accept the packet if the Verification Tag
2214 * matches either its own tag, OR the tag of its peer. Otherwise, the
2215 * receiver MUST silently discard the packet and take no further
2219 * (endpoint, asoc, chunk)
2222 * (asoc, reply_msg, msg_up, timers, counters)
2224 * The return value is the disposition of the chunk.
2226 sctp_disposition_t sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep,
2227 const struct sctp_association *asoc,
2228 const sctp_subtype_t type,
2230 sctp_cmd_seq_t *commands)
2232 struct sctp_chunk *chunk = arg;
2234 __be16 error = SCTP_ERROR_NO_ERROR;
2236 if (!sctp_vtag_verify_either(chunk, asoc))
2237 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2239 /* Make sure that the ABORT chunk has a valid length.
2240 * Since this is an ABORT chunk, we have to discard it
2241 * because of the following text:
2242 * RFC 2960, Section 3.3.7
2243 * If an endpoint receives an ABORT with a format error or for an
2244 * association that doesn't exist, it MUST silently discard it.
2245 * Becasue the length is "invalid", we can't really discard just
2246 * as we do not know its true length. So, to be safe, discard the
2249 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2250 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2252 /* See if we have an error cause code in the chunk. */
2253 len = ntohs(chunk->chunk_hdr->length);
2254 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2255 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2257 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNRESET));
2258 /* ASSOC_FAILED will DELETE_TCB. */
2259 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_PERR(error));
2260 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
2261 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
2263 return SCTP_DISPOSITION_ABORT;
2267 * Process an ABORT. (COOKIE-WAIT state)
2269 * See sctp_sf_do_9_1_abort() above.
2271 sctp_disposition_t sctp_sf_cookie_wait_abort(const struct sctp_endpoint *ep,
2272 const struct sctp_association *asoc,
2273 const sctp_subtype_t type,
2275 sctp_cmd_seq_t *commands)
2277 struct sctp_chunk *chunk = arg;
2279 __be16 error = SCTP_ERROR_NO_ERROR;
2281 if (!sctp_vtag_verify_either(chunk, asoc))
2282 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2284 /* Make sure that the ABORT chunk has a valid length.
2285 * Since this is an ABORT chunk, we have to discard it
2286 * because of the following text:
2287 * RFC 2960, Section 3.3.7
2288 * If an endpoint receives an ABORT with a format error or for an
2289 * association that doesn't exist, it MUST silently discard it.
2290 * Becasue the length is "invalid", we can't really discard just
2291 * as we do not know its true length. So, to be safe, discard the
2294 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2295 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2297 /* See if we have an error cause code in the chunk. */
2298 len = ntohs(chunk->chunk_hdr->length);
2299 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2300 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2302 return sctp_stop_t1_and_abort(commands, error, ECONNREFUSED, asoc,
2307 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2309 sctp_disposition_t sctp_sf_cookie_wait_icmp_abort(const struct sctp_endpoint *ep,
2310 const struct sctp_association *asoc,
2311 const sctp_subtype_t type,
2313 sctp_cmd_seq_t *commands)
2315 return sctp_stop_t1_and_abort(commands, SCTP_ERROR_NO_ERROR,
2317 (struct sctp_transport *)arg);
2321 * Process an ABORT. (COOKIE-ECHOED state)
2323 sctp_disposition_t sctp_sf_cookie_echoed_abort(const struct sctp_endpoint *ep,
2324 const struct sctp_association *asoc,
2325 const sctp_subtype_t type,
2327 sctp_cmd_seq_t *commands)
2329 /* There is a single T1 timer, so we should be able to use
2330 * common function with the COOKIE-WAIT state.
2332 return sctp_sf_cookie_wait_abort(ep, asoc, type, arg, commands);
2336 * Stop T1 timer and abort association with "INIT failed".
2338 * This is common code called by several sctp_sf_*_abort() functions above.
2340 static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands,
2341 __be16 error, int sk_err,
2342 const struct sctp_association *asoc,
2343 struct sctp_transport *transport)
2345 SCTP_DEBUG_PRINTK("ABORT received (INIT).\n");
2346 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2347 SCTP_STATE(SCTP_STATE_CLOSED));
2348 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
2349 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2350 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2351 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(sk_err));
2352 /* CMD_INIT_FAILED will DELETE_TCB. */
2353 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2355 return SCTP_DISPOSITION_ABORT;
2359 * sctp_sf_do_9_2_shut
2362 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2363 * - enter the SHUTDOWN-RECEIVED state,
2365 * - stop accepting new data from its SCTP user
2367 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2368 * that all its outstanding DATA chunks have been received by the
2371 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2372 * send a SHUTDOWN in response to a ULP request. And should discard
2373 * subsequent SHUTDOWN chunks.
2375 * If there are still outstanding DATA chunks left, the SHUTDOWN
2376 * receiver shall continue to follow normal data transmission
2377 * procedures defined in Section 6 until all outstanding DATA chunks
2378 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2379 * new data from its SCTP user.
2381 * Verification Tag: 8.5 Verification Tag [Normal verification]
2384 * (endpoint, asoc, chunk)
2387 * (asoc, reply_msg, msg_up, timers, counters)
2389 * The return value is the disposition of the chunk.
2391 sctp_disposition_t sctp_sf_do_9_2_shutdown(const struct sctp_endpoint *ep,
2392 const struct sctp_association *asoc,
2393 const sctp_subtype_t type,
2395 sctp_cmd_seq_t *commands)
2397 struct sctp_chunk *chunk = arg;
2398 sctp_shutdownhdr_t *sdh;
2399 sctp_disposition_t disposition;
2400 struct sctp_ulpevent *ev;
2402 if (!sctp_vtag_verify(chunk, asoc))
2403 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2405 /* Make sure that the SHUTDOWN chunk has a valid length. */
2406 if (!sctp_chunk_length_valid(chunk,
2407 sizeof(struct sctp_shutdown_chunk_t)))
2408 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2411 /* Convert the elaborate header. */
2412 sdh = (sctp_shutdownhdr_t *)chunk->skb->data;
2413 skb_pull(chunk->skb, sizeof(sctp_shutdownhdr_t));
2414 chunk->subh.shutdown_hdr = sdh;
2416 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2417 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2418 * inform the application that it should cease sending data.
2420 ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC);
2422 disposition = SCTP_DISPOSITION_NOMEM;
2425 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
2427 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2428 * - enter the SHUTDOWN-RECEIVED state,
2429 * - stop accepting new data from its SCTP user
2431 * [This is implicit in the new state.]
2433 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2434 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED));
2435 disposition = SCTP_DISPOSITION_CONSUME;
2437 if (sctp_outq_is_empty(&asoc->outqueue)) {
2438 disposition = sctp_sf_do_9_2_shutdown_ack(ep, asoc, type,
2442 if (SCTP_DISPOSITION_NOMEM == disposition)
2445 /* - verify, by checking the Cumulative TSN Ack field of the
2446 * chunk, that all its outstanding DATA chunks have been
2447 * received by the SHUTDOWN sender.
2449 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
2450 SCTP_BE32(chunk->subh.shutdown_hdr->cum_tsn_ack));
2457 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2458 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2459 * transport addresses (either in the IP addresses or in the INIT chunk)
2460 * that belong to this association, it should discard the INIT chunk and
2461 * retransmit the SHUTDOWN ACK chunk.
2463 sctp_disposition_t sctp_sf_do_9_2_reshutack(const struct sctp_endpoint *ep,
2464 const struct sctp_association *asoc,
2465 const sctp_subtype_t type,
2467 sctp_cmd_seq_t *commands)
2469 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
2470 struct sctp_chunk *reply;
2472 /* Since we are not going to really process this INIT, there
2473 * is no point in verifying chunk boundries. Just generate
2476 reply = sctp_make_shutdown_ack(asoc, chunk);
2480 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2481 * the T2-SHUTDOWN timer.
2483 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
2485 /* and restart the T2-shutdown timer. */
2486 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2487 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2489 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2491 return SCTP_DISPOSITION_CONSUME;
2493 return SCTP_DISPOSITION_NOMEM;
2497 * sctp_sf_do_ecn_cwr
2499 * Section: Appendix A: Explicit Congestion Notification
2503 * RFC 2481 details a specific bit for a sender to send in the header of
2504 * its next outbound TCP segment to indicate to its peer that it has
2505 * reduced its congestion window. This is termed the CWR bit. For
2506 * SCTP the same indication is made by including the CWR chunk.
2507 * This chunk contains one data element, i.e. the TSN number that
2508 * was sent in the ECNE chunk. This element represents the lowest
2509 * TSN number in the datagram that was originally marked with the
2512 * Verification Tag: 8.5 Verification Tag [Normal verification]
2514 * (endpoint, asoc, chunk)
2517 * (asoc, reply_msg, msg_up, timers, counters)
2519 * The return value is the disposition of the chunk.
2521 sctp_disposition_t sctp_sf_do_ecn_cwr(const struct sctp_endpoint *ep,
2522 const struct sctp_association *asoc,
2523 const sctp_subtype_t type,
2525 sctp_cmd_seq_t *commands)
2528 struct sctp_chunk *chunk = arg;
2531 if (!sctp_vtag_verify(chunk, asoc))
2532 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2534 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t)))
2535 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2538 cwr = (sctp_cwrhdr_t *) chunk->skb->data;
2539 skb_pull(chunk->skb, sizeof(sctp_cwrhdr_t));
2541 lowest_tsn = ntohl(cwr->lowest_tsn);
2543 /* Does this CWR ack the last sent congestion notification? */
2544 if (TSN_lte(asoc->last_ecne_tsn, lowest_tsn)) {
2545 /* Stop sending ECNE. */
2546 sctp_add_cmd_sf(commands,
2548 SCTP_U32(lowest_tsn));
2550 return SCTP_DISPOSITION_CONSUME;
2556 * Section: Appendix A: Explicit Congestion Notification
2560 * RFC 2481 details a specific bit for a receiver to send back in its
2561 * TCP acknowledgements to notify the sender of the Congestion
2562 * Experienced (CE) bit having arrived from the network. For SCTP this
2563 * same indication is made by including the ECNE chunk. This chunk
2564 * contains one data element, i.e. the lowest TSN associated with the IP
2565 * datagram marked with the CE bit.....
2567 * Verification Tag: 8.5 Verification Tag [Normal verification]
2569 * (endpoint, asoc, chunk)
2572 * (asoc, reply_msg, msg_up, timers, counters)
2574 * The return value is the disposition of the chunk.
2576 sctp_disposition_t sctp_sf_do_ecne(const struct sctp_endpoint *ep,
2577 const struct sctp_association *asoc,
2578 const sctp_subtype_t type,
2580 sctp_cmd_seq_t *commands)
2582 sctp_ecnehdr_t *ecne;
2583 struct sctp_chunk *chunk = arg;
2585 if (!sctp_vtag_verify(chunk, asoc))
2586 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2588 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t)))
2589 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2592 ecne = (sctp_ecnehdr_t *) chunk->skb->data;
2593 skb_pull(chunk->skb, sizeof(sctp_ecnehdr_t));
2595 /* If this is a newer ECNE than the last CWR packet we sent out */
2596 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE,
2597 SCTP_U32(ntohl(ecne->lowest_tsn)));
2599 return SCTP_DISPOSITION_CONSUME;
2603 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2605 * The SCTP endpoint MUST always acknowledge the reception of each valid
2608 * The guidelines on delayed acknowledgement algorithm specified in
2609 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2610 * acknowledgement SHOULD be generated for at least every second packet
2611 * (not every second DATA chunk) received, and SHOULD be generated within
2612 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2613 * situations it may be beneficial for an SCTP transmitter to be more
2614 * conservative than the algorithms detailed in this document allow.
2615 * However, an SCTP transmitter MUST NOT be more aggressive than the
2616 * following algorithms allow.
2618 * A SCTP receiver MUST NOT generate more than one SACK for every
2619 * incoming packet, other than to update the offered window as the
2620 * receiving application consumes new data.
2622 * Verification Tag: 8.5 Verification Tag [Normal verification]
2625 * (endpoint, asoc, chunk)
2628 * (asoc, reply_msg, msg_up, timers, counters)
2630 * The return value is the disposition of the chunk.
2632 sctp_disposition_t sctp_sf_eat_data_6_2(const struct sctp_endpoint *ep,
2633 const struct sctp_association *asoc,
2634 const sctp_subtype_t type,
2636 sctp_cmd_seq_t *commands)
2638 struct sctp_chunk *chunk = arg;
2641 if (!sctp_vtag_verify(chunk, asoc)) {
2642 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2644 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2647 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t)))
2648 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2651 error = sctp_eat_data(asoc, chunk, commands );
2653 case SCTP_IERROR_NO_ERROR:
2655 case SCTP_IERROR_HIGH_TSN:
2656 case SCTP_IERROR_BAD_STREAM:
2657 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
2658 goto discard_noforce;
2659 case SCTP_IERROR_DUP_TSN:
2660 case SCTP_IERROR_IGNORE_TSN:
2661 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
2663 case SCTP_IERROR_NO_DATA:
2669 if (asoc->autoclose) {
2670 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2671 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
2674 /* If this is the last chunk in a packet, we need to count it
2675 * toward sack generation. Note that we need to SACK every
2676 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2677 * THEM. We elect to NOT generate SACK's if the chunk fails
2678 * the verification tag test.
2680 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2682 * The SCTP endpoint MUST always acknowledge the reception of
2683 * each valid DATA chunk.
2685 * The guidelines on delayed acknowledgement algorithm
2686 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2687 * Specifically, an acknowledgement SHOULD be generated for at
2688 * least every second packet (not every second DATA chunk)
2689 * received, and SHOULD be generated within 200 ms of the
2690 * arrival of any unacknowledged DATA chunk. In some
2691 * situations it may be beneficial for an SCTP transmitter to
2692 * be more conservative than the algorithms detailed in this
2693 * document allow. However, an SCTP transmitter MUST NOT be
2694 * more aggressive than the following algorithms allow.
2696 if (chunk->end_of_packet)
2697 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2699 return SCTP_DISPOSITION_CONSUME;
2702 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2704 * When a packet arrives with duplicate DATA chunk(s) and with
2705 * no new DATA chunk(s), the endpoint MUST immediately send a
2706 * SACK with no delay. If a packet arrives with duplicate
2707 * DATA chunk(s) bundled with new DATA chunks, the endpoint
2708 * MAY immediately send a SACK. Normally receipt of duplicate
2709 * DATA chunks will occur when the original SACK chunk was lost
2710 * and the peer's RTO has expired. The duplicate TSN number(s)
2711 * SHOULD be reported in the SACK as duplicate.
2713 /* In our case, we split the MAY SACK advice up whether or not
2714 * the last chunk is a duplicate.'
2716 if (chunk->end_of_packet)
2717 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2718 return SCTP_DISPOSITION_DISCARD;
2721 if (chunk->end_of_packet)
2722 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2724 return SCTP_DISPOSITION_DISCARD;
2726 return SCTP_DISPOSITION_CONSUME;
2731 * sctp_sf_eat_data_fast_4_4
2734 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
2735 * DATA chunks without delay.
2737 * Verification Tag: 8.5 Verification Tag [Normal verification]
2739 * (endpoint, asoc, chunk)
2742 * (asoc, reply_msg, msg_up, timers, counters)
2744 * The return value is the disposition of the chunk.
2746 sctp_disposition_t sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint *ep,
2747 const struct sctp_association *asoc,
2748 const sctp_subtype_t type,
2750 sctp_cmd_seq_t *commands)
2752 struct sctp_chunk *chunk = arg;
2755 if (!sctp_vtag_verify(chunk, asoc)) {
2756 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2758 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2761 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t)))
2762 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2765 error = sctp_eat_data(asoc, chunk, commands );
2767 case SCTP_IERROR_NO_ERROR:
2768 case SCTP_IERROR_HIGH_TSN:
2769 case SCTP_IERROR_DUP_TSN:
2770 case SCTP_IERROR_IGNORE_TSN:
2771 case SCTP_IERROR_BAD_STREAM:
2773 case SCTP_IERROR_NO_DATA:
2779 /* Go a head and force a SACK, since we are shutting down. */
2781 /* Implementor's Guide.
2783 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
2784 * respond to each received packet containing one or more DATA chunk(s)
2785 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
2787 if (chunk->end_of_packet) {
2788 /* We must delay the chunk creation since the cumulative
2789 * TSN has not been updated yet.
2791 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
2792 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2793 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2794 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2798 return SCTP_DISPOSITION_CONSUME;
2802 * Section: 6.2 Processing a Received SACK
2803 * D) Any time a SACK arrives, the endpoint performs the following:
2805 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
2806 * then drop the SACK. Since Cumulative TSN Ack is monotonically
2807 * increasing, a SACK whose Cumulative TSN Ack is less than the
2808 * Cumulative TSN Ack Point indicates an out-of-order SACK.
2810 * ii) Set rwnd equal to the newly received a_rwnd minus the number
2811 * of bytes still outstanding after processing the Cumulative TSN Ack
2812 * and the Gap Ack Blocks.
2814 * iii) If the SACK is missing a TSN that was previously
2815 * acknowledged via a Gap Ack Block (e.g., the data receiver
2816 * reneged on the data), then mark the corresponding DATA chunk
2817 * as available for retransmit: Mark it as missing for fast
2818 * retransmit as described in Section 7.2.4 and if no retransmit
2819 * timer is running for the destination address to which the DATA
2820 * chunk was originally transmitted, then T3-rtx is started for
2821 * that destination address.
2823 * Verification Tag: 8.5 Verification Tag [Normal verification]
2826 * (endpoint, asoc, chunk)
2829 * (asoc, reply_msg, msg_up, timers, counters)
2831 * The return value is the disposition of the chunk.
2833 sctp_disposition_t sctp_sf_eat_sack_6_2(const struct sctp_endpoint *ep,
2834 const struct sctp_association *asoc,
2835 const sctp_subtype_t type,
2837 sctp_cmd_seq_t *commands)
2839 struct sctp_chunk *chunk = arg;
2840 sctp_sackhdr_t *sackh;
2843 if (!sctp_vtag_verify(chunk, asoc))
2844 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2846 /* Make sure that the SACK chunk has a valid length. */
2847 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_sack_chunk_t)))
2848 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2851 /* Pull the SACK chunk from the data buffer */
2852 sackh = sctp_sm_pull_sack(chunk);
2853 /* Was this a bogus SACK? */
2855 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2856 chunk->subh.sack_hdr = sackh;
2857 ctsn = ntohl(sackh->cum_tsn_ack);
2859 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
2860 * Ack Point, then drop the SACK. Since Cumulative TSN
2861 * Ack is monotonically increasing, a SACK whose
2862 * Cumulative TSN Ack is less than the Cumulative TSN Ack
2863 * Point indicates an out-of-order SACK.
2865 if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
2866 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn);
2867 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc->ctsn_ack_point);
2868 return SCTP_DISPOSITION_DISCARD;
2871 /* Return this SACK for further processing. */
2872 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_SACKH(sackh));
2874 /* Note: We do the rest of the work on the PROCESS_SACK
2877 return SCTP_DISPOSITION_CONSUME;
2881 * Generate an ABORT in response to a packet.
2883 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
2885 * 8) The receiver should respond to the sender of the OOTB packet with
2886 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
2887 * MUST fill in the Verification Tag field of the outbound packet
2888 * with the value found in the Verification Tag field of the OOTB
2889 * packet and set the T-bit in the Chunk Flags to indicate that the
2890 * Verification Tag is reflected. After sending this ABORT, the
2891 * receiver of the OOTB packet shall discard the OOTB packet and take
2892 * no further action.
2896 * The return value is the disposition of the chunk.
2898 sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep,
2899 const struct sctp_association *asoc,
2900 const sctp_subtype_t type,
2902 sctp_cmd_seq_t *commands)
2904 struct sctp_packet *packet = NULL;
2905 struct sctp_chunk *chunk = arg;
2906 struct sctp_chunk *abort;
2908 packet = sctp_ootb_pkt_new(asoc, chunk);
2911 /* Make an ABORT. The T bit will be set if the asoc
2914 abort = sctp_make_abort(asoc, chunk, 0);
2916 sctp_ootb_pkt_free(packet);
2917 return SCTP_DISPOSITION_NOMEM;
2920 /* Reflect vtag if T-Bit is set */
2921 if (sctp_test_T_bit(abort))
2922 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
2924 /* Set the skb to the belonging sock for accounting. */
2925 abort->skb->sk = ep->base.sk;
2927 sctp_packet_append_chunk(packet, abort);
2929 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
2930 SCTP_PACKET(packet));
2932 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
2934 return SCTP_DISPOSITION_CONSUME;
2937 return SCTP_DISPOSITION_NOMEM;
2941 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
2942 * event as ULP notification for each cause included in the chunk.
2944 * API 5.3.1.3 - SCTP_REMOTE_ERROR
2946 * The return value is the disposition of the chunk.
2948 sctp_disposition_t sctp_sf_operr_notify(const struct sctp_endpoint *ep,
2949 const struct sctp_association *asoc,
2950 const sctp_subtype_t type,
2952 sctp_cmd_seq_t *commands)
2954 struct sctp_chunk *chunk = arg;
2955 struct sctp_ulpevent *ev;
2957 if (!sctp_vtag_verify(chunk, asoc))
2958 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2960 /* Make sure that the ERROR chunk has a valid length. */
2961 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t)))
2962 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2965 while (chunk->chunk_end > chunk->skb->data) {
2966 ev = sctp_ulpevent_make_remote_error(asoc, chunk, 0,
2971 if (!sctp_add_cmd(commands, SCTP_CMD_EVENT_ULP,
2972 SCTP_ULPEVENT(ev))) {
2973 sctp_ulpevent_free(ev);
2977 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR,
2980 return SCTP_DISPOSITION_CONSUME;
2983 return SCTP_DISPOSITION_NOMEM;
2987 * Process an inbound SHUTDOWN ACK.
2990 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
2991 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
2992 * peer, and remove all record of the association.
2994 * The return value is the disposition.
2996 sctp_disposition_t sctp_sf_do_9_2_final(const struct sctp_endpoint *ep,
2997 const struct sctp_association *asoc,
2998 const sctp_subtype_t type,
3000 sctp_cmd_seq_t *commands)
3002 struct sctp_chunk *chunk = arg;
3003 struct sctp_chunk *reply;
3004 struct sctp_ulpevent *ev;
3006 if (!sctp_vtag_verify(chunk, asoc))
3007 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3009 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3010 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3011 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3013 /* 10.2 H) SHUTDOWN COMPLETE notification
3015 * When SCTP completes the shutdown procedures (section 9.2) this
3016 * notification is passed to the upper layer.
3018 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
3019 0, 0, 0, GFP_ATOMIC);
3023 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3024 reply = sctp_make_shutdown_complete(asoc, chunk);
3028 /* Do all the commands now (after allocation), so that we
3029 * have consistent state if memory allocation failes
3031 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
3033 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3034 * stop the T2-shutdown timer,
3036 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3037 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3039 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3040 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3042 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3043 SCTP_STATE(SCTP_STATE_CLOSED));
3044 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
3045 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3046 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
3048 /* ...and remove all record of the association. */
3049 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
3050 return SCTP_DISPOSITION_DELETE_TCB;
3053 sctp_ulpevent_free(ev);
3055 return SCTP_DISPOSITION_NOMEM;
3059 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3061 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3062 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3063 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3064 * packet must fill in the Verification Tag field of the outbound
3065 * packet with the Verification Tag received in the SHUTDOWN ACK and
3066 * set the T-bit in the Chunk Flags to indicate that the Verification
3069 * 8) The receiver should respond to the sender of the OOTB packet with
3070 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3071 * MUST fill in the Verification Tag field of the outbound packet
3072 * with the value found in the Verification Tag field of the OOTB
3073 * packet and set the T-bit in the Chunk Flags to indicate that the
3074 * Verification Tag is reflected. After sending this ABORT, the
3075 * receiver of the OOTB packet shall discard the OOTB packet and take
3076 * no further action.
3078 sctp_disposition_t sctp_sf_ootb(const struct sctp_endpoint *ep,
3079 const struct sctp_association *asoc,
3080 const sctp_subtype_t type,
3082 sctp_cmd_seq_t *commands)
3084 struct sctp_chunk *chunk = arg;
3085 struct sk_buff *skb = chunk->skb;
3086 sctp_chunkhdr_t *ch;
3088 int ootb_shut_ack = 0;
3090 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES);
3092 ch = (sctp_chunkhdr_t *) chunk->chunk_hdr;
3094 /* Break out if chunk length is less then minimal. */
3095 if (ntohs(ch->length) < sizeof(sctp_chunkhdr_t))
3098 ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length));
3099 if (ch_end > skb->tail)
3102 if (SCTP_CID_SHUTDOWN_ACK == ch->type)
3105 /* RFC 2960, Section 3.3.7
3106 * Moreover, under any circumstances, an endpoint that
3107 * receives an ABORT MUST NOT respond to that ABORT by
3108 * sending an ABORT of its own.
3110 if (SCTP_CID_ABORT == ch->type)
3111 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3113 ch = (sctp_chunkhdr_t *) ch_end;
3114 } while (ch_end < skb->tail);
3117 sctp_sf_shut_8_4_5(ep, asoc, type, arg, commands);
3119 sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
3121 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3125 * Handle an "Out of the blue" SHUTDOWN ACK.
3127 * Section: 8.4 5, sctpimpguide 2.41.
3129 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3130 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3131 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3132 * packet must fill in the Verification Tag field of the outbound
3133 * packet with the Verification Tag received in the SHUTDOWN ACK and
3134 * set the T-bit in the Chunk Flags to indicate that the Verification
3138 * (endpoint, asoc, type, arg, commands)
3141 * (sctp_disposition_t)
3143 * The return value is the disposition of the chunk.
3145 static sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep,
3146 const struct sctp_association *asoc,
3147 const sctp_subtype_t type,
3149 sctp_cmd_seq_t *commands)
3151 struct sctp_packet *packet = NULL;
3152 struct sctp_chunk *chunk = arg;
3153 struct sctp_chunk *shut;
3155 packet = sctp_ootb_pkt_new(asoc, chunk);
3158 /* Make an SHUTDOWN_COMPLETE.
3159 * The T bit will be set if the asoc is NULL.
3161 shut = sctp_make_shutdown_complete(asoc, chunk);
3163 sctp_ootb_pkt_free(packet);
3164 return SCTP_DISPOSITION_NOMEM;
3167 /* Reflect vtag if T-Bit is set */
3168 if (sctp_test_T_bit(shut))
3169 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
3171 /* Set the skb to the belonging sock for accounting. */
3172 shut->skb->sk = ep->base.sk;
3174 sctp_packet_append_chunk(packet, shut);
3176 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
3177 SCTP_PACKET(packet));
3179 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
3181 /* If the chunk length is invalid, we don't want to process
3182 * the reset of the packet.
3184 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3185 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3187 return SCTP_DISPOSITION_CONSUME;
3190 return SCTP_DISPOSITION_NOMEM;
3194 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3196 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3197 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3198 * procedures in section 8.4 SHOULD be followed, in other words it
3199 * should be treated as an Out Of The Blue packet.
3200 * [This means that we do NOT check the Verification Tag on these
3204 sctp_disposition_t sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint *ep,
3205 const struct sctp_association *asoc,
3206 const sctp_subtype_t type,
3208 sctp_cmd_seq_t *commands)
3210 /* Although we do have an association in this case, it corresponds
3211 * to a restarted association. So the packet is treated as an OOTB
3212 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3213 * called with a NULL association.
3215 return sctp_sf_shut_8_4_5(ep, NULL, type, arg, commands);
3218 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3219 sctp_disposition_t sctp_sf_do_asconf(const struct sctp_endpoint *ep,
3220 const struct sctp_association *asoc,
3221 const sctp_subtype_t type, void *arg,
3222 sctp_cmd_seq_t *commands)
3224 struct sctp_chunk *chunk = arg;
3225 struct sctp_chunk *asconf_ack = NULL;
3226 sctp_addiphdr_t *hdr;
3229 if (!sctp_vtag_verify(chunk, asoc)) {
3230 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3232 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3235 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3236 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_addip_chunk_t)))
3237 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3240 hdr = (sctp_addiphdr_t *)chunk->skb->data;
3241 serial = ntohl(hdr->serial);
3243 /* ADDIP 4.2 C1) Compare the value of the serial number to the value
3244 * the endpoint stored in a new association variable
3245 * 'Peer-Serial-Number'.
3247 if (serial == asoc->peer.addip_serial + 1) {
3248 /* ADDIP 4.2 C2) If the value found in the serial number is
3249 * equal to the ('Peer-Serial-Number' + 1), the endpoint MUST
3252 asconf_ack = sctp_process_asconf((struct sctp_association *)
3255 return SCTP_DISPOSITION_NOMEM;
3256 } else if (serial == asoc->peer.addip_serial) {
3257 /* ADDIP 4.2 C3) If the value found in the serial number is
3258 * equal to the value stored in the 'Peer-Serial-Number'
3259 * IMPLEMENTATION NOTE: As an optimization a receiver may wish
3260 * to save the last ASCONF-ACK for some predetermined period of
3261 * time and instead of re-processing the ASCONF (with the same
3262 * serial number) it may just re-transmit the ASCONF-ACK.
3264 if (asoc->addip_last_asconf_ack)
3265 asconf_ack = asoc->addip_last_asconf_ack;
3267 return SCTP_DISPOSITION_DISCARD;
3269 /* ADDIP 4.2 C4) Otherwise, the ASCONF Chunk is discarded since
3270 * it must be either a stale packet or from an attacker.
3272 return SCTP_DISPOSITION_DISCARD;
3275 /* ADDIP 4.2 C5) In both cases C2 and C3 the ASCONF-ACK MUST be sent
3276 * back to the source address contained in the IP header of the ASCONF
3277 * being responded to.
3279 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack));
3281 return SCTP_DISPOSITION_CONSUME;
3285 * ADDIP Section 4.3 General rules for address manipulation
3286 * When building TLV parameters for the ASCONF Chunk that will add or
3287 * delete IP addresses the D0 to D13 rules should be applied:
3289 sctp_disposition_t sctp_sf_do_asconf_ack(const struct sctp_endpoint *ep,
3290 const struct sctp_association *asoc,
3291 const sctp_subtype_t type, void *arg,
3292 sctp_cmd_seq_t *commands)
3294 struct sctp_chunk *asconf_ack = arg;
3295 struct sctp_chunk *last_asconf = asoc->addip_last_asconf;
3296 struct sctp_chunk *abort;
3297 sctp_addiphdr_t *addip_hdr;
3298 __u32 sent_serial, rcvd_serial;
3300 if (!sctp_vtag_verify(asconf_ack, asoc)) {
3301 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3303 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3306 /* Make sure that the ADDIP chunk has a valid length. */
3307 if (!sctp_chunk_length_valid(asconf_ack, sizeof(sctp_addip_chunk_t)))
3308 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3311 addip_hdr = (sctp_addiphdr_t *)asconf_ack->skb->data;
3312 rcvd_serial = ntohl(addip_hdr->serial);
3315 addip_hdr = (sctp_addiphdr_t *)last_asconf->subh.addip_hdr;
3316 sent_serial = ntohl(addip_hdr->serial);
3318 sent_serial = asoc->addip_serial - 1;
3321 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3322 * equal to the next serial number to be used but no ASCONF chunk is
3323 * outstanding the endpoint MUST ABORT the association. Note that a
3324 * sequence number is greater than if it is no more than 2^^31-1
3325 * larger than the current sequence number (using serial arithmetic).
3327 if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) &&
3328 !(asoc->addip_last_asconf)) {
3329 abort = sctp_make_abort(asoc, asconf_ack,
3330 sizeof(sctp_errhdr_t));
3332 sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, NULL, 0);
3333 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3336 /* We are going to ABORT, so we might as well stop
3337 * processing the rest of the chunks in the packet.
3339 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3340 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3341 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3342 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3343 SCTP_ERROR(ECONNABORTED));
3344 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3345 SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
3346 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3347 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3348 return SCTP_DISPOSITION_ABORT;
3351 if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) {
3352 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3353 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3355 if (!sctp_process_asconf_ack((struct sctp_association *)asoc,
3357 return SCTP_DISPOSITION_CONSUME;
3359 abort = sctp_make_abort(asoc, asconf_ack,
3360 sizeof(sctp_errhdr_t));
3362 sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, NULL, 0);
3363 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3366 /* We are going to ABORT, so we might as well stop
3367 * processing the rest of the chunks in the packet.
3369 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3370 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3371 SCTP_ERROR(ECONNABORTED));
3372 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3373 SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
3374 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3375 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3376 return SCTP_DISPOSITION_ABORT;
3379 return SCTP_DISPOSITION_DISCARD;
3383 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3385 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3386 * its cumulative TSN point to the value carried in the FORWARD TSN
3387 * chunk, and then MUST further advance its cumulative TSN point locally
3389 * After the above processing, the data receiver MUST stop reporting any
3390 * missing TSNs earlier than or equal to the new cumulative TSN point.
3392 * Verification Tag: 8.5 Verification Tag [Normal verification]
3394 * The return value is the disposition of the chunk.
3396 sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep,
3397 const struct sctp_association *asoc,
3398 const sctp_subtype_t type,
3400 sctp_cmd_seq_t *commands)
3402 struct sctp_chunk *chunk = arg;
3403 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3407 if (!sctp_vtag_verify(chunk, asoc)) {
3408 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3410 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3413 /* Make sure that the FORWARD_TSN chunk has valid length. */
3414 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk)))
3415 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3418 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3419 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3420 len = ntohs(chunk->chunk_hdr->length);
3421 len -= sizeof(struct sctp_chunkhdr);
3422 skb_pull(chunk->skb, len);
3424 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3425 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn);
3427 /* The TSN is too high--silently discard the chunk and count on it
3428 * getting retransmitted later.
3430 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3431 goto discard_noforce;
3433 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3434 if (len > sizeof(struct sctp_fwdtsn_hdr))
3435 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3438 /* Count this as receiving DATA. */
3439 if (asoc->autoclose) {
3440 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3441 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
3444 /* FIXME: For now send a SACK, but DATA processing may
3447 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
3449 return SCTP_DISPOSITION_CONSUME;
3452 return SCTP_DISPOSITION_DISCARD;
3455 sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(
3456 const struct sctp_endpoint *ep,
3457 const struct sctp_association *asoc,
3458 const sctp_subtype_t type,
3460 sctp_cmd_seq_t *commands)
3462 struct sctp_chunk *chunk = arg;
3463 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3467 if (!sctp_vtag_verify(chunk, asoc)) {
3468 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3470 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3473 /* Make sure that the FORWARD_TSN chunk has a valid length. */
3474 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk)))
3475 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3478 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3479 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3480 len = ntohs(chunk->chunk_hdr->length);
3481 len -= sizeof(struct sctp_chunkhdr);
3482 skb_pull(chunk->skb, len);
3484 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3485 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn);
3487 /* The TSN is too high--silently discard the chunk and count on it
3488 * getting retransmitted later.
3490 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3493 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3494 if (len > sizeof(struct sctp_fwdtsn_hdr))
3495 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3498 /* Go a head and force a SACK, since we are shutting down. */
3500 /* Implementor's Guide.
3502 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3503 * respond to each received packet containing one or more DATA chunk(s)
3504 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3506 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
3507 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
3508 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3509 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3511 return SCTP_DISPOSITION_CONSUME;
3515 * Process an unknown chunk.
3517 * Section: 3.2. Also, 2.1 in the implementor's guide.
3519 * Chunk Types are encoded such that the highest-order two bits specify
3520 * the action that must be taken if the processing endpoint does not
3521 * recognize the Chunk Type.
3523 * 00 - Stop processing this SCTP packet and discard it, do not process
3524 * any further chunks within it.
3526 * 01 - Stop processing this SCTP packet and discard it, do not process
3527 * any further chunks within it, and report the unrecognized
3528 * chunk in an 'Unrecognized Chunk Type'.
3530 * 10 - Skip this chunk and continue processing.
3532 * 11 - Skip this chunk and continue processing, but report in an ERROR
3533 * Chunk using the 'Unrecognized Chunk Type' cause of error.
3535 * The return value is the disposition of the chunk.
3537 sctp_disposition_t sctp_sf_unk_chunk(const struct sctp_endpoint *ep,
3538 const struct sctp_association *asoc,
3539 const sctp_subtype_t type,
3541 sctp_cmd_seq_t *commands)
3543 struct sctp_chunk *unk_chunk = arg;
3544 struct sctp_chunk *err_chunk;
3545 sctp_chunkhdr_t *hdr;
3547 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type.chunk);
3549 if (!sctp_vtag_verify(unk_chunk, asoc))
3550 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3552 /* Make sure that the chunk has a valid length.
3553 * Since we don't know the chunk type, we use a general
3554 * chunkhdr structure to make a comparison.
3556 if (!sctp_chunk_length_valid(unk_chunk, sizeof(sctp_chunkhdr_t)))
3557 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3560 switch (type.chunk & SCTP_CID_ACTION_MASK) {
3561 case SCTP_CID_ACTION_DISCARD:
3562 /* Discard the packet. */
3563 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3565 case SCTP_CID_ACTION_DISCARD_ERR:
3566 /* Discard the packet. */
3567 sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3569 /* Generate an ERROR chunk as response. */
3570 hdr = unk_chunk->chunk_hdr;
3571 err_chunk = sctp_make_op_error(asoc, unk_chunk,
3572 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
3573 WORD_ROUND(ntohs(hdr->length)));
3575 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3576 SCTP_CHUNK(err_chunk));
3578 return SCTP_DISPOSITION_CONSUME;
3580 case SCTP_CID_ACTION_SKIP:
3581 /* Skip the chunk. */
3582 return SCTP_DISPOSITION_DISCARD;
3584 case SCTP_CID_ACTION_SKIP_ERR:
3585 /* Generate an ERROR chunk as response. */
3586 hdr = unk_chunk->chunk_hdr;
3587 err_chunk = sctp_make_op_error(asoc, unk_chunk,
3588 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
3589 WORD_ROUND(ntohs(hdr->length)));
3591 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3592 SCTP_CHUNK(err_chunk));
3594 /* Skip the chunk. */
3595 return SCTP_DISPOSITION_CONSUME;
3601 return SCTP_DISPOSITION_DISCARD;
3605 * Discard the chunk.
3607 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
3608 * [Too numerous to mention...]
3609 * Verification Tag: No verification needed.
3611 * (endpoint, asoc, chunk)
3614 * (asoc, reply_msg, msg_up, timers, counters)
3616 * The return value is the disposition of the chunk.
3618 sctp_disposition_t sctp_sf_discard_chunk(const struct sctp_endpoint *ep,
3619 const struct sctp_association *asoc,
3620 const sctp_subtype_t type,
3622 sctp_cmd_seq_t *commands)
3624 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type.chunk);
3625 return SCTP_DISPOSITION_DISCARD;
3629 * Discard the whole packet.
3633 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
3634 * silently discard the OOTB packet and take no further action.
3636 * Verification Tag: No verification necessary
3639 * (endpoint, asoc, chunk)
3642 * (asoc, reply_msg, msg_up, timers, counters)
3644 * The return value is the disposition of the chunk.
3646 sctp_disposition_t sctp_sf_pdiscard(const struct sctp_endpoint *ep,
3647 const struct sctp_association *asoc,
3648 const sctp_subtype_t type,
3650 sctp_cmd_seq_t *commands)
3652 SCTP_INC_STATS(SCTP_MIB_IN_PKT_DISCARDS);
3653 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
3655 return SCTP_DISPOSITION_CONSUME;
3660 * The other end is violating protocol.
3662 * Section: Not specified
3663 * Verification Tag: Not specified
3665 * (endpoint, asoc, chunk)
3668 * (asoc, reply_msg, msg_up, timers, counters)
3670 * We simply tag the chunk as a violation. The state machine will log
3671 * the violation and continue.
3673 sctp_disposition_t sctp_sf_violation(const struct sctp_endpoint *ep,
3674 const struct sctp_association *asoc,
3675 const sctp_subtype_t type,
3677 sctp_cmd_seq_t *commands)
3679 return SCTP_DISPOSITION_VIOLATION;
3684 * Handle a protocol violation when the chunk length is invalid.
3685 * "Invalid" length is identified as smaller then the minimal length a
3686 * given chunk can be. For example, a SACK chunk has invalid length
3687 * if it's length is set to be smaller then the size of sctp_sack_chunk_t.
3689 * We inform the other end by sending an ABORT with a Protocol Violation
3692 * Section: Not specified
3693 * Verification Tag: Nothing to do
3695 * (endpoint, asoc, chunk)
3698 * (reply_msg, msg_up, counters)
3700 * Generate an ABORT chunk and terminate the association.
3702 static sctp_disposition_t sctp_sf_violation_chunklen(
3703 const struct sctp_endpoint *ep,
3704 const struct sctp_association *asoc,
3705 const sctp_subtype_t type,
3707 sctp_cmd_seq_t *commands)
3709 struct sctp_chunk *chunk = arg;
3710 struct sctp_chunk *abort = NULL;
3711 char err_str[]="The following chunk had invalid length:";
3713 /* Make the abort chunk. */
3714 abort = sctp_make_abort_violation(asoc, chunk, err_str,
3719 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
3720 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
3722 if (asoc->state <= SCTP_STATE_COOKIE_ECHOED) {
3723 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3724 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
3725 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3726 SCTP_ERROR(ECONNREFUSED));
3727 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
3728 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
3730 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3731 SCTP_ERROR(ECONNABORTED));
3732 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3733 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
3734 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3737 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
3739 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3741 return SCTP_DISPOSITION_ABORT;
3744 return SCTP_DISPOSITION_NOMEM;
3747 /***************************************************************************
3748 * These are the state functions for handling primitive (Section 10) events.
3749 ***************************************************************************/
3751 * sctp_sf_do_prm_asoc
3753 * Section: 10.1 ULP-to-SCTP
3756 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
3757 * outbound stream count)
3758 * -> association id [,destination transport addr list] [,outbound stream
3761 * This primitive allows the upper layer to initiate an association to a
3762 * specific peer endpoint.
3764 * The peer endpoint shall be specified by one of the transport addresses
3765 * which defines the endpoint (see Section 1.4). If the local SCTP
3766 * instance has not been initialized, the ASSOCIATE is considered an
3768 * [This is not relevant for the kernel implementation since we do all
3769 * initialization at boot time. It we hadn't initialized we wouldn't
3770 * get anywhere near this code.]
3772 * An association id, which is a local handle to the SCTP association,
3773 * will be returned on successful establishment of the association. If
3774 * SCTP is not able to open an SCTP association with the peer endpoint,
3775 * an error is returned.
3776 * [In the kernel implementation, the struct sctp_association needs to
3777 * be created BEFORE causing this primitive to run.]
3779 * Other association parameters may be returned, including the
3780 * complete destination transport addresses of the peer as well as the
3781 * outbound stream count of the local endpoint. One of the transport
3782 * address from the returned destination addresses will be selected by
3783 * the local endpoint as default primary path for sending SCTP packets
3784 * to this peer. The returned "destination transport addr list" can
3785 * be used by the ULP to change the default primary path or to force
3786 * sending a packet to a specific transport address. [All of this
3787 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
3790 * Mandatory attributes:
3792 * o local SCTP instance name - obtained from the INITIALIZE operation.
3793 * [This is the argument asoc.]
3794 * o destination transport addr - specified as one of the transport
3795 * addresses of the peer endpoint with which the association is to be
3797 * [This is asoc->peer.active_path.]
3798 * o outbound stream count - the number of outbound streams the ULP
3799 * would like to open towards this peer endpoint.
3800 * [BUG: This is not currently implemented.]
3801 * Optional attributes:
3805 * The return value is a disposition.
3807 sctp_disposition_t sctp_sf_do_prm_asoc(const struct sctp_endpoint *ep,
3808 const struct sctp_association *asoc,
3809 const sctp_subtype_t type,
3811 sctp_cmd_seq_t *commands)
3813 struct sctp_chunk *repl;
3815 /* The comment below says that we enter COOKIE-WAIT AFTER
3816 * sending the INIT, but that doesn't actually work in our
3819 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3820 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
3822 /* RFC 2960 5.1 Normal Establishment of an Association
3824 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
3825 * must provide its Verification Tag (Tag_A) in the Initiate
3826 * Tag field. Tag_A SHOULD be a random number in the range of
3827 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
3830 repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0);
3834 /* Cast away the const modifier, as we want to just
3835 * rerun it through as a sideffect.
3837 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC,
3838 SCTP_ASOC((struct sctp_association *) asoc));
3840 /* Choose transport for INIT. */
3841 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
3844 /* After sending the INIT, "A" starts the T1-init timer and
3845 * enters the COOKIE-WAIT state.
3847 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
3848 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
3849 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
3850 return SCTP_DISPOSITION_CONSUME;
3853 return SCTP_DISPOSITION_NOMEM;
3857 * Process the SEND primitive.
3859 * Section: 10.1 ULP-to-SCTP
3862 * Format: SEND(association id, buffer address, byte count [,context]
3863 * [,stream id] [,life time] [,destination transport address]
3864 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
3867 * This is the main method to send user data via SCTP.
3869 * Mandatory attributes:
3871 * o association id - local handle to the SCTP association
3873 * o buffer address - the location where the user message to be
3874 * transmitted is stored;
3876 * o byte count - The size of the user data in number of bytes;
3878 * Optional attributes:
3880 * o context - an optional 32 bit integer that will be carried in the
3881 * sending failure notification to the ULP if the transportation of
3882 * this User Message fails.
3884 * o stream id - to indicate which stream to send the data on. If not
3885 * specified, stream 0 will be used.
3887 * o life time - specifies the life time of the user data. The user data
3888 * will not be sent by SCTP after the life time expires. This
3889 * parameter can be used to avoid efforts to transmit stale
3890 * user messages. SCTP notifies the ULP if the data cannot be
3891 * initiated to transport (i.e. sent to the destination via SCTP's
3892 * send primitive) within the life time variable. However, the
3893 * user data will be transmitted if SCTP has attempted to transmit a
3894 * chunk before the life time expired.
3896 * o destination transport address - specified as one of the destination
3897 * transport addresses of the peer endpoint to which this packet
3898 * should be sent. Whenever possible, SCTP should use this destination
3899 * transport address for sending the packets, instead of the current
3902 * o unorder flag - this flag, if present, indicates that the user
3903 * would like the data delivered in an unordered fashion to the peer
3904 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
3907 * o no-bundle flag - instructs SCTP not to bundle this user data with
3908 * other outbound DATA chunks. SCTP MAY still bundle even when
3909 * this flag is present, when faced with network congestion.
3911 * o payload protocol-id - A 32 bit unsigned integer that is to be
3912 * passed to the peer indicating the type of payload protocol data
3913 * being transmitted. This value is passed as opaque data by SCTP.
3915 * The return value is the disposition.
3917 sctp_disposition_t sctp_sf_do_prm_send(const struct sctp_endpoint *ep,
3918 const struct sctp_association *asoc,
3919 const sctp_subtype_t type,
3921 sctp_cmd_seq_t *commands)
3923 struct sctp_chunk *chunk = arg;
3925 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
3926 return SCTP_DISPOSITION_CONSUME;
3930 * Process the SHUTDOWN primitive.
3935 * Format: SHUTDOWN(association id)
3938 * Gracefully closes an association. Any locally queued user data
3939 * will be delivered to the peer. The association will be terminated only
3940 * after the peer acknowledges all the SCTP packets sent. A success code
3941 * will be returned on successful termination of the association. If
3942 * attempting to terminate the association results in a failure, an error
3943 * code shall be returned.
3945 * Mandatory attributes:
3947 * o association id - local handle to the SCTP association
3949 * Optional attributes:
3953 * The return value is the disposition.
3955 sctp_disposition_t sctp_sf_do_9_2_prm_shutdown(
3956 const struct sctp_endpoint *ep,
3957 const struct sctp_association *asoc,
3958 const sctp_subtype_t type,
3960 sctp_cmd_seq_t *commands)
3964 /* From 9.2 Shutdown of an Association
3965 * Upon receipt of the SHUTDOWN primitive from its upper
3966 * layer, the endpoint enters SHUTDOWN-PENDING state and
3967 * remains there until all outstanding data has been
3968 * acknowledged by its peer. The endpoint accepts no new data
3969 * from its upper layer, but retransmits data to the far end
3970 * if necessary to fill gaps.
3972 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3973 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
3975 /* sctpimpguide-05 Section 2.12.2
3976 * The sender of the SHUTDOWN MAY also start an overall guard timer
3977 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
3979 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
3980 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3982 disposition = SCTP_DISPOSITION_CONSUME;
3983 if (sctp_outq_is_empty(&asoc->outqueue)) {
3984 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
3991 * Process the ABORT primitive.
3996 * Format: Abort(association id [, cause code])
3999 * Ungracefully closes an association. Any locally queued user data
4000 * will be discarded and an ABORT chunk is sent to the peer. A success code
4001 * will be returned on successful abortion of the association. If
4002 * attempting to abort the association results in a failure, an error
4003 * code shall be returned.
4005 * Mandatory attributes:
4007 * o association id - local handle to the SCTP association
4009 * Optional attributes:
4011 * o cause code - reason of the abort to be passed to the peer
4015 * The return value is the disposition.
4017 sctp_disposition_t sctp_sf_do_9_1_prm_abort(
4018 const struct sctp_endpoint *ep,
4019 const struct sctp_association *asoc,
4020 const sctp_subtype_t type,
4022 sctp_cmd_seq_t *commands)
4024 /* From 9.1 Abort of an Association
4025 * Upon receipt of the ABORT primitive from its upper
4026 * layer, the endpoint enters CLOSED state and
4027 * discard all outstanding data has been
4028 * acknowledged by its peer. The endpoint accepts no new data
4029 * from its upper layer, but retransmits data to the far end
4030 * if necessary to fill gaps.
4032 struct sctp_chunk *abort = arg;
4033 sctp_disposition_t retval;
4035 retval = SCTP_DISPOSITION_CONSUME;
4037 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4039 /* Even if we can't send the ABORT due to low memory delete the
4040 * TCB. This is a departure from our typical NOMEM handling.
4043 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4044 SCTP_ERROR(ECONNABORTED));
4045 /* Delete the established association. */
4046 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4047 SCTP_PERR(SCTP_ERROR_USER_ABORT));
4049 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4050 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4055 /* We tried an illegal operation on an association which is closed. */
4056 sctp_disposition_t sctp_sf_error_closed(const struct sctp_endpoint *ep,
4057 const struct sctp_association *asoc,
4058 const sctp_subtype_t type,
4060 sctp_cmd_seq_t *commands)
4062 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL));
4063 return SCTP_DISPOSITION_CONSUME;
4066 /* We tried an illegal operation on an association which is shutting
4069 sctp_disposition_t sctp_sf_error_shutdown(const struct sctp_endpoint *ep,
4070 const struct sctp_association *asoc,
4071 const sctp_subtype_t type,
4073 sctp_cmd_seq_t *commands)
4075 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR,
4076 SCTP_ERROR(-ESHUTDOWN));
4077 return SCTP_DISPOSITION_CONSUME;
4081 * sctp_cookie_wait_prm_shutdown
4083 * Section: 4 Note: 2
4088 * The RFC does not explicitly address this issue, but is the route through the
4089 * state table when someone issues a shutdown while in COOKIE_WAIT state.
4094 sctp_disposition_t sctp_sf_cookie_wait_prm_shutdown(
4095 const struct sctp_endpoint *ep,
4096 const struct sctp_association *asoc,
4097 const sctp_subtype_t type,
4099 sctp_cmd_seq_t *commands)
4101 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4102 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4104 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4105 SCTP_STATE(SCTP_STATE_CLOSED));
4107 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
4109 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
4111 return SCTP_DISPOSITION_DELETE_TCB;
4115 * sctp_cookie_echoed_prm_shutdown
4117 * Section: 4 Note: 2
4122 * The RFC does not explcitly address this issue, but is the route through the
4123 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
4128 sctp_disposition_t sctp_sf_cookie_echoed_prm_shutdown(
4129 const struct sctp_endpoint *ep,
4130 const struct sctp_association *asoc,
4131 const sctp_subtype_t type,
4132 void *arg, sctp_cmd_seq_t *commands)
4134 /* There is a single T1 timer, so we should be able to use
4135 * common function with the COOKIE-WAIT state.
4137 return sctp_sf_cookie_wait_prm_shutdown(ep, asoc, type, arg, commands);
4141 * sctp_sf_cookie_wait_prm_abort
4143 * Section: 4 Note: 2
4148 * The RFC does not explicitly address this issue, but is the route through the
4149 * state table when someone issues an abort while in COOKIE_WAIT state.
4154 sctp_disposition_t sctp_sf_cookie_wait_prm_abort(
4155 const struct sctp_endpoint *ep,
4156 const struct sctp_association *asoc,
4157 const sctp_subtype_t type,
4159 sctp_cmd_seq_t *commands)
4161 struct sctp_chunk *abort = arg;
4162 sctp_disposition_t retval;
4164 /* Stop T1-init timer */
4165 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4166 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4167 retval = SCTP_DISPOSITION_CONSUME;
4169 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4171 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4172 SCTP_STATE(SCTP_STATE_CLOSED));
4174 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4176 /* Even if we can't send the ABORT due to low memory delete the
4177 * TCB. This is a departure from our typical NOMEM handling.
4180 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4181 SCTP_ERROR(ECONNREFUSED));
4182 /* Delete the established association. */
4183 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4184 SCTP_PERR(SCTP_ERROR_USER_ABORT));
4190 * sctp_sf_cookie_echoed_prm_abort
4192 * Section: 4 Note: 3
4197 * The RFC does not explcitly address this issue, but is the route through the
4198 * state table when someone issues an abort while in COOKIE_ECHOED state.
4203 sctp_disposition_t sctp_sf_cookie_echoed_prm_abort(
4204 const struct sctp_endpoint *ep,
4205 const struct sctp_association *asoc,
4206 const sctp_subtype_t type,
4208 sctp_cmd_seq_t *commands)
4210 /* There is a single T1 timer, so we should be able to use
4211 * common function with the COOKIE-WAIT state.
4213 return sctp_sf_cookie_wait_prm_abort(ep, asoc, type, arg, commands);
4217 * sctp_sf_shutdown_pending_prm_abort
4222 * The RFC does not explicitly address this issue, but is the route through the
4223 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
4228 sctp_disposition_t sctp_sf_shutdown_pending_prm_abort(
4229 const struct sctp_endpoint *ep,
4230 const struct sctp_association *asoc,
4231 const sctp_subtype_t type,
4233 sctp_cmd_seq_t *commands)
4235 /* Stop the T5-shutdown guard timer. */
4236 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4237 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4239 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
4243 * sctp_sf_shutdown_sent_prm_abort
4248 * The RFC does not explicitly address this issue, but is the route through the
4249 * state table when someone issues an abort while in SHUTDOWN-SENT state.
4254 sctp_disposition_t sctp_sf_shutdown_sent_prm_abort(
4255 const struct sctp_endpoint *ep,
4256 const struct sctp_association *asoc,
4257 const sctp_subtype_t type,
4259 sctp_cmd_seq_t *commands)
4261 /* Stop the T2-shutdown timer. */
4262 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4263 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4265 /* Stop the T5-shutdown guard timer. */
4266 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4267 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4269 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
4273 * sctp_sf_cookie_echoed_prm_abort
4278 * The RFC does not explcitly address this issue, but is the route through the
4279 * state table when someone issues an abort while in COOKIE_ECHOED state.
4284 sctp_disposition_t sctp_sf_shutdown_ack_sent_prm_abort(
4285 const struct sctp_endpoint *ep,
4286 const struct sctp_association *asoc,
4287 const sctp_subtype_t type,
4289 sctp_cmd_seq_t *commands)
4291 /* The same T2 timer, so we should be able to use
4292 * common function with the SHUTDOWN-SENT state.
4294 return sctp_sf_shutdown_sent_prm_abort(ep, asoc, type, arg, commands);
4298 * Process the REQUESTHEARTBEAT primitive
4301 * J) Request Heartbeat
4303 * Format: REQUESTHEARTBEAT(association id, destination transport address)
4307 * Instructs the local endpoint to perform a HeartBeat on the specified
4308 * destination transport address of the given association. The returned
4309 * result should indicate whether the transmission of the HEARTBEAT
4310 * chunk to the destination address is successful.
4312 * Mandatory attributes:
4314 * o association id - local handle to the SCTP association
4316 * o destination transport address - the transport address of the
4317 * association on which a heartbeat should be issued.
4319 sctp_disposition_t sctp_sf_do_prm_requestheartbeat(
4320 const struct sctp_endpoint *ep,
4321 const struct sctp_association *asoc,
4322 const sctp_subtype_t type,
4324 sctp_cmd_seq_t *commands)
4326 return sctp_sf_heartbeat(ep, asoc, type, (struct sctp_transport *)arg,
4331 * ADDIP Section 4.1 ASCONF Chunk Procedures
4332 * When an endpoint has an ASCONF signaled change to be sent to the
4333 * remote endpoint it should do A1 to A9
4335 sctp_disposition_t sctp_sf_do_prm_asconf(const struct sctp_endpoint *ep,
4336 const struct sctp_association *asoc,
4337 const sctp_subtype_t type,
4339 sctp_cmd_seq_t *commands)
4341 struct sctp_chunk *chunk = arg;
4343 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
4344 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4345 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4346 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
4347 return SCTP_DISPOSITION_CONSUME;
4351 * Ignore the primitive event
4353 * The return value is the disposition of the primitive.
4355 sctp_disposition_t sctp_sf_ignore_primitive(
4356 const struct sctp_endpoint *ep,
4357 const struct sctp_association *asoc,
4358 const sctp_subtype_t type,
4360 sctp_cmd_seq_t *commands)
4362 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type.primitive);
4363 return SCTP_DISPOSITION_DISCARD;
4366 /***************************************************************************
4367 * These are the state functions for the OTHER events.
4368 ***************************************************************************/
4371 * Start the shutdown negotiation.
4374 * Once all its outstanding data has been acknowledged, the endpoint
4375 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
4376 * TSN Ack field the last sequential TSN it has received from the peer.
4377 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
4378 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
4379 * with the updated last sequential TSN received from its peer.
4381 * The return value is the disposition.
4383 sctp_disposition_t sctp_sf_do_9_2_start_shutdown(
4384 const struct sctp_endpoint *ep,
4385 const struct sctp_association *asoc,
4386 const sctp_subtype_t type,
4388 sctp_cmd_seq_t *commands)
4390 struct sctp_chunk *reply;
4392 /* Once all its outstanding data has been acknowledged, the
4393 * endpoint shall send a SHUTDOWN chunk to its peer including
4394 * in the Cumulative TSN Ack field the last sequential TSN it
4395 * has received from the peer.
4397 reply = sctp_make_shutdown(asoc, NULL);
4401 /* Set the transport for the SHUTDOWN chunk and the timeout for the
4402 * T2-shutdown timer.
4404 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4406 /* It shall then start the T2-shutdown timer */
4407 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4408 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4410 if (asoc->autoclose)
4411 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4412 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
4414 /* and enter the SHUTDOWN-SENT state. */
4415 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4416 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT));
4418 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4420 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4423 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
4425 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4427 return SCTP_DISPOSITION_CONSUME;
4430 return SCTP_DISPOSITION_NOMEM;
4434 * Generate a SHUTDOWN ACK now that everything is SACK'd.
4438 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4439 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
4440 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
4441 * endpoint must re-send the SHUTDOWN ACK.
4443 * The return value is the disposition.
4445 sctp_disposition_t sctp_sf_do_9_2_shutdown_ack(
4446 const struct sctp_endpoint *ep,
4447 const struct sctp_association *asoc,
4448 const sctp_subtype_t type,
4450 sctp_cmd_seq_t *commands)
4452 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
4453 struct sctp_chunk *reply;
4455 /* There are 2 ways of getting here:
4456 * 1) called in response to a SHUTDOWN chunk
4457 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
4459 * For the case (2), the arg parameter is set to NULL. We need
4460 * to check that we have a chunk before accessing it's fields.
4463 if (!sctp_vtag_verify(chunk, asoc))
4464 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
4466 /* Make sure that the SHUTDOWN chunk has a valid length. */
4467 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk_t)))
4468 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
4472 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4473 * shall send a SHUTDOWN ACK ...
4475 reply = sctp_make_shutdown_ack(asoc, chunk);
4479 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
4480 * the T2-shutdown timer.
4482 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4484 /* and start/restart a T2-shutdown timer of its own, */
4485 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4486 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4488 if (asoc->autoclose)
4489 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4490 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
4492 /* Enter the SHUTDOWN-ACK-SENT state. */
4493 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4494 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT));
4496 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4498 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4501 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
4503 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4505 return SCTP_DISPOSITION_CONSUME;
4508 return SCTP_DISPOSITION_NOMEM;
4512 * Ignore the event defined as other
4514 * The return value is the disposition of the event.
4516 sctp_disposition_t sctp_sf_ignore_other(const struct sctp_endpoint *ep,
4517 const struct sctp_association *asoc,
4518 const sctp_subtype_t type,
4520 sctp_cmd_seq_t *commands)
4522 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type.other);
4523 return SCTP_DISPOSITION_DISCARD;
4526 /************************************************************
4527 * These are the state functions for handling timeout events.
4528 ************************************************************/
4533 * Section: 6.3.3 Handle T3-rtx Expiration
4535 * Whenever the retransmission timer T3-rtx expires for a destination
4536 * address, do the following:
4539 * The return value is the disposition of the chunk.
4541 sctp_disposition_t sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint *ep,
4542 const struct sctp_association *asoc,
4543 const sctp_subtype_t type,
4545 sctp_cmd_seq_t *commands)
4547 struct sctp_transport *transport = arg;
4549 SCTP_INC_STATS(SCTP_MIB_T3_RTX_EXPIREDS);
4551 if (asoc->overall_error_count >= asoc->max_retrans) {
4552 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4553 SCTP_ERROR(ETIMEDOUT));
4554 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
4555 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4556 SCTP_PERR(SCTP_ERROR_NO_ERROR));
4557 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4558 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4559 return SCTP_DISPOSITION_DELETE_TCB;
4562 /* E1) For the destination address for which the timer
4563 * expires, adjust its ssthresh with rules defined in Section
4564 * 7.2.3 and set the cwnd <- MTU.
4567 /* E2) For the destination address for which the timer
4568 * expires, set RTO <- RTO * 2 ("back off the timer"). The
4569 * maximum value discussed in rule C7 above (RTO.max) may be
4570 * used to provide an upper bound to this doubling operation.
4573 /* E3) Determine how many of the earliest (i.e., lowest TSN)
4574 * outstanding DATA chunks for the address for which the
4575 * T3-rtx has expired will fit into a single packet, subject
4576 * to the MTU constraint for the path corresponding to the
4577 * destination transport address to which the retransmission
4578 * is being sent (this may be different from the address for
4579 * which the timer expires [see Section 6.4]). Call this
4580 * value K. Bundle and retransmit those K DATA chunks in a
4581 * single packet to the destination endpoint.
4583 * Note: Any DATA chunks that were sent to the address for
4584 * which the T3-rtx timer expired but did not fit in one MTU
4585 * (rule E3 above), should be marked for retransmission and
4586 * sent as soon as cwnd allows (normally when a SACK arrives).
4589 /* NB: Rules E4 and F1 are implicit in R1. */
4590 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport));
4592 /* Do some failure management (Section 8.2). */
4593 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
4595 return SCTP_DISPOSITION_CONSUME;
4599 * Generate delayed SACK on timeout
4601 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
4603 * The guidelines on delayed acknowledgement algorithm specified in
4604 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
4605 * acknowledgement SHOULD be generated for at least every second packet
4606 * (not every second DATA chunk) received, and SHOULD be generated
4607 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
4608 * some situations it may be beneficial for an SCTP transmitter to be
4609 * more conservative than the algorithms detailed in this document
4610 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
4611 * the following algorithms allow.
4613 sctp_disposition_t sctp_sf_do_6_2_sack(const struct sctp_endpoint *ep,
4614 const struct sctp_association *asoc,
4615 const sctp_subtype_t type,
4617 sctp_cmd_seq_t *commands)
4619 SCTP_INC_STATS(SCTP_MIB_DELAY_SACK_EXPIREDS);
4620 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
4621 return SCTP_DISPOSITION_CONSUME;
4625 * sctp_sf_t1_init_timer_expire
4627 * Section: 4 Note: 2
4632 * RFC 2960 Section 4 Notes
4633 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
4634 * and re-start the T1-init timer without changing state. This MUST
4635 * be repeated up to 'Max.Init.Retransmits' times. After that, the
4636 * endpoint MUST abort the initialization process and report the
4637 * error to SCTP user.
4643 sctp_disposition_t sctp_sf_t1_init_timer_expire(const struct sctp_endpoint *ep,
4644 const struct sctp_association *asoc,
4645 const sctp_subtype_t type,
4647 sctp_cmd_seq_t *commands)
4649 struct sctp_chunk *repl = NULL;
4650 struct sctp_bind_addr *bp;
4651 int attempts = asoc->init_err_counter + 1;
4653 SCTP_DEBUG_PRINTK("Timer T1 expired (INIT).\n");
4654 SCTP_INC_STATS(SCTP_MIB_T1_INIT_EXPIREDS);
4656 if (attempts <= asoc->max_init_attempts) {
4657 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
4658 repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0);
4660 return SCTP_DISPOSITION_NOMEM;
4662 /* Choose transport for INIT. */
4663 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
4666 /* Issue a sideeffect to do the needed accounting. */
4667 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART,
4668 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4670 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
4672 SCTP_DEBUG_PRINTK("Giving up on INIT, attempts: %d"
4673 " max_init_attempts: %d\n",
4674 attempts, asoc->max_init_attempts);
4675 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4676 SCTP_ERROR(ETIMEDOUT));
4677 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4678 SCTP_PERR(SCTP_ERROR_NO_ERROR));
4679 return SCTP_DISPOSITION_DELETE_TCB;
4682 return SCTP_DISPOSITION_CONSUME;
4686 * sctp_sf_t1_cookie_timer_expire
4688 * Section: 4 Note: 2
4693 * RFC 2960 Section 4 Notes
4694 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
4695 * COOKIE ECHO and re-start the T1-cookie timer without changing
4696 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
4697 * After that, the endpoint MUST abort the initialization process and
4698 * report the error to SCTP user.
4704 sctp_disposition_t sctp_sf_t1_cookie_timer_expire(const struct sctp_endpoint *ep,
4705 const struct sctp_association *asoc,
4706 const sctp_subtype_t type,
4708 sctp_cmd_seq_t *commands)
4710 struct sctp_chunk *repl = NULL;
4711 int attempts = asoc->init_err_counter + 1;
4713 SCTP_DEBUG_PRINTK("Timer T1 expired (COOKIE-ECHO).\n");
4714 SCTP_INC_STATS(SCTP_MIB_T1_COOKIE_EXPIREDS);
4716 if (attempts <= asoc->max_init_attempts) {
4717 repl = sctp_make_cookie_echo(asoc, NULL);
4719 return SCTP_DISPOSITION_NOMEM;
4721 /* Issue a sideeffect to do the needed accounting. */
4722 sctp_add_cmd_sf(commands, SCTP_CMD_COOKIEECHO_RESTART,
4723 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
4725 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
4727 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4728 SCTP_ERROR(ETIMEDOUT));
4729 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4730 SCTP_PERR(SCTP_ERROR_NO_ERROR));
4731 return SCTP_DISPOSITION_DELETE_TCB;
4734 return SCTP_DISPOSITION_CONSUME;
4737 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
4738 * with the updated last sequential TSN received from its peer.
4740 * An endpoint should limit the number of retransmissions of the
4741 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
4742 * If this threshold is exceeded the endpoint should destroy the TCB and
4743 * MUST report the peer endpoint unreachable to the upper layer (and
4744 * thus the association enters the CLOSED state). The reception of any
4745 * packet from its peer (i.e. as the peer sends all of its queued DATA
4746 * chunks) should clear the endpoint's retransmission count and restart
4747 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
4748 * all of its queued DATA chunks that have not yet been sent.
4750 sctp_disposition_t sctp_sf_t2_timer_expire(const struct sctp_endpoint *ep,
4751 const struct sctp_association *asoc,
4752 const sctp_subtype_t type,
4754 sctp_cmd_seq_t *commands)
4756 struct sctp_chunk *reply = NULL;
4758 SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
4759 SCTP_INC_STATS(SCTP_MIB_T2_SHUTDOWN_EXPIREDS);
4761 if (asoc->overall_error_count >= asoc->max_retrans) {
4762 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4763 SCTP_ERROR(ETIMEDOUT));
4764 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
4765 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4766 SCTP_PERR(SCTP_ERROR_NO_ERROR));
4767 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4768 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4769 return SCTP_DISPOSITION_DELETE_TCB;
4772 switch (asoc->state) {
4773 case SCTP_STATE_SHUTDOWN_SENT:
4774 reply = sctp_make_shutdown(asoc, NULL);
4777 case SCTP_STATE_SHUTDOWN_ACK_SENT:
4778 reply = sctp_make_shutdown_ack(asoc, NULL);
4789 /* Do some failure management (Section 8.2). */
4790 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
4791 SCTP_TRANSPORT(asoc->shutdown_last_sent_to));
4793 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
4794 * the T2-shutdown timer.
4796 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4798 /* Restart the T2-shutdown timer. */
4799 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4800 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4801 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4802 return SCTP_DISPOSITION_CONSUME;
4805 return SCTP_DISPOSITION_NOMEM;
4809 * ADDIP Section 4.1 ASCONF CHunk Procedures
4810 * If the T4 RTO timer expires the endpoint should do B1 to B5
4812 sctp_disposition_t sctp_sf_t4_timer_expire(
4813 const struct sctp_endpoint *ep,
4814 const struct sctp_association *asoc,
4815 const sctp_subtype_t type,
4817 sctp_cmd_seq_t *commands)
4819 struct sctp_chunk *chunk = asoc->addip_last_asconf;
4820 struct sctp_transport *transport = chunk->transport;
4822 SCTP_INC_STATS(SCTP_MIB_T4_RTO_EXPIREDS);
4824 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
4825 * detection on the appropriate destination address as defined in
4826 * RFC2960 [5] section 8.1 and 8.2.
4828 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
4830 /* Reconfig T4 timer and transport. */
4831 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
4833 /* ADDIP 4.1 B2) Increment the association error counters and perform
4834 * endpoint failure detection on the association as defined in
4835 * RFC2960 [5] section 8.1 and 8.2.
4836 * association error counter is incremented in SCTP_CMD_STRIKE.
4838 if (asoc->overall_error_count >= asoc->max_retrans) {
4839 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4840 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4841 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4842 SCTP_ERROR(ETIMEDOUT));
4843 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4844 SCTP_PERR(SCTP_ERROR_NO_ERROR));
4845 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4846 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
4847 return SCTP_DISPOSITION_ABORT;
4850 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
4851 * the ASCONF chunk was sent by doubling the RTO timer value.
4852 * This is done in SCTP_CMD_STRIKE.
4855 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
4856 * choose an alternate destination address (please refer to RFC2960
4857 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
4858 * chunk, it MUST be the same (including its serial number) as the last
4861 sctp_chunk_hold(asoc->addip_last_asconf);
4862 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4863 SCTP_CHUNK(asoc->addip_last_asconf));
4865 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
4866 * destination is selected, then the RTO used will be that of the new
4867 * destination address.
4869 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4870 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4872 return SCTP_DISPOSITION_CONSUME;
4875 /* sctpimpguide-05 Section 2.12.2
4876 * The sender of the SHUTDOWN MAY also start an overall guard timer
4877 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4878 * At the expiration of this timer the sender SHOULD abort the association
4879 * by sending an ABORT chunk.
4881 sctp_disposition_t sctp_sf_t5_timer_expire(const struct sctp_endpoint *ep,
4882 const struct sctp_association *asoc,
4883 const sctp_subtype_t type,
4885 sctp_cmd_seq_t *commands)
4887 struct sctp_chunk *reply = NULL;
4889 SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
4890 SCTP_INC_STATS(SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS);
4892 reply = sctp_make_abort(asoc, NULL, 0);
4896 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4897 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4898 SCTP_ERROR(ETIMEDOUT));
4899 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4900 SCTP_PERR(SCTP_ERROR_NO_ERROR));
4902 return SCTP_DISPOSITION_DELETE_TCB;
4904 return SCTP_DISPOSITION_NOMEM;
4907 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
4908 * the association is automatically closed by starting the shutdown process.
4909 * The work that needs to be done is same as when SHUTDOWN is initiated by
4910 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
4912 sctp_disposition_t sctp_sf_autoclose_timer_expire(
4913 const struct sctp_endpoint *ep,
4914 const struct sctp_association *asoc,
4915 const sctp_subtype_t type,
4917 sctp_cmd_seq_t *commands)
4921 SCTP_INC_STATS(SCTP_MIB_AUTOCLOSE_EXPIREDS);
4923 /* From 9.2 Shutdown of an Association
4924 * Upon receipt of the SHUTDOWN primitive from its upper
4925 * layer, the endpoint enters SHUTDOWN-PENDING state and
4926 * remains there until all outstanding data has been
4927 * acknowledged by its peer. The endpoint accepts no new data
4928 * from its upper layer, but retransmits data to the far end
4929 * if necessary to fill gaps.
4931 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4932 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
4934 /* sctpimpguide-05 Section 2.12.2
4935 * The sender of the SHUTDOWN MAY also start an overall guard timer
4936 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4938 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4939 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4940 disposition = SCTP_DISPOSITION_CONSUME;
4941 if (sctp_outq_is_empty(&asoc->outqueue)) {
4942 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
4948 /*****************************************************************************
4949 * These are sa state functions which could apply to all types of events.
4950 ****************************************************************************/
4953 * This table entry is not implemented.
4956 * (endpoint, asoc, chunk)
4958 * The return value is the disposition of the chunk.
4960 sctp_disposition_t sctp_sf_not_impl(const struct sctp_endpoint *ep,
4961 const struct sctp_association *asoc,
4962 const sctp_subtype_t type,
4964 sctp_cmd_seq_t *commands)
4966 return SCTP_DISPOSITION_NOT_IMPL;
4970 * This table entry represents a bug.
4973 * (endpoint, asoc, chunk)
4975 * The return value is the disposition of the chunk.
4977 sctp_disposition_t sctp_sf_bug(const struct sctp_endpoint *ep,
4978 const struct sctp_association *asoc,
4979 const sctp_subtype_t type,
4981 sctp_cmd_seq_t *commands)
4983 return SCTP_DISPOSITION_BUG;
4987 * This table entry represents the firing of a timer in the wrong state.
4988 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
4989 * when the association is in the wrong state. This event should
4990 * be ignored, so as to prevent any rearming of the timer.
4993 * (endpoint, asoc, chunk)
4995 * The return value is the disposition of the chunk.
4997 sctp_disposition_t sctp_sf_timer_ignore(const struct sctp_endpoint *ep,
4998 const struct sctp_association *asoc,
4999 const sctp_subtype_t type,
5001 sctp_cmd_seq_t *commands)
5003 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type.chunk);
5004 return SCTP_DISPOSITION_CONSUME;
5007 /********************************************************************
5008 * 2nd Level Abstractions
5009 ********************************************************************/
5011 /* Pull the SACK chunk based on the SACK header. */
5012 static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk)
5014 struct sctp_sackhdr *sack;
5019 /* Protect ourselves from reading too far into
5020 * the skb from a bogus sender.
5022 sack = (struct sctp_sackhdr *) chunk->skb->data;
5024 num_blocks = ntohs(sack->num_gap_ack_blocks);
5025 num_dup_tsns = ntohs(sack->num_dup_tsns);
5026 len = sizeof(struct sctp_sackhdr);
5027 len += (num_blocks + num_dup_tsns) * sizeof(__u32);
5028 if (len > chunk->skb->len)
5031 skb_pull(chunk->skb, len);
5036 /* Create an ABORT packet to be sent as a response, with the specified
5039 static struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep,
5040 const struct sctp_association *asoc,
5041 struct sctp_chunk *chunk,
5042 const void *payload,
5045 struct sctp_packet *packet;
5046 struct sctp_chunk *abort;
5048 packet = sctp_ootb_pkt_new(asoc, chunk);
5052 * The T bit will be set if the asoc is NULL.
5054 abort = sctp_make_abort(asoc, chunk, paylen);
5056 sctp_ootb_pkt_free(packet);
5060 /* Reflect vtag if T-Bit is set */
5061 if (sctp_test_T_bit(abort))
5062 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
5064 /* Add specified error causes, i.e., payload, to the
5067 sctp_addto_chunk(abort, paylen, payload);
5069 /* Set the skb to the belonging sock for accounting. */
5070 abort->skb->sk = ep->base.sk;
5072 sctp_packet_append_chunk(packet, abort);
5079 /* Allocate a packet for responding in the OOTB conditions. */
5080 static struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc,
5081 const struct sctp_chunk *chunk)
5083 struct sctp_packet *packet;
5084 struct sctp_transport *transport;
5089 /* Get the source and destination port from the inbound packet. */
5090 sport = ntohs(chunk->sctp_hdr->dest);
5091 dport = ntohs(chunk->sctp_hdr->source);
5093 /* The V-tag is going to be the same as the inbound packet if no
5094 * association exists, otherwise, use the peer's vtag.
5097 vtag = asoc->peer.i.init_tag;
5099 /* Special case the INIT and stale COOKIE_ECHO as there is no
5102 switch(chunk->chunk_hdr->type) {
5105 sctp_init_chunk_t *init;
5107 init = (sctp_init_chunk_t *)chunk->chunk_hdr;
5108 vtag = ntohl(init->init_hdr.init_tag);
5112 vtag = ntohl(chunk->sctp_hdr->vtag);
5117 /* Make a transport for the bucket, Eliza... */
5118 transport = sctp_transport_new(sctp_source(chunk), GFP_ATOMIC);
5122 /* Cache a route for the transport with the chunk's destination as
5123 * the source address.
5125 sctp_transport_route(transport, (union sctp_addr *)&chunk->dest,
5126 sctp_sk(sctp_get_ctl_sock()));
5128 packet = sctp_packet_init(&transport->packet, transport, sport, dport);
5129 packet = sctp_packet_config(packet, vtag, 0);
5137 /* Free the packet allocated earlier for responding in the OOTB condition. */
5138 void sctp_ootb_pkt_free(struct sctp_packet *packet)
5140 sctp_transport_free(packet->transport);
5143 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
5144 static void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep,
5145 const struct sctp_association *asoc,
5146 const struct sctp_chunk *chunk,
5147 sctp_cmd_seq_t *commands,
5148 struct sctp_chunk *err_chunk)
5150 struct sctp_packet *packet;
5153 packet = sctp_ootb_pkt_new(asoc, chunk);
5155 struct sctp_signed_cookie *cookie;
5157 /* Override the OOTB vtag from the cookie. */
5158 cookie = chunk->subh.cookie_hdr;
5159 packet->vtag = cookie->c.peer_vtag;
5161 /* Set the skb to the belonging sock for accounting. */
5162 err_chunk->skb->sk = ep->base.sk;
5163 sctp_packet_append_chunk(packet, err_chunk);
5164 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
5165 SCTP_PACKET(packet));
5166 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
5168 sctp_chunk_free (err_chunk);
5173 /* Process a data chunk */
5174 static int sctp_eat_data(const struct sctp_association *asoc,
5175 struct sctp_chunk *chunk,
5176 sctp_cmd_seq_t *commands)
5178 sctp_datahdr_t *data_hdr;
5179 struct sctp_chunk *err;
5181 sctp_verb_t deliver;
5185 struct sctp_tsnmap *map = (struct sctp_tsnmap *)&asoc->peer.tsn_map;
5186 struct sock *sk = asoc->base.sk;
5187 int rcvbuf_over = 0;
5189 data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *)chunk->skb->data;
5190 skb_pull(chunk->skb, sizeof(sctp_datahdr_t));
5192 tsn = ntohl(data_hdr->tsn);
5193 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn);
5195 /* ASSERT: Now skb->data is really the user data. */
5198 * If we are established, and we have used up our receive buffer
5199 * memory, think about droping the frame.
5200 * Note that we have an opportunity to improve performance here.
5201 * If we accept one chunk from an skbuff, we have to keep all the
5202 * memory of that skbuff around until the chunk is read into user
5203 * space. Therefore, once we accept 1 chunk we may as well accept all
5204 * remaining chunks in the skbuff. The data_accepted flag helps us do
5207 if ((asoc->state == SCTP_STATE_ESTABLISHED) && (!chunk->data_accepted)) {
5209 * If the receive buffer policy is 1, then each
5210 * association can allocate up to sk_rcvbuf bytes
5211 * otherwise, all the associations in aggregate
5212 * may allocate up to sk_rcvbuf bytes
5214 if (asoc->ep->rcvbuf_policy)
5215 account_value = atomic_read(&asoc->rmem_alloc);
5217 account_value = atomic_read(&sk->sk_rmem_alloc);
5218 if (account_value > sk->sk_rcvbuf) {
5220 * We need to make forward progress, even when we are
5221 * under memory pressure, so we always allow the
5222 * next tsn after the ctsn ack point to be accepted.
5223 * This lets us avoid deadlocks in which we have to
5224 * drop frames that would otherwise let us drain the
5227 if ((sctp_tsnmap_get_ctsn(map) + 1) != tsn)
5228 return SCTP_IERROR_IGNORE_TSN;
5231 * We're going to accept the frame but we should renege
5232 * to make space for it. This will send us down that
5233 * path later in this function.
5239 /* Process ECN based congestion.
5241 * Since the chunk structure is reused for all chunks within
5242 * a packet, we use ecn_ce_done to track if we've already
5243 * done CE processing for this packet.
5245 * We need to do ECN processing even if we plan to discard the
5249 if (!chunk->ecn_ce_done) {
5251 chunk->ecn_ce_done = 1;
5253 af = sctp_get_af_specific(
5254 ipver2af(chunk->skb->nh.iph->version));
5256 if (af && af->is_ce(chunk->skb) && asoc->peer.ecn_capable) {
5257 /* Do real work as sideffect. */
5258 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
5263 tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
5265 /* The TSN is too high--silently discard the chunk and
5266 * count on it getting retransmitted later.
5268 return SCTP_IERROR_HIGH_TSN;
5269 } else if (tmp > 0) {
5270 /* This is a duplicate. Record it. */
5271 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
5272 return SCTP_IERROR_DUP_TSN;
5275 /* This is a new TSN. */
5277 /* Discard if there is no room in the receive window.
5278 * Actually, allow a little bit of overflow (up to a MTU).
5280 datalen = ntohs(chunk->chunk_hdr->length);
5281 datalen -= sizeof(sctp_data_chunk_t);
5283 deliver = SCTP_CMD_CHUNK_ULP;
5285 /* Think about partial delivery. */
5286 if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) {
5288 /* Even if we don't accept this chunk there is
5291 sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL());
5294 /* Spill over rwnd a little bit. Note: While allowed, this spill over
5295 * seems a bit troublesome in that frag_point varies based on
5296 * PMTU. In cases, such as loopback, this might be a rather
5298 * NOTE: If we have a full receive buffer here, we only renege if
5299 * our receiver can still make progress without the tsn being
5300 * received. We do this because in the event that the associations
5301 * receive queue is empty we are filling a leading gap, and since
5302 * reneging moves the gap to the end of the tsn stream, we are likely
5303 * to stall again very shortly. Avoiding the renege when we fill a
5304 * leading gap is a good heuristic for avoiding such steady state
5307 if (!asoc->rwnd || asoc->rwnd_over ||
5308 (datalen > asoc->rwnd + asoc->frag_point) ||
5309 (rcvbuf_over && (!skb_queue_len(&sk->sk_receive_queue)))) {
5311 /* If this is the next TSN, consider reneging to make
5312 * room. Note: Playing nice with a confused sender. A
5313 * malicious sender can still eat up all our buffer
5314 * space and in the future we may want to detect and
5315 * do more drastic reneging.
5317 if (sctp_tsnmap_has_gap(map) &&
5318 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
5319 SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn);
5320 deliver = SCTP_CMD_RENEGE;
5322 SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
5323 "rwnd: %d\n", tsn, datalen,
5325 return SCTP_IERROR_IGNORE_TSN;
5330 * Section 3.3.10.9 No User Data (9)
5334 * No User Data: This error cause is returned to the originator of a
5335 * DATA chunk if a received DATA chunk has no user data.
5337 if (unlikely(0 == datalen)) {
5338 err = sctp_make_abort_no_data(asoc, chunk, tsn);
5340 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
5343 /* We are going to ABORT, so we might as well stop
5344 * processing the rest of the chunks in the packet.
5346 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
5347 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5348 SCTP_ERROR(ECONNABORTED));
5349 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5350 SCTP_PERR(SCTP_ERROR_NO_DATA));
5351 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
5352 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
5353 return SCTP_IERROR_NO_DATA;
5356 /* If definately accepting the DATA chunk, record its TSN, otherwise
5357 * wait for renege processing.
5359 if (SCTP_CMD_CHUNK_ULP == deliver)
5360 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
5362 chunk->data_accepted = 1;
5364 /* Note: Some chunks may get overcounted (if we drop) or overcounted
5365 * if we renege and the chunk arrives again.
5367 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
5368 SCTP_INC_STATS(SCTP_MIB_INUNORDERCHUNKS);
5370 SCTP_INC_STATS(SCTP_MIB_INORDERCHUNKS);
5372 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
5374 * If an endpoint receive a DATA chunk with an invalid stream
5375 * identifier, it shall acknowledge the reception of the DATA chunk
5376 * following the normal procedure, immediately send an ERROR chunk
5377 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
5378 * and discard the DATA chunk.
5380 if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) {
5381 err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
5383 sizeof(data_hdr->stream));
5385 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
5387 return SCTP_IERROR_BAD_STREAM;
5390 /* Send the data up to the user. Note: Schedule the
5391 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
5392 * chunk needs the updated rwnd.
5394 sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk));
5396 return SCTP_IERROR_NO_ERROR;