[POWERPC] chrp pci_ops: Use named structure member initializers
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / sctp / sm_statefuns.c
blob71cad56dd73fe62e0e1422f23cd7eb56c5f31f70
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)
18 * any later version.
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
32 * email address(es):
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>
57 #include <linux/ip.h>
58 #include <linux/ipv6.h>
59 #include <linux/net.h>
60 #include <linux/inet.h>
61 #include <net/sock.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,
71 const void *payload,
72 size_t paylen);
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,
86 void *arg,
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,
91 void *arg,
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_abort_violation(
101 const struct sctp_association *asoc,
102 void *arg,
103 sctp_cmd_seq_t *commands,
104 const __u8 *payload,
105 const size_t paylen);
107 static sctp_disposition_t sctp_sf_violation_chunklen(
108 const struct sctp_endpoint *ep,
109 const struct sctp_association *asoc,
110 const sctp_subtype_t type,
111 void *arg,
112 sctp_cmd_seq_t *commands);
114 static sctp_disposition_t sctp_sf_violation_ctsn(
115 const struct sctp_endpoint *ep,
116 const struct sctp_association *asoc,
117 const sctp_subtype_t type,
118 void *arg,
119 sctp_cmd_seq_t *commands);
121 /* Small helper function that checks if the chunk length
122 * is of the appropriate length. The 'required_length' argument
123 * is set to be the size of a specific chunk we are testing.
124 * Return Values: 1 = Valid length
125 * 0 = Invalid length
128 static inline int
129 sctp_chunk_length_valid(struct sctp_chunk *chunk,
130 __u16 required_length)
132 __u16 chunk_length = ntohs(chunk->chunk_hdr->length);
134 if (unlikely(chunk_length < required_length))
135 return 0;
137 return 1;
140 /**********************************************************
141 * These are the state functions for handling chunk events.
142 **********************************************************/
145 * Process the final SHUTDOWN COMPLETE.
147 * Section: 4 (C) (diagram), 9.2
148 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
149 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
150 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
151 * should stop the T2-shutdown timer and remove all knowledge of the
152 * association (and thus the association enters the CLOSED state).
154 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
155 * C) Rules for packet carrying SHUTDOWN COMPLETE:
156 * ...
157 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
158 * if the Verification Tag field of the packet matches its own tag and
159 * the T bit is not set
160 * OR
161 * it is set to its peer's tag and the T bit is set in the Chunk
162 * Flags.
163 * Otherwise, the receiver MUST silently discard the packet
164 * and take no further action. An endpoint MUST ignore the
165 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
167 * Inputs
168 * (endpoint, asoc, chunk)
170 * Outputs
171 * (asoc, reply_msg, msg_up, timers, counters)
173 * The return value is the disposition of the chunk.
175 sctp_disposition_t sctp_sf_do_4_C(const struct sctp_endpoint *ep,
176 const struct sctp_association *asoc,
177 const sctp_subtype_t type,
178 void *arg,
179 sctp_cmd_seq_t *commands)
181 struct sctp_chunk *chunk = arg;
182 struct sctp_ulpevent *ev;
184 /* RFC 2960 6.10 Bundling
186 * An endpoint MUST NOT bundle INIT, INIT ACK or
187 * SHUTDOWN COMPLETE with any other chunks.
189 if (!chunk->singleton)
190 return SCTP_DISPOSITION_VIOLATION;
192 if (!sctp_vtag_verify_either(chunk, asoc))
193 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
195 /* RFC 2960 10.2 SCTP-to-ULP
197 * H) SHUTDOWN COMPLETE notification
199 * When SCTP completes the shutdown procedures (section 9.2) this
200 * notification is passed to the upper layer.
202 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
203 0, 0, 0, NULL, GFP_ATOMIC);
204 if (ev)
205 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
206 SCTP_ULPEVENT(ev));
208 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
209 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
210 * not the chunk should be discarded. If the endpoint is in
211 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
212 * T2-shutdown timer and remove all knowledge of the
213 * association (and thus the association enters the CLOSED
214 * state).
216 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
217 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
219 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
220 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
222 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
223 SCTP_STATE(SCTP_STATE_CLOSED));
225 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
226 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
228 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
230 return SCTP_DISPOSITION_DELETE_TCB;
234 * Respond to a normal INIT chunk.
235 * We are the side that is being asked for an association.
237 * Section: 5.1 Normal Establishment of an Association, B
238 * B) "Z" shall respond immediately with an INIT ACK chunk. The
239 * destination IP address of the INIT ACK MUST be set to the source
240 * IP address of the INIT to which this INIT ACK is responding. In
241 * the response, besides filling in other parameters, "Z" must set the
242 * Verification Tag field to Tag_A, and also provide its own
243 * Verification Tag (Tag_Z) in the Initiate Tag field.
245 * Verification Tag: Must be 0.
247 * Inputs
248 * (endpoint, asoc, chunk)
250 * Outputs
251 * (asoc, reply_msg, msg_up, timers, counters)
253 * The return value is the disposition of the chunk.
255 sctp_disposition_t sctp_sf_do_5_1B_init(const struct sctp_endpoint *ep,
256 const struct sctp_association *asoc,
257 const sctp_subtype_t type,
258 void *arg,
259 sctp_cmd_seq_t *commands)
261 struct sctp_chunk *chunk = arg;
262 struct sctp_chunk *repl;
263 struct sctp_association *new_asoc;
264 struct sctp_chunk *err_chunk;
265 struct sctp_packet *packet;
266 sctp_unrecognized_param_t *unk_param;
267 struct sock *sk;
268 int len;
270 /* 6.10 Bundling
271 * An endpoint MUST NOT bundle INIT, INIT ACK or
272 * SHUTDOWN COMPLETE with any other chunks.
274 * IG Section 2.11.2
275 * Furthermore, we require that the receiver of an INIT chunk MUST
276 * enforce these rules by silently discarding an arriving packet
277 * with an INIT chunk that is bundled with other chunks.
279 if (!chunk->singleton)
280 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
282 /* If the packet is an OOTB packet which is temporarily on the
283 * control endpoint, respond with an ABORT.
285 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
286 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
288 sk = ep->base.sk;
289 /* If the endpoint is not listening or if the number of associations
290 * on the TCP-style socket exceed the max backlog, respond with an
291 * ABORT.
293 if (!sctp_sstate(sk, LISTENING) ||
294 (sctp_style(sk, TCP) &&
295 sk_acceptq_is_full(sk)))
296 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
298 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
299 * Tag.
301 if (chunk->sctp_hdr->vtag != 0)
302 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
304 /* Make sure that the INIT chunk has a valid length.
305 * Normally, this would cause an ABORT with a Protocol Violation
306 * error, but since we don't have an association, we'll
307 * just discard the packet.
309 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
310 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
312 /* Verify the INIT chunk before processing it. */
313 err_chunk = NULL;
314 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
315 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
316 &err_chunk)) {
317 /* This chunk contains fatal error. It is to be discarded.
318 * Send an ABORT, with causes if there is any.
320 if (err_chunk) {
321 packet = sctp_abort_pkt_new(ep, asoc, arg,
322 (__u8 *)(err_chunk->chunk_hdr) +
323 sizeof(sctp_chunkhdr_t),
324 ntohs(err_chunk->chunk_hdr->length) -
325 sizeof(sctp_chunkhdr_t));
327 sctp_chunk_free(err_chunk);
329 if (packet) {
330 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
331 SCTP_PACKET(packet));
332 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
333 return SCTP_DISPOSITION_CONSUME;
334 } else {
335 return SCTP_DISPOSITION_NOMEM;
337 } else {
338 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
339 commands);
343 /* Grab the INIT header. */
344 chunk->subh.init_hdr = (sctp_inithdr_t *)chunk->skb->data;
346 /* Tag the variable length parameters. */
347 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
349 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
350 if (!new_asoc)
351 goto nomem;
353 /* The call, sctp_process_init(), can fail on memory allocation. */
354 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
355 sctp_source(chunk),
356 (sctp_init_chunk_t *)chunk->chunk_hdr,
357 GFP_ATOMIC))
358 goto nomem_init;
360 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
362 /* If there are errors need to be reported for unknown parameters,
363 * make sure to reserve enough room in the INIT ACK for them.
365 len = 0;
366 if (err_chunk)
367 len = ntohs(err_chunk->chunk_hdr->length) -
368 sizeof(sctp_chunkhdr_t);
370 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
371 goto nomem_init;
373 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
374 if (!repl)
375 goto nomem_init;
377 /* If there are errors need to be reported for unknown parameters,
378 * include them in the outgoing INIT ACK as "Unrecognized parameter"
379 * parameter.
381 if (err_chunk) {
382 /* Get the "Unrecognized parameter" parameter(s) out of the
383 * ERROR chunk generated by sctp_verify_init(). Since the
384 * error cause code for "unknown parameter" and the
385 * "Unrecognized parameter" type is the same, we can
386 * construct the parameters in INIT ACK by copying the
387 * ERROR causes over.
389 unk_param = (sctp_unrecognized_param_t *)
390 ((__u8 *)(err_chunk->chunk_hdr) +
391 sizeof(sctp_chunkhdr_t));
392 /* Replace the cause code with the "Unrecognized parameter"
393 * parameter type.
395 sctp_addto_chunk(repl, len, unk_param);
396 sctp_chunk_free(err_chunk);
399 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
401 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
404 * Note: After sending out INIT ACK with the State Cookie parameter,
405 * "Z" MUST NOT allocate any resources, nor keep any states for the
406 * new association. Otherwise, "Z" will be vulnerable to resource
407 * attacks.
409 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
411 return SCTP_DISPOSITION_DELETE_TCB;
413 nomem_init:
414 sctp_association_free(new_asoc);
415 nomem:
416 if (err_chunk)
417 sctp_chunk_free(err_chunk);
418 return SCTP_DISPOSITION_NOMEM;
422 * Respond to a normal INIT ACK chunk.
423 * We are the side that is initiating the association.
425 * Section: 5.1 Normal Establishment of an Association, C
426 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
427 * timer and leave COOKIE-WAIT state. "A" shall then send the State
428 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
429 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
431 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
432 * DATA chunks, but it MUST be the first chunk in the packet and
433 * until the COOKIE ACK is returned the sender MUST NOT send any
434 * other packets to the peer.
436 * Verification Tag: 3.3.3
437 * If the value of the Initiate Tag in a received INIT ACK chunk is
438 * found to be 0, the receiver MUST treat it as an error and close the
439 * association by transmitting an ABORT.
441 * Inputs
442 * (endpoint, asoc, chunk)
444 * Outputs
445 * (asoc, reply_msg, msg_up, timers, counters)
447 * The return value is the disposition of the chunk.
449 sctp_disposition_t sctp_sf_do_5_1C_ack(const struct sctp_endpoint *ep,
450 const struct sctp_association *asoc,
451 const sctp_subtype_t type,
452 void *arg,
453 sctp_cmd_seq_t *commands)
455 struct sctp_chunk *chunk = arg;
456 sctp_init_chunk_t *initchunk;
457 struct sctp_chunk *err_chunk;
458 struct sctp_packet *packet;
459 sctp_error_t error;
461 if (!sctp_vtag_verify(chunk, asoc))
462 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
464 /* Make sure that the INIT-ACK chunk has a valid length */
465 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_initack_chunk_t)))
466 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
467 commands);
468 /* 6.10 Bundling
469 * An endpoint MUST NOT bundle INIT, INIT ACK or
470 * SHUTDOWN COMPLETE with any other chunks.
472 if (!chunk->singleton)
473 return SCTP_DISPOSITION_VIOLATION;
475 /* Grab the INIT header. */
476 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
478 /* Verify the INIT chunk before processing it. */
479 err_chunk = NULL;
480 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
481 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
482 &err_chunk)) {
484 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
486 /* This chunk contains fatal error. It is to be discarded.
487 * Send an ABORT, with causes if there is any.
489 if (err_chunk) {
490 packet = sctp_abort_pkt_new(ep, asoc, arg,
491 (__u8 *)(err_chunk->chunk_hdr) +
492 sizeof(sctp_chunkhdr_t),
493 ntohs(err_chunk->chunk_hdr->length) -
494 sizeof(sctp_chunkhdr_t));
496 sctp_chunk_free(err_chunk);
498 if (packet) {
499 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
500 SCTP_PACKET(packet));
501 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
502 error = SCTP_ERROR_INV_PARAM;
503 } else {
504 error = SCTP_ERROR_NO_RESOURCE;
506 } else {
507 sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
508 error = SCTP_ERROR_INV_PARAM;
510 return sctp_stop_t1_and_abort(commands, error, ECONNREFUSED,
511 asoc, chunk->transport);
514 /* Tag the variable length parameters. Note that we never
515 * convert the parameters in an INIT chunk.
517 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
519 initchunk = (sctp_init_chunk_t *) chunk->chunk_hdr;
521 sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT,
522 SCTP_PEER_INIT(initchunk));
524 /* Reset init error count upon receipt of INIT-ACK. */
525 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
527 /* 5.1 C) "A" shall stop the T1-init timer and leave
528 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
529 * timer, and enter the COOKIE-ECHOED state.
531 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
532 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
533 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
534 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
535 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
536 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED));
538 /* 5.1 C) "A" shall then send the State Cookie received in the
539 * INIT ACK chunk in a COOKIE ECHO chunk, ...
541 /* If there is any errors to report, send the ERROR chunk generated
542 * for unknown parameters as well.
544 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO,
545 SCTP_CHUNK(err_chunk));
547 return SCTP_DISPOSITION_CONSUME;
551 * Respond to a normal COOKIE ECHO chunk.
552 * We are the side that is being asked for an association.
554 * Section: 5.1 Normal Establishment of an Association, D
555 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
556 * with a COOKIE ACK chunk after building a TCB and moving to
557 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
558 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
559 * chunk MUST be the first chunk in the packet.
561 * IMPLEMENTATION NOTE: An implementation may choose to send the
562 * Communication Up notification to the SCTP user upon reception
563 * of a valid COOKIE ECHO chunk.
565 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
566 * D) Rules for packet carrying a COOKIE ECHO
568 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
569 * Initial Tag received in the INIT ACK.
571 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
573 * Inputs
574 * (endpoint, asoc, chunk)
576 * Outputs
577 * (asoc, reply_msg, msg_up, timers, counters)
579 * The return value is the disposition of the chunk.
581 sctp_disposition_t sctp_sf_do_5_1D_ce(const struct sctp_endpoint *ep,
582 const struct sctp_association *asoc,
583 const sctp_subtype_t type, void *arg,
584 sctp_cmd_seq_t *commands)
586 struct sctp_chunk *chunk = arg;
587 struct sctp_association *new_asoc;
588 sctp_init_chunk_t *peer_init;
589 struct sctp_chunk *repl;
590 struct sctp_ulpevent *ev, *ai_ev = NULL;
591 int error = 0;
592 struct sctp_chunk *err_chk_p;
594 /* If the packet is an OOTB packet which is temporarily on the
595 * control endpoint, respond with an ABORT.
597 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
598 return sctp_sf_ootb(ep, asoc, type, arg, commands);
600 /* Make sure that the COOKIE_ECHO chunk has a valid length.
601 * In this case, we check that we have enough for at least a
602 * chunk header. More detailed verification is done
603 * in sctp_unpack_cookie().
605 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
606 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
608 /* "Decode" the chunk. We have no optional parameters so we
609 * are in good shape.
611 chunk->subh.cookie_hdr =
612 (struct sctp_signed_cookie *)chunk->skb->data;
613 if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
614 sizeof(sctp_chunkhdr_t)))
615 goto nomem;
617 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
618 * "Z" will reply with a COOKIE ACK chunk after building a TCB
619 * and moving to the ESTABLISHED state.
621 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
622 &err_chk_p);
624 /* FIXME:
625 * If the re-build failed, what is the proper error path
626 * from here?
628 * [We should abort the association. --piggy]
630 if (!new_asoc) {
631 /* FIXME: Several errors are possible. A bad cookie should
632 * be silently discarded, but think about logging it too.
634 switch (error) {
635 case -SCTP_IERROR_NOMEM:
636 goto nomem;
638 case -SCTP_IERROR_STALE_COOKIE:
639 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
640 err_chk_p);
641 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
643 case -SCTP_IERROR_BAD_SIG:
644 default:
645 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
650 /* Delay state machine commands until later.
652 * Re-build the bind address for the association is done in
653 * the sctp_unpack_cookie() already.
655 /* This is a brand-new association, so these are not yet side
656 * effects--it is safe to run them here.
658 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
660 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
661 &chunk->subh.cookie_hdr->c.peer_addr,
662 peer_init, GFP_ATOMIC))
663 goto nomem_init;
665 repl = sctp_make_cookie_ack(new_asoc, chunk);
666 if (!repl)
667 goto nomem_init;
669 /* RFC 2960 5.1 Normal Establishment of an Association
671 * D) IMPLEMENTATION NOTE: An implementation may choose to
672 * send the Communication Up notification to the SCTP user
673 * upon reception of a valid COOKIE ECHO chunk.
675 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0,
676 new_asoc->c.sinit_num_ostreams,
677 new_asoc->c.sinit_max_instreams,
678 NULL, GFP_ATOMIC);
679 if (!ev)
680 goto nomem_ev;
682 /* Sockets API Draft Section 5.3.1.6
683 * When a peer sends a Adaptation Layer Indication parameter , SCTP
684 * delivers this notification to inform the application that of the
685 * peers requested adaptation layer.
687 if (new_asoc->peer.adaptation_ind) {
688 ai_ev = sctp_ulpevent_make_adaptation_indication(new_asoc,
689 GFP_ATOMIC);
690 if (!ai_ev)
691 goto nomem_aiev;
694 /* Add all the state machine commands now since we've created
695 * everything. This way we don't introduce memory corruptions
696 * during side-effect processing and correclty count established
697 * associations.
699 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
700 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
701 SCTP_STATE(SCTP_STATE_ESTABLISHED));
702 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
703 SCTP_INC_STATS(SCTP_MIB_PASSIVEESTABS);
704 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
706 if (new_asoc->autoclose)
707 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
708 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
710 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
712 /* This will send the COOKIE ACK */
713 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
715 /* Queue the ASSOC_CHANGE event */
716 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
718 /* Send up the Adaptation Layer Indication event */
719 if (ai_ev)
720 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
721 SCTP_ULPEVENT(ai_ev));
723 return SCTP_DISPOSITION_CONSUME;
725 nomem_aiev:
726 sctp_ulpevent_free(ev);
727 nomem_ev:
728 sctp_chunk_free(repl);
729 nomem_init:
730 sctp_association_free(new_asoc);
731 nomem:
732 return SCTP_DISPOSITION_NOMEM;
736 * Respond to a normal COOKIE ACK chunk.
737 * We are the side that is being asked for an association.
739 * RFC 2960 5.1 Normal Establishment of an Association
741 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
742 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
743 * timer. It may also notify its ULP about the successful
744 * establishment of the association with a Communication Up
745 * notification (see Section 10).
747 * Verification Tag:
748 * Inputs
749 * (endpoint, asoc, chunk)
751 * Outputs
752 * (asoc, reply_msg, msg_up, timers, counters)
754 * The return value is the disposition of the chunk.
756 sctp_disposition_t sctp_sf_do_5_1E_ca(const struct sctp_endpoint *ep,
757 const struct sctp_association *asoc,
758 const sctp_subtype_t type, void *arg,
759 sctp_cmd_seq_t *commands)
761 struct sctp_chunk *chunk = arg;
762 struct sctp_ulpevent *ev;
764 if (!sctp_vtag_verify(chunk, asoc))
765 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
767 /* Verify that the chunk length for the COOKIE-ACK is OK.
768 * If we don't do this, any bundled chunks may be junked.
770 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
771 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
772 commands);
774 /* Reset init error count upon receipt of COOKIE-ACK,
775 * to avoid problems with the managemement of this
776 * counter in stale cookie situations when a transition back
777 * from the COOKIE-ECHOED state to the COOKIE-WAIT
778 * state is performed.
780 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
782 /* RFC 2960 5.1 Normal Establishment of an Association
784 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
785 * from the COOKIE-ECHOED state to the ESTABLISHED state,
786 * stopping the T1-cookie timer.
788 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
789 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
790 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
791 SCTP_STATE(SCTP_STATE_ESTABLISHED));
792 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
793 SCTP_INC_STATS(SCTP_MIB_ACTIVEESTABS);
794 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
795 if (asoc->autoclose)
796 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
797 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
798 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
800 /* It may also notify its ULP about the successful
801 * establishment of the association with a Communication Up
802 * notification (see Section 10).
804 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP,
805 0, asoc->c.sinit_num_ostreams,
806 asoc->c.sinit_max_instreams,
807 NULL, GFP_ATOMIC);
809 if (!ev)
810 goto nomem;
812 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
814 /* Sockets API Draft Section 5.3.1.6
815 * When a peer sends a Adaptation Layer Indication parameter , SCTP
816 * delivers this notification to inform the application that of the
817 * peers requested adaptation layer.
819 if (asoc->peer.adaptation_ind) {
820 ev = sctp_ulpevent_make_adaptation_indication(asoc, GFP_ATOMIC);
821 if (!ev)
822 goto nomem;
824 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
825 SCTP_ULPEVENT(ev));
828 return SCTP_DISPOSITION_CONSUME;
829 nomem:
830 return SCTP_DISPOSITION_NOMEM;
833 /* Generate and sendout a heartbeat packet. */
834 static sctp_disposition_t sctp_sf_heartbeat(const struct sctp_endpoint *ep,
835 const struct sctp_association *asoc,
836 const sctp_subtype_t type,
837 void *arg,
838 sctp_cmd_seq_t *commands)
840 struct sctp_transport *transport = (struct sctp_transport *) arg;
841 struct sctp_chunk *reply;
842 sctp_sender_hb_info_t hbinfo;
843 size_t paylen = 0;
845 hbinfo.param_hdr.type = SCTP_PARAM_HEARTBEAT_INFO;
846 hbinfo.param_hdr.length = htons(sizeof(sctp_sender_hb_info_t));
847 hbinfo.daddr = transport->ipaddr;
848 hbinfo.sent_at = jiffies;
849 hbinfo.hb_nonce = transport->hb_nonce;
851 /* Send a heartbeat to our peer. */
852 paylen = sizeof(sctp_sender_hb_info_t);
853 reply = sctp_make_heartbeat(asoc, transport, &hbinfo, paylen);
854 if (!reply)
855 return SCTP_DISPOSITION_NOMEM;
857 /* Set rto_pending indicating that an RTT measurement
858 * is started with this heartbeat chunk.
860 sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING,
861 SCTP_TRANSPORT(transport));
863 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
864 return SCTP_DISPOSITION_CONSUME;
867 /* Generate a HEARTBEAT packet on the given transport. */
868 sctp_disposition_t sctp_sf_sendbeat_8_3(const struct sctp_endpoint *ep,
869 const struct sctp_association *asoc,
870 const sctp_subtype_t type,
871 void *arg,
872 sctp_cmd_seq_t *commands)
874 struct sctp_transport *transport = (struct sctp_transport *) arg;
876 if (asoc->overall_error_count >= asoc->max_retrans) {
877 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
878 SCTP_ERROR(ETIMEDOUT));
879 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
880 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
881 SCTP_PERR(SCTP_ERROR_NO_ERROR));
882 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
883 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
884 return SCTP_DISPOSITION_DELETE_TCB;
887 /* Section 3.3.5.
888 * The Sender-specific Heartbeat Info field should normally include
889 * information about the sender's current time when this HEARTBEAT
890 * chunk is sent and the destination transport address to which this
891 * HEARTBEAT is sent (see Section 8.3).
894 if (transport->param_flags & SPP_HB_ENABLE) {
895 if (SCTP_DISPOSITION_NOMEM ==
896 sctp_sf_heartbeat(ep, asoc, type, arg,
897 commands))
898 return SCTP_DISPOSITION_NOMEM;
899 /* Set transport error counter and association error counter
900 * when sending heartbeat.
902 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET,
903 SCTP_TRANSPORT(transport));
905 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE,
906 SCTP_TRANSPORT(transport));
908 return SCTP_DISPOSITION_CONSUME;
912 * Process an heartbeat request.
914 * Section: 8.3 Path Heartbeat
915 * The receiver of the HEARTBEAT should immediately respond with a
916 * HEARTBEAT ACK that contains the Heartbeat Information field copied
917 * from the received HEARTBEAT chunk.
919 * Verification Tag: 8.5 Verification Tag [Normal verification]
920 * When receiving an SCTP packet, the endpoint MUST ensure that the
921 * value in the Verification Tag field of the received SCTP packet
922 * matches its own Tag. If the received Verification Tag value does not
923 * match the receiver's own tag value, the receiver shall silently
924 * discard the packet and shall not process it any further except for
925 * those cases listed in Section 8.5.1 below.
927 * Inputs
928 * (endpoint, asoc, chunk)
930 * Outputs
931 * (asoc, reply_msg, msg_up, timers, counters)
933 * The return value is the disposition of the chunk.
935 sctp_disposition_t sctp_sf_beat_8_3(const struct sctp_endpoint *ep,
936 const struct sctp_association *asoc,
937 const sctp_subtype_t type,
938 void *arg,
939 sctp_cmd_seq_t *commands)
941 struct sctp_chunk *chunk = arg;
942 struct sctp_chunk *reply;
943 size_t paylen = 0;
945 if (!sctp_vtag_verify(chunk, asoc))
946 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
948 /* Make sure that the HEARTBEAT chunk has a valid length. */
949 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t)))
950 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
951 commands);
953 /* 8.3 The receiver of the HEARTBEAT should immediately
954 * respond with a HEARTBEAT ACK that contains the Heartbeat
955 * Information field copied from the received HEARTBEAT chunk.
957 chunk->subh.hb_hdr = (sctp_heartbeathdr_t *) chunk->skb->data;
958 paylen = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t);
959 if (!pskb_pull(chunk->skb, paylen))
960 goto nomem;
962 reply = sctp_make_heartbeat_ack(asoc, chunk,
963 chunk->subh.hb_hdr, paylen);
964 if (!reply)
965 goto nomem;
967 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
968 return SCTP_DISPOSITION_CONSUME;
970 nomem:
971 return SCTP_DISPOSITION_NOMEM;
975 * Process the returning HEARTBEAT ACK.
977 * Section: 8.3 Path Heartbeat
978 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
979 * should clear the error counter of the destination transport
980 * address to which the HEARTBEAT was sent, and mark the destination
981 * transport address as active if it is not so marked. The endpoint may
982 * optionally report to the upper layer when an inactive destination
983 * address is marked as active due to the reception of the latest
984 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
985 * clear the association overall error count as well (as defined
986 * in section 8.1).
988 * The receiver of the HEARTBEAT ACK should also perform an RTT
989 * measurement for that destination transport address using the time
990 * value carried in the HEARTBEAT ACK chunk.
992 * Verification Tag: 8.5 Verification Tag [Normal verification]
994 * Inputs
995 * (endpoint, asoc, chunk)
997 * Outputs
998 * (asoc, reply_msg, msg_up, timers, counters)
1000 * The return value is the disposition of the chunk.
1002 sctp_disposition_t sctp_sf_backbeat_8_3(const struct sctp_endpoint *ep,
1003 const struct sctp_association *asoc,
1004 const sctp_subtype_t type,
1005 void *arg,
1006 sctp_cmd_seq_t *commands)
1008 struct sctp_chunk *chunk = arg;
1009 union sctp_addr from_addr;
1010 struct sctp_transport *link;
1011 sctp_sender_hb_info_t *hbinfo;
1012 unsigned long max_interval;
1014 if (!sctp_vtag_verify(chunk, asoc))
1015 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1017 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1018 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t)))
1019 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1020 commands);
1022 hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data;
1023 /* Make sure that the length of the parameter is what we expect */
1024 if (ntohs(hbinfo->param_hdr.length) !=
1025 sizeof(sctp_sender_hb_info_t)) {
1026 return SCTP_DISPOSITION_DISCARD;
1029 from_addr = hbinfo->daddr;
1030 link = sctp_assoc_lookup_paddr(asoc, &from_addr);
1032 /* This should never happen, but lets log it if so. */
1033 if (unlikely(!link)) {
1034 if (from_addr.sa.sa_family == AF_INET6) {
1035 printk(KERN_WARNING
1036 "%s association %p could not find address "
1037 NIP6_FMT "\n",
1038 __FUNCTION__,
1039 asoc,
1040 NIP6(from_addr.v6.sin6_addr));
1041 } else {
1042 printk(KERN_WARNING
1043 "%s association %p could not find address "
1044 NIPQUAD_FMT "\n",
1045 __FUNCTION__,
1046 asoc,
1047 NIPQUAD(from_addr.v4.sin_addr.s_addr));
1049 return SCTP_DISPOSITION_DISCARD;
1052 /* Validate the 64-bit random nonce. */
1053 if (hbinfo->hb_nonce != link->hb_nonce)
1054 return SCTP_DISPOSITION_DISCARD;
1056 max_interval = link->hbinterval + link->rto;
1058 /* Check if the timestamp looks valid. */
1059 if (time_after(hbinfo->sent_at, jiffies) ||
1060 time_after(jiffies, hbinfo->sent_at + max_interval)) {
1061 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp"
1062 "received for transport: %p\n",
1063 __FUNCTION__, link);
1064 return SCTP_DISPOSITION_DISCARD;
1067 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1068 * the HEARTBEAT should clear the error counter of the
1069 * destination transport address to which the HEARTBEAT was
1070 * sent and mark the destination transport address as active if
1071 * it is not so marked.
1073 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link));
1075 return SCTP_DISPOSITION_CONSUME;
1078 /* Helper function to send out an abort for the restart
1079 * condition.
1081 static int sctp_sf_send_restart_abort(union sctp_addr *ssa,
1082 struct sctp_chunk *init,
1083 sctp_cmd_seq_t *commands)
1085 int len;
1086 struct sctp_packet *pkt;
1087 union sctp_addr_param *addrparm;
1088 struct sctp_errhdr *errhdr;
1089 struct sctp_endpoint *ep;
1090 char buffer[sizeof(struct sctp_errhdr)+sizeof(union sctp_addr_param)];
1091 struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family);
1093 /* Build the error on the stack. We are way to malloc crazy
1094 * throughout the code today.
1096 errhdr = (struct sctp_errhdr *)buffer;
1097 addrparm = (union sctp_addr_param *)errhdr->variable;
1099 /* Copy into a parm format. */
1100 len = af->to_addr_param(ssa, addrparm);
1101 len += sizeof(sctp_errhdr_t);
1103 errhdr->cause = SCTP_ERROR_RESTART;
1104 errhdr->length = htons(len);
1106 /* Assign to the control socket. */
1107 ep = sctp_sk((sctp_get_ctl_sock()))->ep;
1109 /* Association is NULL since this may be a restart attack and we
1110 * want to send back the attacker's vtag.
1112 pkt = sctp_abort_pkt_new(ep, NULL, init, errhdr, len);
1114 if (!pkt)
1115 goto out;
1116 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt));
1118 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1120 /* Discard the rest of the inbound packet. */
1121 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
1123 out:
1124 /* Even if there is no memory, treat as a failure so
1125 * the packet will get dropped.
1127 return 0;
1130 /* A restart is occurring, check to make sure no new addresses
1131 * are being added as we may be under a takeover attack.
1133 static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc,
1134 const struct sctp_association *asoc,
1135 struct sctp_chunk *init,
1136 sctp_cmd_seq_t *commands)
1138 struct sctp_transport *new_addr, *addr;
1139 struct list_head *pos, *pos2;
1140 int found;
1142 /* Implementor's Guide - Sectin 5.2.2
1143 * ...
1144 * Before responding the endpoint MUST check to see if the
1145 * unexpected INIT adds new addresses to the association. If new
1146 * addresses are added to the association, the endpoint MUST respond
1147 * with an ABORT..
1150 /* Search through all current addresses and make sure
1151 * we aren't adding any new ones.
1153 new_addr = NULL;
1154 found = 0;
1156 list_for_each(pos, &new_asoc->peer.transport_addr_list) {
1157 new_addr = list_entry(pos, struct sctp_transport, transports);
1158 found = 0;
1159 list_for_each(pos2, &asoc->peer.transport_addr_list) {
1160 addr = list_entry(pos2, struct sctp_transport,
1161 transports);
1162 if (sctp_cmp_addr_exact(&new_addr->ipaddr,
1163 &addr->ipaddr)) {
1164 found = 1;
1165 break;
1168 if (!found)
1169 break;
1172 /* If a new address was added, ABORT the sender. */
1173 if (!found && new_addr) {
1174 sctp_sf_send_restart_abort(&new_addr->ipaddr, init, commands);
1177 /* Return success if all addresses were found. */
1178 return found;
1181 /* Populate the verification/tie tags based on overlapping INIT
1182 * scenario.
1184 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1186 static void sctp_tietags_populate(struct sctp_association *new_asoc,
1187 const struct sctp_association *asoc)
1189 switch (asoc->state) {
1191 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1193 case SCTP_STATE_COOKIE_WAIT:
1194 new_asoc->c.my_vtag = asoc->c.my_vtag;
1195 new_asoc->c.my_ttag = asoc->c.my_vtag;
1196 new_asoc->c.peer_ttag = 0;
1197 break;
1199 case SCTP_STATE_COOKIE_ECHOED:
1200 new_asoc->c.my_vtag = asoc->c.my_vtag;
1201 new_asoc->c.my_ttag = asoc->c.my_vtag;
1202 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1203 break;
1205 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1206 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1208 default:
1209 new_asoc->c.my_ttag = asoc->c.my_vtag;
1210 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1211 break;
1214 /* Other parameters for the endpoint SHOULD be copied from the
1215 * existing parameters of the association (e.g. number of
1216 * outbound streams) into the INIT ACK and cookie.
1218 new_asoc->rwnd = asoc->rwnd;
1219 new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams;
1220 new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams;
1221 new_asoc->c.initial_tsn = asoc->c.initial_tsn;
1225 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1226 * handling action.
1228 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1230 * Returns value representing action to be taken. These action values
1231 * correspond to Action/Description values in RFC 2960, Table 2.
1233 static char sctp_tietags_compare(struct sctp_association *new_asoc,
1234 const struct sctp_association *asoc)
1236 /* In this case, the peer may have restarted. */
1237 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1238 (asoc->c.peer_vtag != new_asoc->c.peer_vtag) &&
1239 (asoc->c.my_vtag == new_asoc->c.my_ttag) &&
1240 (asoc->c.peer_vtag == new_asoc->c.peer_ttag))
1241 return 'A';
1243 /* Collision case B. */
1244 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1245 ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) ||
1246 (0 == asoc->c.peer_vtag))) {
1247 return 'B';
1250 /* Collision case D. */
1251 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1252 (asoc->c.peer_vtag == new_asoc->c.peer_vtag))
1253 return 'D';
1255 /* Collision case C. */
1256 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1257 (asoc->c.peer_vtag == new_asoc->c.peer_vtag) &&
1258 (0 == new_asoc->c.my_ttag) &&
1259 (0 == new_asoc->c.peer_ttag))
1260 return 'C';
1262 /* No match to any of the special cases; discard this packet. */
1263 return 'E';
1266 /* Common helper routine for both duplicate and simulataneous INIT
1267 * chunk handling.
1269 static sctp_disposition_t sctp_sf_do_unexpected_init(
1270 const struct sctp_endpoint *ep,
1271 const struct sctp_association *asoc,
1272 const sctp_subtype_t type,
1273 void *arg, sctp_cmd_seq_t *commands)
1275 sctp_disposition_t retval;
1276 struct sctp_chunk *chunk = arg;
1277 struct sctp_chunk *repl;
1278 struct sctp_association *new_asoc;
1279 struct sctp_chunk *err_chunk;
1280 struct sctp_packet *packet;
1281 sctp_unrecognized_param_t *unk_param;
1282 int len;
1284 /* 6.10 Bundling
1285 * An endpoint MUST NOT bundle INIT, INIT ACK or
1286 * SHUTDOWN COMPLETE with any other chunks.
1288 * IG Section 2.11.2
1289 * Furthermore, we require that the receiver of an INIT chunk MUST
1290 * enforce these rules by silently discarding an arriving packet
1291 * with an INIT chunk that is bundled with other chunks.
1293 if (!chunk->singleton)
1294 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1296 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1297 * Tag.
1299 if (chunk->sctp_hdr->vtag != 0)
1300 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
1302 /* Make sure that the INIT chunk has a valid length.
1303 * In this case, we generate a protocol violation since we have
1304 * an association established.
1306 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
1307 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1308 commands);
1309 /* Grab the INIT header. */
1310 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
1312 /* Tag the variable length parameters. */
1313 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
1315 /* Verify the INIT chunk before processing it. */
1316 err_chunk = NULL;
1317 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
1318 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
1319 &err_chunk)) {
1320 /* This chunk contains fatal error. It is to be discarded.
1321 * Send an ABORT, with causes if there is any.
1323 if (err_chunk) {
1324 packet = sctp_abort_pkt_new(ep, asoc, arg,
1325 (__u8 *)(err_chunk->chunk_hdr) +
1326 sizeof(sctp_chunkhdr_t),
1327 ntohs(err_chunk->chunk_hdr->length) -
1328 sizeof(sctp_chunkhdr_t));
1330 if (packet) {
1331 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
1332 SCTP_PACKET(packet));
1333 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1334 retval = SCTP_DISPOSITION_CONSUME;
1335 } else {
1336 retval = SCTP_DISPOSITION_NOMEM;
1338 goto cleanup;
1339 } else {
1340 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
1341 commands);
1346 * Other parameters for the endpoint SHOULD be copied from the
1347 * existing parameters of the association (e.g. number of
1348 * outbound streams) into the INIT ACK and cookie.
1349 * FIXME: We are copying parameters from the endpoint not the
1350 * association.
1352 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
1353 if (!new_asoc)
1354 goto nomem;
1356 /* In the outbound INIT ACK the endpoint MUST copy its current
1357 * Verification Tag and Peers Verification tag into a reserved
1358 * place (local tie-tag and per tie-tag) within the state cookie.
1360 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1361 sctp_source(chunk),
1362 (sctp_init_chunk_t *)chunk->chunk_hdr,
1363 GFP_ATOMIC))
1364 goto nomem;
1366 /* Make sure no new addresses are being added during the
1367 * restart. Do not do this check for COOKIE-WAIT state,
1368 * since there are no peer addresses to check against.
1369 * Upon return an ABORT will have been sent if needed.
1371 if (!sctp_state(asoc, COOKIE_WAIT)) {
1372 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
1373 commands)) {
1374 retval = SCTP_DISPOSITION_CONSUME;
1375 goto nomem_retval;
1379 sctp_tietags_populate(new_asoc, asoc);
1381 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1383 /* If there are errors need to be reported for unknown parameters,
1384 * make sure to reserve enough room in the INIT ACK for them.
1386 len = 0;
1387 if (err_chunk) {
1388 len = ntohs(err_chunk->chunk_hdr->length) -
1389 sizeof(sctp_chunkhdr_t);
1392 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
1393 goto nomem;
1395 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
1396 if (!repl)
1397 goto nomem;
1399 /* If there are errors need to be reported for unknown parameters,
1400 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1401 * parameter.
1403 if (err_chunk) {
1404 /* Get the "Unrecognized parameter" parameter(s) out of the
1405 * ERROR chunk generated by sctp_verify_init(). Since the
1406 * error cause code for "unknown parameter" and the
1407 * "Unrecognized parameter" type is the same, we can
1408 * construct the parameters in INIT ACK by copying the
1409 * ERROR causes over.
1411 unk_param = (sctp_unrecognized_param_t *)
1412 ((__u8 *)(err_chunk->chunk_hdr) +
1413 sizeof(sctp_chunkhdr_t));
1414 /* Replace the cause code with the "Unrecognized parameter"
1415 * parameter type.
1417 sctp_addto_chunk(repl, len, unk_param);
1420 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1421 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1424 * Note: After sending out INIT ACK with the State Cookie parameter,
1425 * "Z" MUST NOT allocate any resources for this new association.
1426 * Otherwise, "Z" will be vulnerable to resource attacks.
1428 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1429 retval = SCTP_DISPOSITION_CONSUME;
1431 return retval;
1433 nomem:
1434 retval = SCTP_DISPOSITION_NOMEM;
1435 nomem_retval:
1436 if (new_asoc)
1437 sctp_association_free(new_asoc);
1438 cleanup:
1439 if (err_chunk)
1440 sctp_chunk_free(err_chunk);
1441 return retval;
1445 * Handle simultanous INIT.
1446 * This means we started an INIT and then we got an INIT request from
1447 * our peer.
1449 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1450 * This usually indicates an initialization collision, i.e., each
1451 * endpoint is attempting, at about the same time, to establish an
1452 * association with the other endpoint.
1454 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1455 * endpoint MUST respond with an INIT ACK using the same parameters it
1456 * sent in its original INIT chunk (including its Verification Tag,
1457 * unchanged). These original parameters are combined with those from the
1458 * newly received INIT chunk. The endpoint shall also generate a State
1459 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1460 * INIT to calculate the State Cookie.
1462 * After that, the endpoint MUST NOT change its state, the T1-init
1463 * timer shall be left running and the corresponding TCB MUST NOT be
1464 * destroyed. The normal procedures for handling State Cookies when
1465 * a TCB exists will resolve the duplicate INITs to a single association.
1467 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1468 * its Tie-Tags with the Tag information of itself and its peer (see
1469 * section 5.2.2 for a description of the Tie-Tags).
1471 * Verification Tag: Not explicit, but an INIT can not have a valid
1472 * verification tag, so we skip the check.
1474 * Inputs
1475 * (endpoint, asoc, chunk)
1477 * Outputs
1478 * (asoc, reply_msg, msg_up, timers, counters)
1480 * The return value is the disposition of the chunk.
1482 sctp_disposition_t sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint *ep,
1483 const struct sctp_association *asoc,
1484 const sctp_subtype_t type,
1485 void *arg,
1486 sctp_cmd_seq_t *commands)
1488 /* Call helper to do the real work for both simulataneous and
1489 * duplicate INIT chunk handling.
1491 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1495 * Handle duplicated INIT messages. These are usually delayed
1496 * restransmissions.
1498 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1499 * COOKIE-ECHOED and COOKIE-WAIT
1501 * Unless otherwise stated, upon reception of an unexpected INIT for
1502 * this association, the endpoint shall generate an INIT ACK with a
1503 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1504 * current Verification Tag and peer's Verification Tag into a reserved
1505 * place within the state cookie. We shall refer to these locations as
1506 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1507 * containing this INIT ACK MUST carry a Verification Tag value equal to
1508 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1509 * MUST contain a new Initiation Tag (randomly generated see Section
1510 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1511 * existing parameters of the association (e.g. number of outbound
1512 * streams) into the INIT ACK and cookie.
1514 * After sending out the INIT ACK, the endpoint shall take no further
1515 * actions, i.e., the existing association, including its current state,
1516 * and the corresponding TCB MUST NOT be changed.
1518 * Note: Only when a TCB exists and the association is not in a COOKIE-
1519 * WAIT state are the Tie-Tags populated. For a normal association INIT
1520 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1521 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1522 * State Cookie are populated as specified in section 5.2.1.
1524 * Verification Tag: Not specified, but an INIT has no way of knowing
1525 * what the verification tag could be, so we ignore it.
1527 * Inputs
1528 * (endpoint, asoc, chunk)
1530 * Outputs
1531 * (asoc, reply_msg, msg_up, timers, counters)
1533 * The return value is the disposition of the chunk.
1535 sctp_disposition_t sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint *ep,
1536 const struct sctp_association *asoc,
1537 const sctp_subtype_t type,
1538 void *arg,
1539 sctp_cmd_seq_t *commands)
1541 /* Call helper to do the real work for both simulataneous and
1542 * duplicate INIT chunk handling.
1544 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1549 * Unexpected INIT-ACK handler.
1551 * Section 5.2.3
1552 * If an INIT ACK received by an endpoint in any state other than the
1553 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1554 * An unexpected INIT ACK usually indicates the processing of an old or
1555 * duplicated INIT chunk.
1557 sctp_disposition_t sctp_sf_do_5_2_3_initack(const struct sctp_endpoint *ep,
1558 const struct sctp_association *asoc,
1559 const sctp_subtype_t type,
1560 void *arg, sctp_cmd_seq_t *commands)
1562 /* Per the above section, we'll discard the chunk if we have an
1563 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1565 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
1566 return sctp_sf_ootb(ep, asoc, type, arg, commands);
1567 else
1568 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
1571 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1573 * Section 5.2.4
1574 * A) In this case, the peer may have restarted.
1576 static sctp_disposition_t sctp_sf_do_dupcook_a(const struct sctp_endpoint *ep,
1577 const struct sctp_association *asoc,
1578 struct sctp_chunk *chunk,
1579 sctp_cmd_seq_t *commands,
1580 struct sctp_association *new_asoc)
1582 sctp_init_chunk_t *peer_init;
1583 struct sctp_ulpevent *ev;
1584 struct sctp_chunk *repl;
1585 struct sctp_chunk *err;
1586 sctp_disposition_t disposition;
1588 /* new_asoc is a brand-new association, so these are not yet
1589 * side effects--it is safe to run them here.
1591 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1593 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1594 sctp_source(chunk), peer_init,
1595 GFP_ATOMIC))
1596 goto nomem;
1598 /* Make sure no new addresses are being added during the
1599 * restart. Though this is a pretty complicated attack
1600 * since you'd have to get inside the cookie.
1602 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) {
1603 return SCTP_DISPOSITION_CONSUME;
1606 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1607 * the peer has restarted (Action A), it MUST NOT setup a new
1608 * association but instead resend the SHUTDOWN ACK and send an ERROR
1609 * chunk with a "Cookie Received while Shutting Down" error cause to
1610 * its peer.
1612 if (sctp_state(asoc, SHUTDOWN_ACK_SENT)) {
1613 disposition = sctp_sf_do_9_2_reshutack(ep, asoc,
1614 SCTP_ST_CHUNK(chunk->chunk_hdr->type),
1615 chunk, commands);
1616 if (SCTP_DISPOSITION_NOMEM == disposition)
1617 goto nomem;
1619 err = sctp_make_op_error(asoc, chunk,
1620 SCTP_ERROR_COOKIE_IN_SHUTDOWN,
1621 NULL, 0);
1622 if (err)
1623 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1624 SCTP_CHUNK(err));
1626 return SCTP_DISPOSITION_CONSUME;
1629 /* For now, fail any unsent/unacked data. Consider the optional
1630 * choice of resending of this data.
1632 sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL());
1634 repl = sctp_make_cookie_ack(new_asoc, chunk);
1635 if (!repl)
1636 goto nomem;
1638 /* Report association restart to upper layer. */
1639 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0,
1640 new_asoc->c.sinit_num_ostreams,
1641 new_asoc->c.sinit_max_instreams,
1642 NULL, GFP_ATOMIC);
1643 if (!ev)
1644 goto nomem_ev;
1646 /* Update the content of current association. */
1647 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1648 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1649 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1650 return SCTP_DISPOSITION_CONSUME;
1652 nomem_ev:
1653 sctp_chunk_free(repl);
1654 nomem:
1655 return SCTP_DISPOSITION_NOMEM;
1658 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1660 * Section 5.2.4
1661 * B) In this case, both sides may be attempting to start an association
1662 * at about the same time but the peer endpoint started its INIT
1663 * after responding to the local endpoint's INIT
1665 /* This case represents an initialization collision. */
1666 static sctp_disposition_t sctp_sf_do_dupcook_b(const struct sctp_endpoint *ep,
1667 const struct sctp_association *asoc,
1668 struct sctp_chunk *chunk,
1669 sctp_cmd_seq_t *commands,
1670 struct sctp_association *new_asoc)
1672 sctp_init_chunk_t *peer_init;
1673 struct sctp_chunk *repl;
1675 /* new_asoc is a brand-new association, so these are not yet
1676 * side effects--it is safe to run them here.
1678 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1679 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1680 sctp_source(chunk), peer_init,
1681 GFP_ATOMIC))
1682 goto nomem;
1684 /* Update the content of current association. */
1685 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1686 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1687 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1688 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
1689 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
1691 repl = sctp_make_cookie_ack(new_asoc, chunk);
1692 if (!repl)
1693 goto nomem;
1695 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1696 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1698 /* RFC 2960 5.1 Normal Establishment of an Association
1700 * D) IMPLEMENTATION NOTE: An implementation may choose to
1701 * send the Communication Up notification to the SCTP user
1702 * upon reception of a valid COOKIE ECHO chunk.
1704 * Sadly, this needs to be implemented as a side-effect, because
1705 * we are not guaranteed to have set the association id of the real
1706 * association and so these notifications need to be delayed until
1707 * the association id is allocated.
1710 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_CHANGE, SCTP_U8(SCTP_COMM_UP));
1712 /* Sockets API Draft Section 5.3.1.6
1713 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1714 * delivers this notification to inform the application that of the
1715 * peers requested adaptation layer.
1717 * This also needs to be done as a side effect for the same reason as
1718 * above.
1720 if (asoc->peer.adaptation_ind)
1721 sctp_add_cmd_sf(commands, SCTP_CMD_ADAPTATION_IND, SCTP_NULL());
1723 return SCTP_DISPOSITION_CONSUME;
1725 nomem:
1726 return SCTP_DISPOSITION_NOMEM;
1729 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1731 * Section 5.2.4
1732 * C) In this case, the local endpoint's cookie has arrived late.
1733 * Before it arrived, the local endpoint sent an INIT and received an
1734 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1735 * but a new tag of its own.
1737 /* This case represents an initialization collision. */
1738 static sctp_disposition_t sctp_sf_do_dupcook_c(const struct sctp_endpoint *ep,
1739 const struct sctp_association *asoc,
1740 struct sctp_chunk *chunk,
1741 sctp_cmd_seq_t *commands,
1742 struct sctp_association *new_asoc)
1744 /* The cookie should be silently discarded.
1745 * The endpoint SHOULD NOT change states and should leave
1746 * any timers running.
1748 return SCTP_DISPOSITION_DISCARD;
1751 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1753 * Section 5.2.4
1755 * D) When both local and remote tags match the endpoint should always
1756 * enter the ESTABLISHED state, if it has not already done so.
1758 /* This case represents an initialization collision. */
1759 static sctp_disposition_t sctp_sf_do_dupcook_d(const struct sctp_endpoint *ep,
1760 const struct sctp_association *asoc,
1761 struct sctp_chunk *chunk,
1762 sctp_cmd_seq_t *commands,
1763 struct sctp_association *new_asoc)
1765 struct sctp_ulpevent *ev = NULL, *ai_ev = NULL;
1766 struct sctp_chunk *repl;
1768 /* Clarification from Implementor's Guide:
1769 * D) When both local and remote tags match the endpoint should
1770 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1771 * It should stop any cookie timer that may be running and send
1772 * a COOKIE ACK.
1775 /* Don't accidentally move back into established state. */
1776 if (asoc->state < SCTP_STATE_ESTABLISHED) {
1777 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1778 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
1779 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1780 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1781 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
1782 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START,
1783 SCTP_NULL());
1785 /* RFC 2960 5.1 Normal Establishment of an Association
1787 * D) IMPLEMENTATION NOTE: An implementation may choose
1788 * to send the Communication Up notification to the
1789 * SCTP user upon reception of a valid COOKIE
1790 * ECHO chunk.
1792 ev = sctp_ulpevent_make_assoc_change(asoc, 0,
1793 SCTP_COMM_UP, 0,
1794 asoc->c.sinit_num_ostreams,
1795 asoc->c.sinit_max_instreams,
1796 NULL, GFP_ATOMIC);
1797 if (!ev)
1798 goto nomem;
1800 /* Sockets API Draft Section 5.3.1.6
1801 * When a peer sends a Adaptation Layer Indication parameter,
1802 * SCTP delivers this notification to inform the application
1803 * that of the peers requested adaptation layer.
1805 if (asoc->peer.adaptation_ind) {
1806 ai_ev = sctp_ulpevent_make_adaptation_indication(asoc,
1807 GFP_ATOMIC);
1808 if (!ai_ev)
1809 goto nomem;
1813 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1815 repl = sctp_make_cookie_ack(new_asoc, chunk);
1816 if (!repl)
1817 goto nomem;
1819 if (ev)
1820 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1821 SCTP_ULPEVENT(ev));
1822 if (ai_ev)
1823 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1824 SCTP_ULPEVENT(ai_ev));
1826 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1827 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1829 return SCTP_DISPOSITION_CONSUME;
1831 nomem:
1832 if (ai_ev)
1833 sctp_ulpevent_free(ai_ev);
1834 if (ev)
1835 sctp_ulpevent_free(ev);
1836 return SCTP_DISPOSITION_NOMEM;
1840 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1841 * chunk was retransmitted and then delayed in the network.
1843 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1845 * Verification Tag: None. Do cookie validation.
1847 * Inputs
1848 * (endpoint, asoc, chunk)
1850 * Outputs
1851 * (asoc, reply_msg, msg_up, timers, counters)
1853 * The return value is the disposition of the chunk.
1855 sctp_disposition_t sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint *ep,
1856 const struct sctp_association *asoc,
1857 const sctp_subtype_t type,
1858 void *arg,
1859 sctp_cmd_seq_t *commands)
1861 sctp_disposition_t retval;
1862 struct sctp_chunk *chunk = arg;
1863 struct sctp_association *new_asoc;
1864 int error = 0;
1865 char action;
1866 struct sctp_chunk *err_chk_p;
1868 /* Make sure that the chunk has a valid length from the protocol
1869 * perspective. In this case check to make sure we have at least
1870 * enough for the chunk header. Cookie length verification is
1871 * done later.
1873 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
1874 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1875 commands);
1877 /* "Decode" the chunk. We have no optional parameters so we
1878 * are in good shape.
1880 chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data;
1881 if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
1882 sizeof(sctp_chunkhdr_t)))
1883 goto nomem;
1885 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
1886 * of a duplicate COOKIE ECHO match the Verification Tags of the
1887 * current association, consider the State Cookie valid even if
1888 * the lifespan is exceeded.
1890 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
1891 &err_chk_p);
1893 /* FIXME:
1894 * If the re-build failed, what is the proper error path
1895 * from here?
1897 * [We should abort the association. --piggy]
1899 if (!new_asoc) {
1900 /* FIXME: Several errors are possible. A bad cookie should
1901 * be silently discarded, but think about logging it too.
1903 switch (error) {
1904 case -SCTP_IERROR_NOMEM:
1905 goto nomem;
1907 case -SCTP_IERROR_STALE_COOKIE:
1908 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
1909 err_chk_p);
1910 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1911 case -SCTP_IERROR_BAD_SIG:
1912 default:
1913 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1917 /* Compare the tie_tag in cookie with the verification tag of
1918 * current association.
1920 action = sctp_tietags_compare(new_asoc, asoc);
1922 switch (action) {
1923 case 'A': /* Association restart. */
1924 retval = sctp_sf_do_dupcook_a(ep, asoc, chunk, commands,
1925 new_asoc);
1926 break;
1928 case 'B': /* Collision case B. */
1929 retval = sctp_sf_do_dupcook_b(ep, asoc, chunk, commands,
1930 new_asoc);
1931 break;
1933 case 'C': /* Collision case C. */
1934 retval = sctp_sf_do_dupcook_c(ep, asoc, chunk, commands,
1935 new_asoc);
1936 break;
1938 case 'D': /* Collision case D. */
1939 retval = sctp_sf_do_dupcook_d(ep, asoc, chunk, commands,
1940 new_asoc);
1941 break;
1943 default: /* Discard packet for all others. */
1944 retval = sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1945 break;
1948 /* Delete the tempory new association. */
1949 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1950 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1952 return retval;
1954 nomem:
1955 return SCTP_DISPOSITION_NOMEM;
1959 * Process an ABORT. (SHUTDOWN-PENDING state)
1961 * See sctp_sf_do_9_1_abort().
1963 sctp_disposition_t sctp_sf_shutdown_pending_abort(
1964 const struct sctp_endpoint *ep,
1965 const struct sctp_association *asoc,
1966 const sctp_subtype_t type,
1967 void *arg,
1968 sctp_cmd_seq_t *commands)
1970 struct sctp_chunk *chunk = arg;
1972 if (!sctp_vtag_verify_either(chunk, asoc))
1973 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1975 /* Make sure that the ABORT chunk has a valid length.
1976 * Since this is an ABORT chunk, we have to discard it
1977 * because of the following text:
1978 * RFC 2960, Section 3.3.7
1979 * If an endpoint receives an ABORT with a format error or for an
1980 * association that doesn't exist, it MUST silently discard it.
1981 * Becasue the length is "invalid", we can't really discard just
1982 * as we do not know its true length. So, to be safe, discard the
1983 * packet.
1985 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
1986 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1988 /* Stop the T5-shutdown guard timer. */
1989 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1990 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
1992 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
1996 * Process an ABORT. (SHUTDOWN-SENT state)
1998 * See sctp_sf_do_9_1_abort().
2000 sctp_disposition_t sctp_sf_shutdown_sent_abort(const struct sctp_endpoint *ep,
2001 const struct sctp_association *asoc,
2002 const sctp_subtype_t type,
2003 void *arg,
2004 sctp_cmd_seq_t *commands)
2006 struct sctp_chunk *chunk = arg;
2008 if (!sctp_vtag_verify_either(chunk, asoc))
2009 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2011 /* Make sure that the ABORT chunk has a valid length.
2012 * Since this is an ABORT chunk, we have to discard it
2013 * because of the following text:
2014 * RFC 2960, Section 3.3.7
2015 * If an endpoint receives an ABORT with a format error or for an
2016 * association that doesn't exist, it MUST silently discard it.
2017 * Becasue the length is "invalid", we can't really discard just
2018 * as we do not know its true length. So, to be safe, discard the
2019 * packet.
2021 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2022 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2024 /* Stop the T2-shutdown timer. */
2025 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2026 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2028 /* Stop the T5-shutdown guard timer. */
2029 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2030 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
2032 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
2036 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2038 * See sctp_sf_do_9_1_abort().
2040 sctp_disposition_t sctp_sf_shutdown_ack_sent_abort(
2041 const struct sctp_endpoint *ep,
2042 const struct sctp_association *asoc,
2043 const sctp_subtype_t type,
2044 void *arg,
2045 sctp_cmd_seq_t *commands)
2047 /* The same T2 timer, so we should be able to use
2048 * common function with the SHUTDOWN-SENT state.
2050 return sctp_sf_shutdown_sent_abort(ep, asoc, type, arg, commands);
2054 * Handle an Error received in COOKIE_ECHOED state.
2056 * Only handle the error type of stale COOKIE Error, the other errors will
2057 * be ignored.
2059 * Inputs
2060 * (endpoint, asoc, chunk)
2062 * Outputs
2063 * (asoc, reply_msg, msg_up, timers, counters)
2065 * The return value is the disposition of the chunk.
2067 sctp_disposition_t sctp_sf_cookie_echoed_err(const struct sctp_endpoint *ep,
2068 const struct sctp_association *asoc,
2069 const sctp_subtype_t type,
2070 void *arg,
2071 sctp_cmd_seq_t *commands)
2073 struct sctp_chunk *chunk = arg;
2074 sctp_errhdr_t *err;
2076 if (!sctp_vtag_verify(chunk, asoc))
2077 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2079 /* Make sure that the ERROR chunk has a valid length.
2080 * The parameter walking depends on this as well.
2082 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t)))
2083 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2084 commands);
2086 /* Process the error here */
2087 /* FUTURE FIXME: When PR-SCTP related and other optional
2088 * parms are emitted, this will have to change to handle multiple
2089 * errors.
2091 sctp_walk_errors(err, chunk->chunk_hdr) {
2092 if (SCTP_ERROR_STALE_COOKIE == err->cause)
2093 return sctp_sf_do_5_2_6_stale(ep, asoc, type,
2094 arg, commands);
2097 /* It is possible to have malformed error causes, and that
2098 * will cause us to end the walk early. However, since
2099 * we are discarding the packet, there should be no adverse
2100 * affects.
2102 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2106 * Handle a Stale COOKIE Error
2108 * Section: 5.2.6 Handle Stale COOKIE Error
2109 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2110 * one of the following three alternatives.
2111 * ...
2112 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2113 * Preservative parameter requesting an extension to the lifetime of
2114 * the State Cookie. When calculating the time extension, an
2115 * implementation SHOULD use the RTT information measured based on the
2116 * previous COOKIE ECHO / ERROR exchange, and should add no more
2117 * than 1 second beyond the measured RTT, due to long State Cookie
2118 * lifetimes making the endpoint more subject to a replay attack.
2120 * Verification Tag: Not explicit, but safe to ignore.
2122 * Inputs
2123 * (endpoint, asoc, chunk)
2125 * Outputs
2126 * (asoc, reply_msg, msg_up, timers, counters)
2128 * The return value is the disposition of the chunk.
2130 static sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep,
2131 const struct sctp_association *asoc,
2132 const sctp_subtype_t type,
2133 void *arg,
2134 sctp_cmd_seq_t *commands)
2136 struct sctp_chunk *chunk = arg;
2137 time_t stale;
2138 sctp_cookie_preserve_param_t bht;
2139 sctp_errhdr_t *err;
2140 struct sctp_chunk *reply;
2141 struct sctp_bind_addr *bp;
2142 int attempts = asoc->init_err_counter + 1;
2144 if (attempts > asoc->max_init_attempts) {
2145 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
2146 SCTP_ERROR(ETIMEDOUT));
2147 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2148 SCTP_PERR(SCTP_ERROR_STALE_COOKIE));
2149 return SCTP_DISPOSITION_DELETE_TCB;
2152 err = (sctp_errhdr_t *)(chunk->skb->data);
2154 /* When calculating the time extension, an implementation
2155 * SHOULD use the RTT information measured based on the
2156 * previous COOKIE ECHO / ERROR exchange, and should add no
2157 * more than 1 second beyond the measured RTT, due to long
2158 * State Cookie lifetimes making the endpoint more subject to
2159 * a replay attack.
2160 * Measure of Staleness's unit is usec. (1/1000000 sec)
2161 * Suggested Cookie Life-span Increment's unit is msec.
2162 * (1/1000 sec)
2163 * In general, if you use the suggested cookie life, the value
2164 * found in the field of measure of staleness should be doubled
2165 * to give ample time to retransmit the new cookie and thus
2166 * yield a higher probability of success on the reattempt.
2168 stale = ntohl(*(__be32 *)((u8 *)err + sizeof(sctp_errhdr_t)));
2169 stale = (stale * 2) / 1000;
2171 bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE;
2172 bht.param_hdr.length = htons(sizeof(bht));
2173 bht.lifespan_increment = htonl(stale);
2175 /* Build that new INIT chunk. */
2176 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
2177 reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht));
2178 if (!reply)
2179 goto nomem;
2181 sctp_addto_chunk(reply, sizeof(bht), &bht);
2183 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2184 sctp_add_cmd_sf(commands, SCTP_CMD_CLEAR_INIT_TAG, SCTP_NULL());
2186 /* Stop pending T3-rtx and heartbeat timers */
2187 sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL());
2188 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
2190 /* Delete non-primary peer ip addresses since we are transitioning
2191 * back to the COOKIE-WAIT state
2193 sctp_add_cmd_sf(commands, SCTP_CMD_DEL_NON_PRIMARY, SCTP_NULL());
2195 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2196 * resend
2198 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN,
2199 SCTP_TRANSPORT(asoc->peer.primary_path));
2201 /* Cast away the const modifier, as we want to just
2202 * rerun it through as a sideffect.
2204 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_INC, SCTP_NULL());
2206 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2207 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
2208 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2209 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
2210 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
2211 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2213 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2215 return SCTP_DISPOSITION_CONSUME;
2217 nomem:
2218 return SCTP_DISPOSITION_NOMEM;
2222 * Process an ABORT.
2224 * Section: 9.1
2225 * After checking the Verification Tag, the receiving endpoint shall
2226 * remove the association from its record, and shall report the
2227 * termination to its upper layer.
2229 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2230 * B) Rules for packet carrying ABORT:
2232 * - The endpoint shall always fill in the Verification Tag field of the
2233 * outbound packet with the destination endpoint's tag value if it
2234 * is known.
2236 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2237 * MUST follow the procedure described in Section 8.4.
2239 * - The receiver MUST accept the packet if the Verification Tag
2240 * matches either its own tag, OR the tag of its peer. Otherwise, the
2241 * receiver MUST silently discard the packet and take no further
2242 * action.
2244 * Inputs
2245 * (endpoint, asoc, chunk)
2247 * Outputs
2248 * (asoc, reply_msg, msg_up, timers, counters)
2250 * The return value is the disposition of the chunk.
2252 sctp_disposition_t sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep,
2253 const struct sctp_association *asoc,
2254 const sctp_subtype_t type,
2255 void *arg,
2256 sctp_cmd_seq_t *commands)
2258 struct sctp_chunk *chunk = arg;
2259 unsigned len;
2260 __be16 error = SCTP_ERROR_NO_ERROR;
2262 if (!sctp_vtag_verify_either(chunk, asoc))
2263 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2265 /* Make sure that the ABORT chunk has a valid length.
2266 * Since this is an ABORT chunk, we have to discard it
2267 * because of the following text:
2268 * RFC 2960, Section 3.3.7
2269 * If an endpoint receives an ABORT with a format error or for an
2270 * association that doesn't exist, it MUST silently discard it.
2271 * Becasue the length is "invalid", we can't really discard just
2272 * as we do not know its true length. So, to be safe, discard the
2273 * packet.
2275 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2276 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2278 /* See if we have an error cause code in the chunk. */
2279 len = ntohs(chunk->chunk_hdr->length);
2280 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2281 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2283 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNRESET));
2284 /* ASSOC_FAILED will DELETE_TCB. */
2285 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_PERR(error));
2286 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
2287 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
2289 return SCTP_DISPOSITION_ABORT;
2293 * Process an ABORT. (COOKIE-WAIT state)
2295 * See sctp_sf_do_9_1_abort() above.
2297 sctp_disposition_t sctp_sf_cookie_wait_abort(const struct sctp_endpoint *ep,
2298 const struct sctp_association *asoc,
2299 const sctp_subtype_t type,
2300 void *arg,
2301 sctp_cmd_seq_t *commands)
2303 struct sctp_chunk *chunk = arg;
2304 unsigned len;
2305 __be16 error = SCTP_ERROR_NO_ERROR;
2307 if (!sctp_vtag_verify_either(chunk, asoc))
2308 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2310 /* Make sure that the ABORT chunk has a valid length.
2311 * Since this is an ABORT chunk, we have to discard it
2312 * because of the following text:
2313 * RFC 2960, Section 3.3.7
2314 * If an endpoint receives an ABORT with a format error or for an
2315 * association that doesn't exist, it MUST silently discard it.
2316 * Becasue the length is "invalid", we can't really discard just
2317 * as we do not know its true length. So, to be safe, discard the
2318 * packet.
2320 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2321 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2323 /* See if we have an error cause code in the chunk. */
2324 len = ntohs(chunk->chunk_hdr->length);
2325 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2326 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2328 return sctp_stop_t1_and_abort(commands, error, ECONNREFUSED, asoc,
2329 chunk->transport);
2333 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2335 sctp_disposition_t sctp_sf_cookie_wait_icmp_abort(const struct sctp_endpoint *ep,
2336 const struct sctp_association *asoc,
2337 const sctp_subtype_t type,
2338 void *arg,
2339 sctp_cmd_seq_t *commands)
2341 return sctp_stop_t1_and_abort(commands, SCTP_ERROR_NO_ERROR,
2342 ENOPROTOOPT, asoc,
2343 (struct sctp_transport *)arg);
2347 * Process an ABORT. (COOKIE-ECHOED state)
2349 sctp_disposition_t sctp_sf_cookie_echoed_abort(const struct sctp_endpoint *ep,
2350 const struct sctp_association *asoc,
2351 const sctp_subtype_t type,
2352 void *arg,
2353 sctp_cmd_seq_t *commands)
2355 /* There is a single T1 timer, so we should be able to use
2356 * common function with the COOKIE-WAIT state.
2358 return sctp_sf_cookie_wait_abort(ep, asoc, type, arg, commands);
2362 * Stop T1 timer and abort association with "INIT failed".
2364 * This is common code called by several sctp_sf_*_abort() functions above.
2366 static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands,
2367 __be16 error, int sk_err,
2368 const struct sctp_association *asoc,
2369 struct sctp_transport *transport)
2371 SCTP_DEBUG_PRINTK("ABORT received (INIT).\n");
2372 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2373 SCTP_STATE(SCTP_STATE_CLOSED));
2374 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
2375 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2376 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2377 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(sk_err));
2378 /* CMD_INIT_FAILED will DELETE_TCB. */
2379 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2380 SCTP_PERR(error));
2381 return SCTP_DISPOSITION_ABORT;
2385 * sctp_sf_do_9_2_shut
2387 * Section: 9.2
2388 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2389 * - enter the SHUTDOWN-RECEIVED state,
2391 * - stop accepting new data from its SCTP user
2393 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2394 * that all its outstanding DATA chunks have been received by the
2395 * SHUTDOWN sender.
2397 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2398 * send a SHUTDOWN in response to a ULP request. And should discard
2399 * subsequent SHUTDOWN chunks.
2401 * If there are still outstanding DATA chunks left, the SHUTDOWN
2402 * receiver shall continue to follow normal data transmission
2403 * procedures defined in Section 6 until all outstanding DATA chunks
2404 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2405 * new data from its SCTP user.
2407 * Verification Tag: 8.5 Verification Tag [Normal verification]
2409 * Inputs
2410 * (endpoint, asoc, chunk)
2412 * Outputs
2413 * (asoc, reply_msg, msg_up, timers, counters)
2415 * The return value is the disposition of the chunk.
2417 sctp_disposition_t sctp_sf_do_9_2_shutdown(const struct sctp_endpoint *ep,
2418 const struct sctp_association *asoc,
2419 const sctp_subtype_t type,
2420 void *arg,
2421 sctp_cmd_seq_t *commands)
2423 struct sctp_chunk *chunk = arg;
2424 sctp_shutdownhdr_t *sdh;
2425 sctp_disposition_t disposition;
2426 struct sctp_ulpevent *ev;
2428 if (!sctp_vtag_verify(chunk, asoc))
2429 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2431 /* Make sure that the SHUTDOWN chunk has a valid length. */
2432 if (!sctp_chunk_length_valid(chunk,
2433 sizeof(struct sctp_shutdown_chunk_t)))
2434 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2435 commands);
2437 /* Convert the elaborate header. */
2438 sdh = (sctp_shutdownhdr_t *)chunk->skb->data;
2439 skb_pull(chunk->skb, sizeof(sctp_shutdownhdr_t));
2440 chunk->subh.shutdown_hdr = sdh;
2442 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2443 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2444 * inform the application that it should cease sending data.
2446 ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC);
2447 if (!ev) {
2448 disposition = SCTP_DISPOSITION_NOMEM;
2449 goto out;
2451 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
2453 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2454 * - enter the SHUTDOWN-RECEIVED state,
2455 * - stop accepting new data from its SCTP user
2457 * [This is implicit in the new state.]
2459 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2460 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED));
2461 disposition = SCTP_DISPOSITION_CONSUME;
2463 if (sctp_outq_is_empty(&asoc->outqueue)) {
2464 disposition = sctp_sf_do_9_2_shutdown_ack(ep, asoc, type,
2465 arg, commands);
2468 if (SCTP_DISPOSITION_NOMEM == disposition)
2469 goto out;
2471 /* - verify, by checking the Cumulative TSN Ack field of the
2472 * chunk, that all its outstanding DATA chunks have been
2473 * received by the SHUTDOWN sender.
2475 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
2476 SCTP_BE32(chunk->subh.shutdown_hdr->cum_tsn_ack));
2478 out:
2479 return disposition;
2482 /* RFC 2960 9.2
2483 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2484 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2485 * transport addresses (either in the IP addresses or in the INIT chunk)
2486 * that belong to this association, it should discard the INIT chunk and
2487 * retransmit the SHUTDOWN ACK chunk.
2489 sctp_disposition_t sctp_sf_do_9_2_reshutack(const struct sctp_endpoint *ep,
2490 const struct sctp_association *asoc,
2491 const sctp_subtype_t type,
2492 void *arg,
2493 sctp_cmd_seq_t *commands)
2495 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
2496 struct sctp_chunk *reply;
2498 /* Since we are not going to really process this INIT, there
2499 * is no point in verifying chunk boundries. Just generate
2500 * the SHUTDOWN ACK.
2502 reply = sctp_make_shutdown_ack(asoc, chunk);
2503 if (NULL == reply)
2504 goto nomem;
2506 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2507 * the T2-SHUTDOWN timer.
2509 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
2511 /* and restart the T2-shutdown timer. */
2512 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2513 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2515 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2517 return SCTP_DISPOSITION_CONSUME;
2518 nomem:
2519 return SCTP_DISPOSITION_NOMEM;
2523 * sctp_sf_do_ecn_cwr
2525 * Section: Appendix A: Explicit Congestion Notification
2527 * CWR:
2529 * RFC 2481 details a specific bit for a sender to send in the header of
2530 * its next outbound TCP segment to indicate to its peer that it has
2531 * reduced its congestion window. This is termed the CWR bit. For
2532 * SCTP the same indication is made by including the CWR chunk.
2533 * This chunk contains one data element, i.e. the TSN number that
2534 * was sent in the ECNE chunk. This element represents the lowest
2535 * TSN number in the datagram that was originally marked with the
2536 * CE bit.
2538 * Verification Tag: 8.5 Verification Tag [Normal verification]
2539 * Inputs
2540 * (endpoint, asoc, chunk)
2542 * Outputs
2543 * (asoc, reply_msg, msg_up, timers, counters)
2545 * The return value is the disposition of the chunk.
2547 sctp_disposition_t sctp_sf_do_ecn_cwr(const struct sctp_endpoint *ep,
2548 const struct sctp_association *asoc,
2549 const sctp_subtype_t type,
2550 void *arg,
2551 sctp_cmd_seq_t *commands)
2553 sctp_cwrhdr_t *cwr;
2554 struct sctp_chunk *chunk = arg;
2555 u32 lowest_tsn;
2557 if (!sctp_vtag_verify(chunk, asoc))
2558 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2560 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t)))
2561 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2562 commands);
2564 cwr = (sctp_cwrhdr_t *) chunk->skb->data;
2565 skb_pull(chunk->skb, sizeof(sctp_cwrhdr_t));
2567 lowest_tsn = ntohl(cwr->lowest_tsn);
2569 /* Does this CWR ack the last sent congestion notification? */
2570 if (TSN_lte(asoc->last_ecne_tsn, lowest_tsn)) {
2571 /* Stop sending ECNE. */
2572 sctp_add_cmd_sf(commands,
2573 SCTP_CMD_ECN_CWR,
2574 SCTP_U32(lowest_tsn));
2576 return SCTP_DISPOSITION_CONSUME;
2580 * sctp_sf_do_ecne
2582 * Section: Appendix A: Explicit Congestion Notification
2584 * ECN-Echo
2586 * RFC 2481 details a specific bit for a receiver to send back in its
2587 * TCP acknowledgements to notify the sender of the Congestion
2588 * Experienced (CE) bit having arrived from the network. For SCTP this
2589 * same indication is made by including the ECNE chunk. This chunk
2590 * contains one data element, i.e. the lowest TSN associated with the IP
2591 * datagram marked with the CE bit.....
2593 * Verification Tag: 8.5 Verification Tag [Normal verification]
2594 * Inputs
2595 * (endpoint, asoc, chunk)
2597 * Outputs
2598 * (asoc, reply_msg, msg_up, timers, counters)
2600 * The return value is the disposition of the chunk.
2602 sctp_disposition_t sctp_sf_do_ecne(const struct sctp_endpoint *ep,
2603 const struct sctp_association *asoc,
2604 const sctp_subtype_t type,
2605 void *arg,
2606 sctp_cmd_seq_t *commands)
2608 sctp_ecnehdr_t *ecne;
2609 struct sctp_chunk *chunk = arg;
2611 if (!sctp_vtag_verify(chunk, asoc))
2612 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2614 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t)))
2615 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2616 commands);
2618 ecne = (sctp_ecnehdr_t *) chunk->skb->data;
2619 skb_pull(chunk->skb, sizeof(sctp_ecnehdr_t));
2621 /* If this is a newer ECNE than the last CWR packet we sent out */
2622 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE,
2623 SCTP_U32(ntohl(ecne->lowest_tsn)));
2625 return SCTP_DISPOSITION_CONSUME;
2629 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2631 * The SCTP endpoint MUST always acknowledge the reception of each valid
2632 * DATA chunk.
2634 * The guidelines on delayed acknowledgement algorithm specified in
2635 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2636 * acknowledgement SHOULD be generated for at least every second packet
2637 * (not every second DATA chunk) received, and SHOULD be generated within
2638 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2639 * situations it may be beneficial for an SCTP transmitter to be more
2640 * conservative than the algorithms detailed in this document allow.
2641 * However, an SCTP transmitter MUST NOT be more aggressive than the
2642 * following algorithms allow.
2644 * A SCTP receiver MUST NOT generate more than one SACK for every
2645 * incoming packet, other than to update the offered window as the
2646 * receiving application consumes new data.
2648 * Verification Tag: 8.5 Verification Tag [Normal verification]
2650 * Inputs
2651 * (endpoint, asoc, chunk)
2653 * Outputs
2654 * (asoc, reply_msg, msg_up, timers, counters)
2656 * The return value is the disposition of the chunk.
2658 sctp_disposition_t sctp_sf_eat_data_6_2(const struct sctp_endpoint *ep,
2659 const struct sctp_association *asoc,
2660 const sctp_subtype_t type,
2661 void *arg,
2662 sctp_cmd_seq_t *commands)
2664 struct sctp_chunk *chunk = arg;
2665 int error;
2667 if (!sctp_vtag_verify(chunk, asoc)) {
2668 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2669 SCTP_NULL());
2670 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2673 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t)))
2674 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2675 commands);
2677 error = sctp_eat_data(asoc, chunk, commands );
2678 switch (error) {
2679 case SCTP_IERROR_NO_ERROR:
2680 break;
2681 case SCTP_IERROR_HIGH_TSN:
2682 case SCTP_IERROR_BAD_STREAM:
2683 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
2684 goto discard_noforce;
2685 case SCTP_IERROR_DUP_TSN:
2686 case SCTP_IERROR_IGNORE_TSN:
2687 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
2688 goto discard_force;
2689 case SCTP_IERROR_NO_DATA:
2690 goto consume;
2691 default:
2692 BUG();
2695 if (asoc->autoclose) {
2696 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2697 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
2700 /* If this is the last chunk in a packet, we need to count it
2701 * toward sack generation. Note that we need to SACK every
2702 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2703 * THEM. We elect to NOT generate SACK's if the chunk fails
2704 * the verification tag test.
2706 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2708 * The SCTP endpoint MUST always acknowledge the reception of
2709 * each valid DATA chunk.
2711 * The guidelines on delayed acknowledgement algorithm
2712 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2713 * Specifically, an acknowledgement SHOULD be generated for at
2714 * least every second packet (not every second DATA chunk)
2715 * received, and SHOULD be generated within 200 ms of the
2716 * arrival of any unacknowledged DATA chunk. In some
2717 * situations it may be beneficial for an SCTP transmitter to
2718 * be more conservative than the algorithms detailed in this
2719 * document allow. However, an SCTP transmitter MUST NOT be
2720 * more aggressive than the following algorithms allow.
2722 if (chunk->end_of_packet)
2723 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2725 return SCTP_DISPOSITION_CONSUME;
2727 discard_force:
2728 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2730 * When a packet arrives with duplicate DATA chunk(s) and with
2731 * no new DATA chunk(s), the endpoint MUST immediately send a
2732 * SACK with no delay. If a packet arrives with duplicate
2733 * DATA chunk(s) bundled with new DATA chunks, the endpoint
2734 * MAY immediately send a SACK. Normally receipt of duplicate
2735 * DATA chunks will occur when the original SACK chunk was lost
2736 * and the peer's RTO has expired. The duplicate TSN number(s)
2737 * SHOULD be reported in the SACK as duplicate.
2739 /* In our case, we split the MAY SACK advice up whether or not
2740 * the last chunk is a duplicate.'
2742 if (chunk->end_of_packet)
2743 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2744 return SCTP_DISPOSITION_DISCARD;
2746 discard_noforce:
2747 if (chunk->end_of_packet)
2748 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2750 return SCTP_DISPOSITION_DISCARD;
2751 consume:
2752 return SCTP_DISPOSITION_CONSUME;
2757 * sctp_sf_eat_data_fast_4_4
2759 * Section: 4 (4)
2760 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
2761 * DATA chunks without delay.
2763 * Verification Tag: 8.5 Verification Tag [Normal verification]
2764 * Inputs
2765 * (endpoint, asoc, chunk)
2767 * Outputs
2768 * (asoc, reply_msg, msg_up, timers, counters)
2770 * The return value is the disposition of the chunk.
2772 sctp_disposition_t sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint *ep,
2773 const struct sctp_association *asoc,
2774 const sctp_subtype_t type,
2775 void *arg,
2776 sctp_cmd_seq_t *commands)
2778 struct sctp_chunk *chunk = arg;
2779 int error;
2781 if (!sctp_vtag_verify(chunk, asoc)) {
2782 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2783 SCTP_NULL());
2784 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2787 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t)))
2788 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2789 commands);
2791 error = sctp_eat_data(asoc, chunk, commands );
2792 switch (error) {
2793 case SCTP_IERROR_NO_ERROR:
2794 case SCTP_IERROR_HIGH_TSN:
2795 case SCTP_IERROR_DUP_TSN:
2796 case SCTP_IERROR_IGNORE_TSN:
2797 case SCTP_IERROR_BAD_STREAM:
2798 break;
2799 case SCTP_IERROR_NO_DATA:
2800 goto consume;
2801 default:
2802 BUG();
2805 /* Go a head and force a SACK, since we are shutting down. */
2807 /* Implementor's Guide.
2809 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
2810 * respond to each received packet containing one or more DATA chunk(s)
2811 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
2813 if (chunk->end_of_packet) {
2814 /* We must delay the chunk creation since the cumulative
2815 * TSN has not been updated yet.
2817 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
2818 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2819 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2820 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2823 consume:
2824 return SCTP_DISPOSITION_CONSUME;
2828 * Section: 6.2 Processing a Received SACK
2829 * D) Any time a SACK arrives, the endpoint performs the following:
2831 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
2832 * then drop the SACK. Since Cumulative TSN Ack is monotonically
2833 * increasing, a SACK whose Cumulative TSN Ack is less than the
2834 * Cumulative TSN Ack Point indicates an out-of-order SACK.
2836 * ii) Set rwnd equal to the newly received a_rwnd minus the number
2837 * of bytes still outstanding after processing the Cumulative TSN Ack
2838 * and the Gap Ack Blocks.
2840 * iii) If the SACK is missing a TSN that was previously
2841 * acknowledged via a Gap Ack Block (e.g., the data receiver
2842 * reneged on the data), then mark the corresponding DATA chunk
2843 * as available for retransmit: Mark it as missing for fast
2844 * retransmit as described in Section 7.2.4 and if no retransmit
2845 * timer is running for the destination address to which the DATA
2846 * chunk was originally transmitted, then T3-rtx is started for
2847 * that destination address.
2849 * Verification Tag: 8.5 Verification Tag [Normal verification]
2851 * Inputs
2852 * (endpoint, asoc, chunk)
2854 * Outputs
2855 * (asoc, reply_msg, msg_up, timers, counters)
2857 * The return value is the disposition of the chunk.
2859 sctp_disposition_t sctp_sf_eat_sack_6_2(const struct sctp_endpoint *ep,
2860 const struct sctp_association *asoc,
2861 const sctp_subtype_t type,
2862 void *arg,
2863 sctp_cmd_seq_t *commands)
2865 struct sctp_chunk *chunk = arg;
2866 sctp_sackhdr_t *sackh;
2867 __u32 ctsn;
2869 if (!sctp_vtag_verify(chunk, asoc))
2870 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2872 /* Make sure that the SACK chunk has a valid length. */
2873 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_sack_chunk_t)))
2874 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2875 commands);
2877 /* Pull the SACK chunk from the data buffer */
2878 sackh = sctp_sm_pull_sack(chunk);
2879 /* Was this a bogus SACK? */
2880 if (!sackh)
2881 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2882 chunk->subh.sack_hdr = sackh;
2883 ctsn = ntohl(sackh->cum_tsn_ack);
2885 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
2886 * Ack Point, then drop the SACK. Since Cumulative TSN
2887 * Ack is monotonically increasing, a SACK whose
2888 * Cumulative TSN Ack is less than the Cumulative TSN Ack
2889 * Point indicates an out-of-order SACK.
2891 if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
2892 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn);
2893 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc->ctsn_ack_point);
2894 return SCTP_DISPOSITION_DISCARD;
2897 /* If Cumulative TSN Ack beyond the max tsn currently
2898 * send, terminating the association and respond to the
2899 * sender with an ABORT.
2901 if (!TSN_lt(ctsn, asoc->next_tsn))
2902 return sctp_sf_violation_ctsn(ep, asoc, type, arg, commands);
2904 /* Return this SACK for further processing. */
2905 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_SACKH(sackh));
2907 /* Note: We do the rest of the work on the PROCESS_SACK
2908 * sideeffect.
2910 return SCTP_DISPOSITION_CONSUME;
2914 * Generate an ABORT in response to a packet.
2916 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
2918 * 8) The receiver should respond to the sender of the OOTB packet with
2919 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
2920 * MUST fill in the Verification Tag field of the outbound packet
2921 * with the value found in the Verification Tag field of the OOTB
2922 * packet and set the T-bit in the Chunk Flags to indicate that the
2923 * Verification Tag is reflected. After sending this ABORT, the
2924 * receiver of the OOTB packet shall discard the OOTB packet and take
2925 * no further action.
2927 * Verification Tag:
2929 * The return value is the disposition of the chunk.
2931 sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep,
2932 const struct sctp_association *asoc,
2933 const sctp_subtype_t type,
2934 void *arg,
2935 sctp_cmd_seq_t *commands)
2937 struct sctp_packet *packet = NULL;
2938 struct sctp_chunk *chunk = arg;
2939 struct sctp_chunk *abort;
2941 packet = sctp_ootb_pkt_new(asoc, chunk);
2943 if (packet) {
2944 /* Make an ABORT. The T bit will be set if the asoc
2945 * is NULL.
2947 abort = sctp_make_abort(asoc, chunk, 0);
2948 if (!abort) {
2949 sctp_ootb_pkt_free(packet);
2950 return SCTP_DISPOSITION_NOMEM;
2953 /* Reflect vtag if T-Bit is set */
2954 if (sctp_test_T_bit(abort))
2955 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
2957 /* Set the skb to the belonging sock for accounting. */
2958 abort->skb->sk = ep->base.sk;
2960 sctp_packet_append_chunk(packet, abort);
2962 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
2963 SCTP_PACKET(packet));
2965 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
2967 return SCTP_DISPOSITION_CONSUME;
2970 return SCTP_DISPOSITION_NOMEM;
2974 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
2975 * event as ULP notification for each cause included in the chunk.
2977 * API 5.3.1.3 - SCTP_REMOTE_ERROR
2979 * The return value is the disposition of the chunk.
2981 sctp_disposition_t sctp_sf_operr_notify(const struct sctp_endpoint *ep,
2982 const struct sctp_association *asoc,
2983 const sctp_subtype_t type,
2984 void *arg,
2985 sctp_cmd_seq_t *commands)
2987 struct sctp_chunk *chunk = arg;
2988 struct sctp_ulpevent *ev;
2990 if (!sctp_vtag_verify(chunk, asoc))
2991 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2993 /* Make sure that the ERROR chunk has a valid length. */
2994 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t)))
2995 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2996 commands);
2998 while (chunk->chunk_end > chunk->skb->data) {
2999 ev = sctp_ulpevent_make_remote_error(asoc, chunk, 0,
3000 GFP_ATOMIC);
3001 if (!ev)
3002 goto nomem;
3004 if (!sctp_add_cmd(commands, SCTP_CMD_EVENT_ULP,
3005 SCTP_ULPEVENT(ev))) {
3006 sctp_ulpevent_free(ev);
3007 goto nomem;
3010 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR,
3011 SCTP_CHUNK(chunk));
3013 return SCTP_DISPOSITION_CONSUME;
3015 nomem:
3016 return SCTP_DISPOSITION_NOMEM;
3020 * Process an inbound SHUTDOWN ACK.
3022 * From Section 9.2:
3023 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3024 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3025 * peer, and remove all record of the association.
3027 * The return value is the disposition.
3029 sctp_disposition_t sctp_sf_do_9_2_final(const struct sctp_endpoint *ep,
3030 const struct sctp_association *asoc,
3031 const sctp_subtype_t type,
3032 void *arg,
3033 sctp_cmd_seq_t *commands)
3035 struct sctp_chunk *chunk = arg;
3036 struct sctp_chunk *reply;
3037 struct sctp_ulpevent *ev;
3039 if (!sctp_vtag_verify(chunk, asoc))
3040 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3042 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3043 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3044 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3045 commands);
3046 /* 10.2 H) SHUTDOWN COMPLETE notification
3048 * When SCTP completes the shutdown procedures (section 9.2) this
3049 * notification is passed to the upper layer.
3051 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
3052 0, 0, 0, NULL, GFP_ATOMIC);
3053 if (!ev)
3054 goto nomem;
3056 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3057 reply = sctp_make_shutdown_complete(asoc, chunk);
3058 if (!reply)
3059 goto nomem_chunk;
3061 /* Do all the commands now (after allocation), so that we
3062 * have consistent state if memory allocation failes
3064 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
3066 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3067 * stop the T2-shutdown timer,
3069 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3070 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3072 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3073 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3075 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3076 SCTP_STATE(SCTP_STATE_CLOSED));
3077 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
3078 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3079 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
3081 /* ...and remove all record of the association. */
3082 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
3083 return SCTP_DISPOSITION_DELETE_TCB;
3085 nomem_chunk:
3086 sctp_ulpevent_free(ev);
3087 nomem:
3088 return SCTP_DISPOSITION_NOMEM;
3092 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3094 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3095 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3096 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3097 * packet must fill in the Verification Tag field of the outbound
3098 * packet with the Verification Tag received in the SHUTDOWN ACK and
3099 * set the T-bit in the Chunk Flags to indicate that the Verification
3100 * Tag is reflected.
3102 * 8) The receiver should respond to the sender of the OOTB packet with
3103 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3104 * MUST fill in the Verification Tag field of the outbound packet
3105 * with the value found in the Verification Tag field of the OOTB
3106 * packet and set the T-bit in the Chunk Flags to indicate that the
3107 * Verification Tag is reflected. After sending this ABORT, the
3108 * receiver of the OOTB packet shall discard the OOTB packet and take
3109 * no further action.
3111 sctp_disposition_t sctp_sf_ootb(const struct sctp_endpoint *ep,
3112 const struct sctp_association *asoc,
3113 const sctp_subtype_t type,
3114 void *arg,
3115 sctp_cmd_seq_t *commands)
3117 struct sctp_chunk *chunk = arg;
3118 struct sk_buff *skb = chunk->skb;
3119 sctp_chunkhdr_t *ch;
3120 __u8 *ch_end;
3121 int ootb_shut_ack = 0;
3123 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES);
3125 ch = (sctp_chunkhdr_t *) chunk->chunk_hdr;
3126 do {
3127 /* Break out if chunk length is less then minimal. */
3128 if (ntohs(ch->length) < sizeof(sctp_chunkhdr_t))
3129 break;
3131 ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length));
3132 if (ch_end > skb_tail_pointer(skb))
3133 break;
3135 if (SCTP_CID_SHUTDOWN_ACK == ch->type)
3136 ootb_shut_ack = 1;
3138 /* RFC 2960, Section 3.3.7
3139 * Moreover, under any circumstances, an endpoint that
3140 * receives an ABORT MUST NOT respond to that ABORT by
3141 * sending an ABORT of its own.
3143 if (SCTP_CID_ABORT == ch->type)
3144 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3146 ch = (sctp_chunkhdr_t *) ch_end;
3147 } while (ch_end < skb_tail_pointer(skb));
3149 if (ootb_shut_ack)
3150 sctp_sf_shut_8_4_5(ep, asoc, type, arg, commands);
3151 else
3152 sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
3154 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3158 * Handle an "Out of the blue" SHUTDOWN ACK.
3160 * Section: 8.4 5, sctpimpguide 2.41.
3162 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3163 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3164 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3165 * packet must fill in the Verification Tag field of the outbound
3166 * packet with the Verification Tag received in the SHUTDOWN ACK and
3167 * set the T-bit in the Chunk Flags to indicate that the Verification
3168 * Tag is reflected.
3170 * Inputs
3171 * (endpoint, asoc, type, arg, commands)
3173 * Outputs
3174 * (sctp_disposition_t)
3176 * The return value is the disposition of the chunk.
3178 static sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep,
3179 const struct sctp_association *asoc,
3180 const sctp_subtype_t type,
3181 void *arg,
3182 sctp_cmd_seq_t *commands)
3184 struct sctp_packet *packet = NULL;
3185 struct sctp_chunk *chunk = arg;
3186 struct sctp_chunk *shut;
3188 packet = sctp_ootb_pkt_new(asoc, chunk);
3190 if (packet) {
3191 /* Make an SHUTDOWN_COMPLETE.
3192 * The T bit will be set if the asoc is NULL.
3194 shut = sctp_make_shutdown_complete(asoc, chunk);
3195 if (!shut) {
3196 sctp_ootb_pkt_free(packet);
3197 return SCTP_DISPOSITION_NOMEM;
3200 /* Reflect vtag if T-Bit is set */
3201 if (sctp_test_T_bit(shut))
3202 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
3204 /* Set the skb to the belonging sock for accounting. */
3205 shut->skb->sk = ep->base.sk;
3207 sctp_packet_append_chunk(packet, shut);
3209 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
3210 SCTP_PACKET(packet));
3212 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
3214 /* If the chunk length is invalid, we don't want to process
3215 * the reset of the packet.
3217 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3218 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3220 return SCTP_DISPOSITION_CONSUME;
3223 return SCTP_DISPOSITION_NOMEM;
3227 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3229 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3230 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3231 * procedures in section 8.4 SHOULD be followed, in other words it
3232 * should be treated as an Out Of The Blue packet.
3233 * [This means that we do NOT check the Verification Tag on these
3234 * chunks. --piggy ]
3237 sctp_disposition_t sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint *ep,
3238 const struct sctp_association *asoc,
3239 const sctp_subtype_t type,
3240 void *arg,
3241 sctp_cmd_seq_t *commands)
3243 /* Although we do have an association in this case, it corresponds
3244 * to a restarted association. So the packet is treated as an OOTB
3245 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3246 * called with a NULL association.
3248 return sctp_sf_shut_8_4_5(ep, NULL, type, arg, commands);
3251 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3252 sctp_disposition_t sctp_sf_do_asconf(const struct sctp_endpoint *ep,
3253 const struct sctp_association *asoc,
3254 const sctp_subtype_t type, void *arg,
3255 sctp_cmd_seq_t *commands)
3257 struct sctp_chunk *chunk = arg;
3258 struct sctp_chunk *asconf_ack = NULL;
3259 sctp_addiphdr_t *hdr;
3260 __u32 serial;
3262 if (!sctp_vtag_verify(chunk, asoc)) {
3263 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3264 SCTP_NULL());
3265 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3268 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3269 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_addip_chunk_t)))
3270 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3271 commands);
3273 hdr = (sctp_addiphdr_t *)chunk->skb->data;
3274 serial = ntohl(hdr->serial);
3276 /* ADDIP 4.2 C1) Compare the value of the serial number to the value
3277 * the endpoint stored in a new association variable
3278 * 'Peer-Serial-Number'.
3280 if (serial == asoc->peer.addip_serial + 1) {
3281 /* ADDIP 4.2 C2) If the value found in the serial number is
3282 * equal to the ('Peer-Serial-Number' + 1), the endpoint MUST
3283 * do V1-V5.
3285 asconf_ack = sctp_process_asconf((struct sctp_association *)
3286 asoc, chunk);
3287 if (!asconf_ack)
3288 return SCTP_DISPOSITION_NOMEM;
3289 } else if (serial == asoc->peer.addip_serial) {
3290 /* ADDIP 4.2 C3) If the value found in the serial number is
3291 * equal to the value stored in the 'Peer-Serial-Number'
3292 * IMPLEMENTATION NOTE: As an optimization a receiver may wish
3293 * to save the last ASCONF-ACK for some predetermined period of
3294 * time and instead of re-processing the ASCONF (with the same
3295 * serial number) it may just re-transmit the ASCONF-ACK.
3297 if (asoc->addip_last_asconf_ack)
3298 asconf_ack = asoc->addip_last_asconf_ack;
3299 else
3300 return SCTP_DISPOSITION_DISCARD;
3301 } else {
3302 /* ADDIP 4.2 C4) Otherwise, the ASCONF Chunk is discarded since
3303 * it must be either a stale packet or from an attacker.
3305 return SCTP_DISPOSITION_DISCARD;
3308 /* ADDIP 4.2 C5) In both cases C2 and C3 the ASCONF-ACK MUST be sent
3309 * back to the source address contained in the IP header of the ASCONF
3310 * being responded to.
3312 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack));
3314 return SCTP_DISPOSITION_CONSUME;
3318 * ADDIP Section 4.3 General rules for address manipulation
3319 * When building TLV parameters for the ASCONF Chunk that will add or
3320 * delete IP addresses the D0 to D13 rules should be applied:
3322 sctp_disposition_t sctp_sf_do_asconf_ack(const struct sctp_endpoint *ep,
3323 const struct sctp_association *asoc,
3324 const sctp_subtype_t type, void *arg,
3325 sctp_cmd_seq_t *commands)
3327 struct sctp_chunk *asconf_ack = arg;
3328 struct sctp_chunk *last_asconf = asoc->addip_last_asconf;
3329 struct sctp_chunk *abort;
3330 sctp_addiphdr_t *addip_hdr;
3331 __u32 sent_serial, rcvd_serial;
3333 if (!sctp_vtag_verify(asconf_ack, asoc)) {
3334 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3335 SCTP_NULL());
3336 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3339 /* Make sure that the ADDIP chunk has a valid length. */
3340 if (!sctp_chunk_length_valid(asconf_ack, sizeof(sctp_addip_chunk_t)))
3341 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3342 commands);
3344 addip_hdr = (sctp_addiphdr_t *)asconf_ack->skb->data;
3345 rcvd_serial = ntohl(addip_hdr->serial);
3347 if (last_asconf) {
3348 addip_hdr = (sctp_addiphdr_t *)last_asconf->subh.addip_hdr;
3349 sent_serial = ntohl(addip_hdr->serial);
3350 } else {
3351 sent_serial = asoc->addip_serial - 1;
3354 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3355 * equal to the next serial number to be used but no ASCONF chunk is
3356 * outstanding the endpoint MUST ABORT the association. Note that a
3357 * sequence number is greater than if it is no more than 2^^31-1
3358 * larger than the current sequence number (using serial arithmetic).
3360 if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) &&
3361 !(asoc->addip_last_asconf)) {
3362 abort = sctp_make_abort(asoc, asconf_ack,
3363 sizeof(sctp_errhdr_t));
3364 if (abort) {
3365 sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, NULL, 0);
3366 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3367 SCTP_CHUNK(abort));
3369 /* We are going to ABORT, so we might as well stop
3370 * processing the rest of the chunks in the packet.
3372 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3373 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3374 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3375 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3376 SCTP_ERROR(ECONNABORTED));
3377 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3378 SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
3379 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3380 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3381 return SCTP_DISPOSITION_ABORT;
3384 if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) {
3385 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3386 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3388 if (!sctp_process_asconf_ack((struct sctp_association *)asoc,
3389 asconf_ack))
3390 return SCTP_DISPOSITION_CONSUME;
3392 abort = sctp_make_abort(asoc, asconf_ack,
3393 sizeof(sctp_errhdr_t));
3394 if (abort) {
3395 sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, NULL, 0);
3396 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3397 SCTP_CHUNK(abort));
3399 /* We are going to ABORT, so we might as well stop
3400 * processing the rest of the chunks in the packet.
3402 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3403 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3404 SCTP_ERROR(ECONNABORTED));
3405 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3406 SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
3407 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3408 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3409 return SCTP_DISPOSITION_ABORT;
3412 return SCTP_DISPOSITION_DISCARD;
3416 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3418 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3419 * its cumulative TSN point to the value carried in the FORWARD TSN
3420 * chunk, and then MUST further advance its cumulative TSN point locally
3421 * if possible.
3422 * After the above processing, the data receiver MUST stop reporting any
3423 * missing TSNs earlier than or equal to the new cumulative TSN point.
3425 * Verification Tag: 8.5 Verification Tag [Normal verification]
3427 * The return value is the disposition of the chunk.
3429 sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep,
3430 const struct sctp_association *asoc,
3431 const sctp_subtype_t type,
3432 void *arg,
3433 sctp_cmd_seq_t *commands)
3435 struct sctp_chunk *chunk = arg;
3436 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3437 __u16 len;
3438 __u32 tsn;
3440 if (!sctp_vtag_verify(chunk, asoc)) {
3441 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3442 SCTP_NULL());
3443 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3446 /* Make sure that the FORWARD_TSN chunk has valid length. */
3447 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk)))
3448 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3449 commands);
3451 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3452 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3453 len = ntohs(chunk->chunk_hdr->length);
3454 len -= sizeof(struct sctp_chunkhdr);
3455 skb_pull(chunk->skb, len);
3457 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3458 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn);
3460 /* The TSN is too high--silently discard the chunk and count on it
3461 * getting retransmitted later.
3463 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3464 goto discard_noforce;
3466 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3467 if (len > sizeof(struct sctp_fwdtsn_hdr))
3468 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3469 SCTP_CHUNK(chunk));
3471 /* Count this as receiving DATA. */
3472 if (asoc->autoclose) {
3473 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3474 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
3477 /* FIXME: For now send a SACK, but DATA processing may
3478 * send another.
3480 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
3482 return SCTP_DISPOSITION_CONSUME;
3484 discard_noforce:
3485 return SCTP_DISPOSITION_DISCARD;
3488 sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(
3489 const struct sctp_endpoint *ep,
3490 const struct sctp_association *asoc,
3491 const sctp_subtype_t type,
3492 void *arg,
3493 sctp_cmd_seq_t *commands)
3495 struct sctp_chunk *chunk = arg;
3496 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3497 __u16 len;
3498 __u32 tsn;
3500 if (!sctp_vtag_verify(chunk, asoc)) {
3501 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3502 SCTP_NULL());
3503 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3506 /* Make sure that the FORWARD_TSN chunk has a valid length. */
3507 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk)))
3508 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3509 commands);
3511 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3512 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3513 len = ntohs(chunk->chunk_hdr->length);
3514 len -= sizeof(struct sctp_chunkhdr);
3515 skb_pull(chunk->skb, len);
3517 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3518 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn);
3520 /* The TSN is too high--silently discard the chunk and count on it
3521 * getting retransmitted later.
3523 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3524 goto gen_shutdown;
3526 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3527 if (len > sizeof(struct sctp_fwdtsn_hdr))
3528 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3529 SCTP_CHUNK(chunk));
3531 /* Go a head and force a SACK, since we are shutting down. */
3532 gen_shutdown:
3533 /* Implementor's Guide.
3535 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3536 * respond to each received packet containing one or more DATA chunk(s)
3537 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3539 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
3540 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
3541 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3542 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3544 return SCTP_DISPOSITION_CONSUME;
3548 * Process an unknown chunk.
3550 * Section: 3.2. Also, 2.1 in the implementor's guide.
3552 * Chunk Types are encoded such that the highest-order two bits specify
3553 * the action that must be taken if the processing endpoint does not
3554 * recognize the Chunk Type.
3556 * 00 - Stop processing this SCTP packet and discard it, do not process
3557 * any further chunks within it.
3559 * 01 - Stop processing this SCTP packet and discard it, do not process
3560 * any further chunks within it, and report the unrecognized
3561 * chunk in an 'Unrecognized Chunk Type'.
3563 * 10 - Skip this chunk and continue processing.
3565 * 11 - Skip this chunk and continue processing, but report in an ERROR
3566 * Chunk using the 'Unrecognized Chunk Type' cause of error.
3568 * The return value is the disposition of the chunk.
3570 sctp_disposition_t sctp_sf_unk_chunk(const struct sctp_endpoint *ep,
3571 const struct sctp_association *asoc,
3572 const sctp_subtype_t type,
3573 void *arg,
3574 sctp_cmd_seq_t *commands)
3576 struct sctp_chunk *unk_chunk = arg;
3577 struct sctp_chunk *err_chunk;
3578 sctp_chunkhdr_t *hdr;
3580 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type.chunk);
3582 if (!sctp_vtag_verify(unk_chunk, asoc))
3583 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3585 /* Make sure that the chunk has a valid length.
3586 * Since we don't know the chunk type, we use a general
3587 * chunkhdr structure to make a comparison.
3589 if (!sctp_chunk_length_valid(unk_chunk, sizeof(sctp_chunkhdr_t)))
3590 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3591 commands);
3593 switch (type.chunk & SCTP_CID_ACTION_MASK) {
3594 case SCTP_CID_ACTION_DISCARD:
3595 /* Discard the packet. */
3596 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3597 break;
3598 case SCTP_CID_ACTION_DISCARD_ERR:
3599 /* Discard the packet. */
3600 sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3602 /* Generate an ERROR chunk as response. */
3603 hdr = unk_chunk->chunk_hdr;
3604 err_chunk = sctp_make_op_error(asoc, unk_chunk,
3605 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
3606 WORD_ROUND(ntohs(hdr->length)));
3607 if (err_chunk) {
3608 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3609 SCTP_CHUNK(err_chunk));
3611 return SCTP_DISPOSITION_CONSUME;
3612 break;
3613 case SCTP_CID_ACTION_SKIP:
3614 /* Skip the chunk. */
3615 return SCTP_DISPOSITION_DISCARD;
3616 break;
3617 case SCTP_CID_ACTION_SKIP_ERR:
3618 /* Generate an ERROR chunk as response. */
3619 hdr = unk_chunk->chunk_hdr;
3620 err_chunk = sctp_make_op_error(asoc, unk_chunk,
3621 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
3622 WORD_ROUND(ntohs(hdr->length)));
3623 if (err_chunk) {
3624 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3625 SCTP_CHUNK(err_chunk));
3627 /* Skip the chunk. */
3628 return SCTP_DISPOSITION_CONSUME;
3629 break;
3630 default:
3631 break;
3634 return SCTP_DISPOSITION_DISCARD;
3638 * Discard the chunk.
3640 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
3641 * [Too numerous to mention...]
3642 * Verification Tag: No verification needed.
3643 * Inputs
3644 * (endpoint, asoc, chunk)
3646 * Outputs
3647 * (asoc, reply_msg, msg_up, timers, counters)
3649 * The return value is the disposition of the chunk.
3651 sctp_disposition_t sctp_sf_discard_chunk(const struct sctp_endpoint *ep,
3652 const struct sctp_association *asoc,
3653 const sctp_subtype_t type,
3654 void *arg,
3655 sctp_cmd_seq_t *commands)
3657 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type.chunk);
3658 return SCTP_DISPOSITION_DISCARD;
3662 * Discard the whole packet.
3664 * Section: 8.4 2)
3666 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
3667 * silently discard the OOTB packet and take no further action.
3669 * Verification Tag: No verification necessary
3671 * Inputs
3672 * (endpoint, asoc, chunk)
3674 * Outputs
3675 * (asoc, reply_msg, msg_up, timers, counters)
3677 * The return value is the disposition of the chunk.
3679 sctp_disposition_t sctp_sf_pdiscard(const struct sctp_endpoint *ep,
3680 const struct sctp_association *asoc,
3681 const sctp_subtype_t type,
3682 void *arg,
3683 sctp_cmd_seq_t *commands)
3685 SCTP_INC_STATS(SCTP_MIB_IN_PKT_DISCARDS);
3686 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
3688 return SCTP_DISPOSITION_CONSUME;
3693 * The other end is violating protocol.
3695 * Section: Not specified
3696 * Verification Tag: Not specified
3697 * Inputs
3698 * (endpoint, asoc, chunk)
3700 * Outputs
3701 * (asoc, reply_msg, msg_up, timers, counters)
3703 * We simply tag the chunk as a violation. The state machine will log
3704 * the violation and continue.
3706 sctp_disposition_t sctp_sf_violation(const struct sctp_endpoint *ep,
3707 const struct sctp_association *asoc,
3708 const sctp_subtype_t type,
3709 void *arg,
3710 sctp_cmd_seq_t *commands)
3712 return SCTP_DISPOSITION_VIOLATION;
3716 * Common function to handle a protocol violation.
3718 static sctp_disposition_t sctp_sf_abort_violation(
3719 const struct sctp_association *asoc,
3720 void *arg,
3721 sctp_cmd_seq_t *commands,
3722 const __u8 *payload,
3723 const size_t paylen)
3725 struct sctp_chunk *chunk = arg;
3726 struct sctp_chunk *abort = NULL;
3728 /* Make the abort chunk. */
3729 abort = sctp_make_abort_violation(asoc, chunk, payload, paylen);
3730 if (!abort)
3731 goto nomem;
3733 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
3734 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
3736 if (asoc->state <= SCTP_STATE_COOKIE_ECHOED) {
3737 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3738 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
3739 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3740 SCTP_ERROR(ECONNREFUSED));
3741 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
3742 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
3743 } else {
3744 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3745 SCTP_ERROR(ECONNABORTED));
3746 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3747 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
3748 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3751 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
3753 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3755 return SCTP_DISPOSITION_ABORT;
3757 nomem:
3758 return SCTP_DISPOSITION_NOMEM;
3762 * Handle a protocol violation when the chunk length is invalid.
3763 * "Invalid" length is identified as smaller then the minimal length a
3764 * given chunk can be. For example, a SACK chunk has invalid length
3765 * if it's length is set to be smaller then the size of sctp_sack_chunk_t.
3767 * We inform the other end by sending an ABORT with a Protocol Violation
3768 * error code.
3770 * Section: Not specified
3771 * Verification Tag: Nothing to do
3772 * Inputs
3773 * (endpoint, asoc, chunk)
3775 * Outputs
3776 * (reply_msg, msg_up, counters)
3778 * Generate an ABORT chunk and terminate the association.
3780 static sctp_disposition_t sctp_sf_violation_chunklen(
3781 const struct sctp_endpoint *ep,
3782 const struct sctp_association *asoc,
3783 const sctp_subtype_t type,
3784 void *arg,
3785 sctp_cmd_seq_t *commands)
3787 char err_str[]="The following chunk had invalid length:";
3789 return sctp_sf_abort_violation(asoc, arg, commands, err_str,
3790 sizeof(err_str));
3793 /* Handle a protocol violation when the peer trying to advance the
3794 * cumulative tsn ack to a point beyond the max tsn currently sent.
3796 * We inform the other end by sending an ABORT with a Protocol Violation
3797 * error code.
3799 static sctp_disposition_t sctp_sf_violation_ctsn(
3800 const struct sctp_endpoint *ep,
3801 const struct sctp_association *asoc,
3802 const sctp_subtype_t type,
3803 void *arg,
3804 sctp_cmd_seq_t *commands)
3806 char err_str[]="The cumulative tsn ack beyond the max tsn currently sent:";
3808 return sctp_sf_abort_violation(asoc, arg, commands, err_str,
3809 sizeof(err_str));
3812 /***************************************************************************
3813 * These are the state functions for handling primitive (Section 10) events.
3814 ***************************************************************************/
3816 * sctp_sf_do_prm_asoc
3818 * Section: 10.1 ULP-to-SCTP
3819 * B) Associate
3821 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
3822 * outbound stream count)
3823 * -> association id [,destination transport addr list] [,outbound stream
3824 * count]
3826 * This primitive allows the upper layer to initiate an association to a
3827 * specific peer endpoint.
3829 * The peer endpoint shall be specified by one of the transport addresses
3830 * which defines the endpoint (see Section 1.4). If the local SCTP
3831 * instance has not been initialized, the ASSOCIATE is considered an
3832 * error.
3833 * [This is not relevant for the kernel implementation since we do all
3834 * initialization at boot time. It we hadn't initialized we wouldn't
3835 * get anywhere near this code.]
3837 * An association id, which is a local handle to the SCTP association,
3838 * will be returned on successful establishment of the association. If
3839 * SCTP is not able to open an SCTP association with the peer endpoint,
3840 * an error is returned.
3841 * [In the kernel implementation, the struct sctp_association needs to
3842 * be created BEFORE causing this primitive to run.]
3844 * Other association parameters may be returned, including the
3845 * complete destination transport addresses of the peer as well as the
3846 * outbound stream count of the local endpoint. One of the transport
3847 * address from the returned destination addresses will be selected by
3848 * the local endpoint as default primary path for sending SCTP packets
3849 * to this peer. The returned "destination transport addr list" can
3850 * be used by the ULP to change the default primary path or to force
3851 * sending a packet to a specific transport address. [All of this
3852 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
3853 * function.]
3855 * Mandatory attributes:
3857 * o local SCTP instance name - obtained from the INITIALIZE operation.
3858 * [This is the argument asoc.]
3859 * o destination transport addr - specified as one of the transport
3860 * addresses of the peer endpoint with which the association is to be
3861 * established.
3862 * [This is asoc->peer.active_path.]
3863 * o outbound stream count - the number of outbound streams the ULP
3864 * would like to open towards this peer endpoint.
3865 * [BUG: This is not currently implemented.]
3866 * Optional attributes:
3868 * None.
3870 * The return value is a disposition.
3872 sctp_disposition_t sctp_sf_do_prm_asoc(const struct sctp_endpoint *ep,
3873 const struct sctp_association *asoc,
3874 const sctp_subtype_t type,
3875 void *arg,
3876 sctp_cmd_seq_t *commands)
3878 struct sctp_chunk *repl;
3880 /* The comment below says that we enter COOKIE-WAIT AFTER
3881 * sending the INIT, but that doesn't actually work in our
3882 * implementation...
3884 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3885 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
3887 /* RFC 2960 5.1 Normal Establishment of an Association
3889 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
3890 * must provide its Verification Tag (Tag_A) in the Initiate
3891 * Tag field. Tag_A SHOULD be a random number in the range of
3892 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
3895 repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0);
3896 if (!repl)
3897 goto nomem;
3899 /* Cast away the const modifier, as we want to just
3900 * rerun it through as a sideffect.
3902 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC,
3903 SCTP_ASOC((struct sctp_association *) asoc));
3905 /* Choose transport for INIT. */
3906 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
3907 SCTP_CHUNK(repl));
3909 /* After sending the INIT, "A" starts the T1-init timer and
3910 * enters the COOKIE-WAIT state.
3912 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
3913 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
3914 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
3915 return SCTP_DISPOSITION_CONSUME;
3917 nomem:
3918 return SCTP_DISPOSITION_NOMEM;
3922 * Process the SEND primitive.
3924 * Section: 10.1 ULP-to-SCTP
3925 * E) Send
3927 * Format: SEND(association id, buffer address, byte count [,context]
3928 * [,stream id] [,life time] [,destination transport address]
3929 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
3930 * -> result
3932 * This is the main method to send user data via SCTP.
3934 * Mandatory attributes:
3936 * o association id - local handle to the SCTP association
3938 * o buffer address - the location where the user message to be
3939 * transmitted is stored;
3941 * o byte count - The size of the user data in number of bytes;
3943 * Optional attributes:
3945 * o context - an optional 32 bit integer that will be carried in the
3946 * sending failure notification to the ULP if the transportation of
3947 * this User Message fails.
3949 * o stream id - to indicate which stream to send the data on. If not
3950 * specified, stream 0 will be used.
3952 * o life time - specifies the life time of the user data. The user data
3953 * will not be sent by SCTP after the life time expires. This
3954 * parameter can be used to avoid efforts to transmit stale
3955 * user messages. SCTP notifies the ULP if the data cannot be
3956 * initiated to transport (i.e. sent to the destination via SCTP's
3957 * send primitive) within the life time variable. However, the
3958 * user data will be transmitted if SCTP has attempted to transmit a
3959 * chunk before the life time expired.
3961 * o destination transport address - specified as one of the destination
3962 * transport addresses of the peer endpoint to which this packet
3963 * should be sent. Whenever possible, SCTP should use this destination
3964 * transport address for sending the packets, instead of the current
3965 * primary path.
3967 * o unorder flag - this flag, if present, indicates that the user
3968 * would like the data delivered in an unordered fashion to the peer
3969 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
3970 * message).
3972 * o no-bundle flag - instructs SCTP not to bundle this user data with
3973 * other outbound DATA chunks. SCTP MAY still bundle even when
3974 * this flag is present, when faced with network congestion.
3976 * o payload protocol-id - A 32 bit unsigned integer that is to be
3977 * passed to the peer indicating the type of payload protocol data
3978 * being transmitted. This value is passed as opaque data by SCTP.
3980 * The return value is the disposition.
3982 sctp_disposition_t sctp_sf_do_prm_send(const struct sctp_endpoint *ep,
3983 const struct sctp_association *asoc,
3984 const sctp_subtype_t type,
3985 void *arg,
3986 sctp_cmd_seq_t *commands)
3988 struct sctp_chunk *chunk = arg;
3990 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
3991 return SCTP_DISPOSITION_CONSUME;
3995 * Process the SHUTDOWN primitive.
3997 * Section: 10.1:
3998 * C) Shutdown
4000 * Format: SHUTDOWN(association id)
4001 * -> result
4003 * Gracefully closes an association. Any locally queued user data
4004 * will be delivered to the peer. The association will be terminated only
4005 * after the peer acknowledges all the SCTP packets sent. A success code
4006 * will be returned on successful termination of the association. If
4007 * attempting to terminate the association results in a failure, an error
4008 * code shall be returned.
4010 * Mandatory attributes:
4012 * o association id - local handle to the SCTP association
4014 * Optional attributes:
4016 * None.
4018 * The return value is the disposition.
4020 sctp_disposition_t sctp_sf_do_9_2_prm_shutdown(
4021 const struct sctp_endpoint *ep,
4022 const struct sctp_association *asoc,
4023 const sctp_subtype_t type,
4024 void *arg,
4025 sctp_cmd_seq_t *commands)
4027 int disposition;
4029 /* From 9.2 Shutdown of an Association
4030 * Upon receipt of the SHUTDOWN primitive from its upper
4031 * layer, the endpoint enters SHUTDOWN-PENDING state and
4032 * remains there until all outstanding data has been
4033 * acknowledged by its peer. The endpoint accepts no new data
4034 * from its upper layer, but retransmits data to the far end
4035 * if necessary to fill gaps.
4037 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4038 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
4040 /* sctpimpguide-05 Section 2.12.2
4041 * The sender of the SHUTDOWN MAY also start an overall guard timer
4042 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4044 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4045 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4047 disposition = SCTP_DISPOSITION_CONSUME;
4048 if (sctp_outq_is_empty(&asoc->outqueue)) {
4049 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
4050 arg, commands);
4052 return disposition;
4056 * Process the ABORT primitive.
4058 * Section: 10.1:
4059 * C) Abort
4061 * Format: Abort(association id [, cause code])
4062 * -> result
4064 * Ungracefully closes an association. Any locally queued user data
4065 * will be discarded and an ABORT chunk is sent to the peer. A success code
4066 * will be returned on successful abortion of the association. If
4067 * attempting to abort the association results in a failure, an error
4068 * code shall be returned.
4070 * Mandatory attributes:
4072 * o association id - local handle to the SCTP association
4074 * Optional attributes:
4076 * o cause code - reason of the abort to be passed to the peer
4078 * None.
4080 * The return value is the disposition.
4082 sctp_disposition_t sctp_sf_do_9_1_prm_abort(
4083 const struct sctp_endpoint *ep,
4084 const struct sctp_association *asoc,
4085 const sctp_subtype_t type,
4086 void *arg,
4087 sctp_cmd_seq_t *commands)
4089 /* From 9.1 Abort of an Association
4090 * Upon receipt of the ABORT primitive from its upper
4091 * layer, the endpoint enters CLOSED state and
4092 * discard all outstanding data has been
4093 * acknowledged by its peer. The endpoint accepts no new data
4094 * from its upper layer, but retransmits data to the far end
4095 * if necessary to fill gaps.
4097 struct sctp_chunk *abort = arg;
4098 sctp_disposition_t retval;
4100 retval = SCTP_DISPOSITION_CONSUME;
4102 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4104 /* Even if we can't send the ABORT due to low memory delete the
4105 * TCB. This is a departure from our typical NOMEM handling.
4108 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4109 SCTP_ERROR(ECONNABORTED));
4110 /* Delete the established association. */
4111 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4112 SCTP_PERR(SCTP_ERROR_USER_ABORT));
4114 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4115 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4117 return retval;
4120 /* We tried an illegal operation on an association which is closed. */
4121 sctp_disposition_t sctp_sf_error_closed(const struct sctp_endpoint *ep,
4122 const struct sctp_association *asoc,
4123 const sctp_subtype_t type,
4124 void *arg,
4125 sctp_cmd_seq_t *commands)
4127 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL));
4128 return SCTP_DISPOSITION_CONSUME;
4131 /* We tried an illegal operation on an association which is shutting
4132 * down.
4134 sctp_disposition_t sctp_sf_error_shutdown(const struct sctp_endpoint *ep,
4135 const struct sctp_association *asoc,
4136 const sctp_subtype_t type,
4137 void *arg,
4138 sctp_cmd_seq_t *commands)
4140 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR,
4141 SCTP_ERROR(-ESHUTDOWN));
4142 return SCTP_DISPOSITION_CONSUME;
4146 * sctp_cookie_wait_prm_shutdown
4148 * Section: 4 Note: 2
4149 * Verification Tag:
4150 * Inputs
4151 * (endpoint, asoc)
4153 * The RFC does not explicitly address this issue, but is the route through the
4154 * state table when someone issues a shutdown while in COOKIE_WAIT state.
4156 * Outputs
4157 * (timers)
4159 sctp_disposition_t sctp_sf_cookie_wait_prm_shutdown(
4160 const struct sctp_endpoint *ep,
4161 const struct sctp_association *asoc,
4162 const sctp_subtype_t type,
4163 void *arg,
4164 sctp_cmd_seq_t *commands)
4166 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4167 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4169 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4170 SCTP_STATE(SCTP_STATE_CLOSED));
4172 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
4174 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
4176 return SCTP_DISPOSITION_DELETE_TCB;
4180 * sctp_cookie_echoed_prm_shutdown
4182 * Section: 4 Note: 2
4183 * Verification Tag:
4184 * Inputs
4185 * (endpoint, asoc)
4187 * The RFC does not explcitly address this issue, but is the route through the
4188 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
4190 * Outputs
4191 * (timers)
4193 sctp_disposition_t sctp_sf_cookie_echoed_prm_shutdown(
4194 const struct sctp_endpoint *ep,
4195 const struct sctp_association *asoc,
4196 const sctp_subtype_t type,
4197 void *arg, sctp_cmd_seq_t *commands)
4199 /* There is a single T1 timer, so we should be able to use
4200 * common function with the COOKIE-WAIT state.
4202 return sctp_sf_cookie_wait_prm_shutdown(ep, asoc, type, arg, commands);
4206 * sctp_sf_cookie_wait_prm_abort
4208 * Section: 4 Note: 2
4209 * Verification Tag:
4210 * Inputs
4211 * (endpoint, asoc)
4213 * The RFC does not explicitly address this issue, but is the route through the
4214 * state table when someone issues an abort while in COOKIE_WAIT state.
4216 * Outputs
4217 * (timers)
4219 sctp_disposition_t sctp_sf_cookie_wait_prm_abort(
4220 const struct sctp_endpoint *ep,
4221 const struct sctp_association *asoc,
4222 const sctp_subtype_t type,
4223 void *arg,
4224 sctp_cmd_seq_t *commands)
4226 struct sctp_chunk *abort = arg;
4227 sctp_disposition_t retval;
4229 /* Stop T1-init timer */
4230 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4231 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4232 retval = SCTP_DISPOSITION_CONSUME;
4234 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4236 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4237 SCTP_STATE(SCTP_STATE_CLOSED));
4239 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4241 /* Even if we can't send the ABORT due to low memory delete the
4242 * TCB. This is a departure from our typical NOMEM handling.
4245 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4246 SCTP_ERROR(ECONNREFUSED));
4247 /* Delete the established association. */
4248 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4249 SCTP_PERR(SCTP_ERROR_USER_ABORT));
4251 return retval;
4255 * sctp_sf_cookie_echoed_prm_abort
4257 * Section: 4 Note: 3
4258 * Verification Tag:
4259 * Inputs
4260 * (endpoint, asoc)
4262 * The RFC does not explcitly address this issue, but is the route through the
4263 * state table when someone issues an abort while in COOKIE_ECHOED state.
4265 * Outputs
4266 * (timers)
4268 sctp_disposition_t sctp_sf_cookie_echoed_prm_abort(
4269 const struct sctp_endpoint *ep,
4270 const struct sctp_association *asoc,
4271 const sctp_subtype_t type,
4272 void *arg,
4273 sctp_cmd_seq_t *commands)
4275 /* There is a single T1 timer, so we should be able to use
4276 * common function with the COOKIE-WAIT state.
4278 return sctp_sf_cookie_wait_prm_abort(ep, asoc, type, arg, commands);
4282 * sctp_sf_shutdown_pending_prm_abort
4284 * Inputs
4285 * (endpoint, asoc)
4287 * The RFC does not explicitly address this issue, but is the route through the
4288 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
4290 * Outputs
4291 * (timers)
4293 sctp_disposition_t sctp_sf_shutdown_pending_prm_abort(
4294 const struct sctp_endpoint *ep,
4295 const struct sctp_association *asoc,
4296 const sctp_subtype_t type,
4297 void *arg,
4298 sctp_cmd_seq_t *commands)
4300 /* Stop the T5-shutdown guard timer. */
4301 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4302 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4304 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
4308 * sctp_sf_shutdown_sent_prm_abort
4310 * Inputs
4311 * (endpoint, asoc)
4313 * The RFC does not explicitly address this issue, but is the route through the
4314 * state table when someone issues an abort while in SHUTDOWN-SENT state.
4316 * Outputs
4317 * (timers)
4319 sctp_disposition_t sctp_sf_shutdown_sent_prm_abort(
4320 const struct sctp_endpoint *ep,
4321 const struct sctp_association *asoc,
4322 const sctp_subtype_t type,
4323 void *arg,
4324 sctp_cmd_seq_t *commands)
4326 /* Stop the T2-shutdown timer. */
4327 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4328 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4330 /* Stop the T5-shutdown guard timer. */
4331 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4332 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4334 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
4338 * sctp_sf_cookie_echoed_prm_abort
4340 * Inputs
4341 * (endpoint, asoc)
4343 * The RFC does not explcitly address this issue, but is the route through the
4344 * state table when someone issues an abort while in COOKIE_ECHOED state.
4346 * Outputs
4347 * (timers)
4349 sctp_disposition_t sctp_sf_shutdown_ack_sent_prm_abort(
4350 const struct sctp_endpoint *ep,
4351 const struct sctp_association *asoc,
4352 const sctp_subtype_t type,
4353 void *arg,
4354 sctp_cmd_seq_t *commands)
4356 /* The same T2 timer, so we should be able to use
4357 * common function with the SHUTDOWN-SENT state.
4359 return sctp_sf_shutdown_sent_prm_abort(ep, asoc, type, arg, commands);
4363 * Process the REQUESTHEARTBEAT primitive
4365 * 10.1 ULP-to-SCTP
4366 * J) Request Heartbeat
4368 * Format: REQUESTHEARTBEAT(association id, destination transport address)
4370 * -> result
4372 * Instructs the local endpoint to perform a HeartBeat on the specified
4373 * destination transport address of the given association. The returned
4374 * result should indicate whether the transmission of the HEARTBEAT
4375 * chunk to the destination address is successful.
4377 * Mandatory attributes:
4379 * o association id - local handle to the SCTP association
4381 * o destination transport address - the transport address of the
4382 * association on which a heartbeat should be issued.
4384 sctp_disposition_t sctp_sf_do_prm_requestheartbeat(
4385 const struct sctp_endpoint *ep,
4386 const struct sctp_association *asoc,
4387 const sctp_subtype_t type,
4388 void *arg,
4389 sctp_cmd_seq_t *commands)
4391 if (SCTP_DISPOSITION_NOMEM == sctp_sf_heartbeat(ep, asoc, type,
4392 (struct sctp_transport *)arg, commands))
4393 return SCTP_DISPOSITION_NOMEM;
4396 * RFC 2960 (bis), section 8.3
4398 * D) Request an on-demand HEARTBEAT on a specific destination
4399 * transport address of a given association.
4401 * The endpoint should increment the respective error counter of
4402 * the destination transport address each time a HEARTBEAT is sent
4403 * to that address and not acknowledged within one RTO.
4406 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET,
4407 SCTP_TRANSPORT(arg));
4408 return SCTP_DISPOSITION_CONSUME;
4412 * ADDIP Section 4.1 ASCONF Chunk Procedures
4413 * When an endpoint has an ASCONF signaled change to be sent to the
4414 * remote endpoint it should do A1 to A9
4416 sctp_disposition_t sctp_sf_do_prm_asconf(const struct sctp_endpoint *ep,
4417 const struct sctp_association *asoc,
4418 const sctp_subtype_t type,
4419 void *arg,
4420 sctp_cmd_seq_t *commands)
4422 struct sctp_chunk *chunk = arg;
4424 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
4425 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4426 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4427 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
4428 return SCTP_DISPOSITION_CONSUME;
4432 * Ignore the primitive event
4434 * The return value is the disposition of the primitive.
4436 sctp_disposition_t sctp_sf_ignore_primitive(
4437 const struct sctp_endpoint *ep,
4438 const struct sctp_association *asoc,
4439 const sctp_subtype_t type,
4440 void *arg,
4441 sctp_cmd_seq_t *commands)
4443 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type.primitive);
4444 return SCTP_DISPOSITION_DISCARD;
4447 /***************************************************************************
4448 * These are the state functions for the OTHER events.
4449 ***************************************************************************/
4452 * Start the shutdown negotiation.
4454 * From Section 9.2:
4455 * Once all its outstanding data has been acknowledged, the endpoint
4456 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
4457 * TSN Ack field the last sequential TSN it has received from the peer.
4458 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
4459 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
4460 * with the updated last sequential TSN received from its peer.
4462 * The return value is the disposition.
4464 sctp_disposition_t sctp_sf_do_9_2_start_shutdown(
4465 const struct sctp_endpoint *ep,
4466 const struct sctp_association *asoc,
4467 const sctp_subtype_t type,
4468 void *arg,
4469 sctp_cmd_seq_t *commands)
4471 struct sctp_chunk *reply;
4473 /* Once all its outstanding data has been acknowledged, the
4474 * endpoint shall send a SHUTDOWN chunk to its peer including
4475 * in the Cumulative TSN Ack field the last sequential TSN it
4476 * has received from the peer.
4478 reply = sctp_make_shutdown(asoc, NULL);
4479 if (!reply)
4480 goto nomem;
4482 /* Set the transport for the SHUTDOWN chunk and the timeout for the
4483 * T2-shutdown timer.
4485 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4487 /* It shall then start the T2-shutdown timer */
4488 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4489 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4491 if (asoc->autoclose)
4492 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4493 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
4495 /* and enter the SHUTDOWN-SENT state. */
4496 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4497 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT));
4499 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4501 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4502 * or SHUTDOWN-ACK.
4504 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
4506 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4508 return SCTP_DISPOSITION_CONSUME;
4510 nomem:
4511 return SCTP_DISPOSITION_NOMEM;
4515 * Generate a SHUTDOWN ACK now that everything is SACK'd.
4517 * From Section 9.2:
4519 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4520 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
4521 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
4522 * endpoint must re-send the SHUTDOWN ACK.
4524 * The return value is the disposition.
4526 sctp_disposition_t sctp_sf_do_9_2_shutdown_ack(
4527 const struct sctp_endpoint *ep,
4528 const struct sctp_association *asoc,
4529 const sctp_subtype_t type,
4530 void *arg,
4531 sctp_cmd_seq_t *commands)
4533 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
4534 struct sctp_chunk *reply;
4536 /* There are 2 ways of getting here:
4537 * 1) called in response to a SHUTDOWN chunk
4538 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
4540 * For the case (2), the arg parameter is set to NULL. We need
4541 * to check that we have a chunk before accessing it's fields.
4543 if (chunk) {
4544 if (!sctp_vtag_verify(chunk, asoc))
4545 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
4547 /* Make sure that the SHUTDOWN chunk has a valid length. */
4548 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk_t)))
4549 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
4550 commands);
4553 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4554 * shall send a SHUTDOWN ACK ...
4556 reply = sctp_make_shutdown_ack(asoc, chunk);
4557 if (!reply)
4558 goto nomem;
4560 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
4561 * the T2-shutdown timer.
4563 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4565 /* and start/restart a T2-shutdown timer of its own, */
4566 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4567 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4569 if (asoc->autoclose)
4570 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4571 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
4573 /* Enter the SHUTDOWN-ACK-SENT state. */
4574 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4575 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT));
4577 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4579 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4580 * or SHUTDOWN-ACK.
4582 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
4584 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4586 return SCTP_DISPOSITION_CONSUME;
4588 nomem:
4589 return SCTP_DISPOSITION_NOMEM;
4593 * Ignore the event defined as other
4595 * The return value is the disposition of the event.
4597 sctp_disposition_t sctp_sf_ignore_other(const struct sctp_endpoint *ep,
4598 const struct sctp_association *asoc,
4599 const sctp_subtype_t type,
4600 void *arg,
4601 sctp_cmd_seq_t *commands)
4603 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type.other);
4604 return SCTP_DISPOSITION_DISCARD;
4607 /************************************************************
4608 * These are the state functions for handling timeout events.
4609 ************************************************************/
4612 * RTX Timeout
4614 * Section: 6.3.3 Handle T3-rtx Expiration
4616 * Whenever the retransmission timer T3-rtx expires for a destination
4617 * address, do the following:
4618 * [See below]
4620 * The return value is the disposition of the chunk.
4622 sctp_disposition_t sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint *ep,
4623 const struct sctp_association *asoc,
4624 const sctp_subtype_t type,
4625 void *arg,
4626 sctp_cmd_seq_t *commands)
4628 struct sctp_transport *transport = arg;
4630 SCTP_INC_STATS(SCTP_MIB_T3_RTX_EXPIREDS);
4632 if (asoc->overall_error_count >= asoc->max_retrans) {
4633 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4634 SCTP_ERROR(ETIMEDOUT));
4635 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
4636 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4637 SCTP_PERR(SCTP_ERROR_NO_ERROR));
4638 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4639 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4640 return SCTP_DISPOSITION_DELETE_TCB;
4643 /* E1) For the destination address for which the timer
4644 * expires, adjust its ssthresh with rules defined in Section
4645 * 7.2.3 and set the cwnd <- MTU.
4648 /* E2) For the destination address for which the timer
4649 * expires, set RTO <- RTO * 2 ("back off the timer"). The
4650 * maximum value discussed in rule C7 above (RTO.max) may be
4651 * used to provide an upper bound to this doubling operation.
4654 /* E3) Determine how many of the earliest (i.e., lowest TSN)
4655 * outstanding DATA chunks for the address for which the
4656 * T3-rtx has expired will fit into a single packet, subject
4657 * to the MTU constraint for the path corresponding to the
4658 * destination transport address to which the retransmission
4659 * is being sent (this may be different from the address for
4660 * which the timer expires [see Section 6.4]). Call this
4661 * value K. Bundle and retransmit those K DATA chunks in a
4662 * single packet to the destination endpoint.
4664 * Note: Any DATA chunks that were sent to the address for
4665 * which the T3-rtx timer expired but did not fit in one MTU
4666 * (rule E3 above), should be marked for retransmission and
4667 * sent as soon as cwnd allows (normally when a SACK arrives).
4670 /* Do some failure management (Section 8.2). */
4671 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
4673 /* NB: Rules E4 and F1 are implicit in R1. */
4674 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport));
4676 return SCTP_DISPOSITION_CONSUME;
4680 * Generate delayed SACK on timeout
4682 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
4684 * The guidelines on delayed acknowledgement algorithm specified in
4685 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
4686 * acknowledgement SHOULD be generated for at least every second packet
4687 * (not every second DATA chunk) received, and SHOULD be generated
4688 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
4689 * some situations it may be beneficial for an SCTP transmitter to be
4690 * more conservative than the algorithms detailed in this document
4691 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
4692 * the following algorithms allow.
4694 sctp_disposition_t sctp_sf_do_6_2_sack(const struct sctp_endpoint *ep,
4695 const struct sctp_association *asoc,
4696 const sctp_subtype_t type,
4697 void *arg,
4698 sctp_cmd_seq_t *commands)
4700 SCTP_INC_STATS(SCTP_MIB_DELAY_SACK_EXPIREDS);
4701 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
4702 return SCTP_DISPOSITION_CONSUME;
4706 * sctp_sf_t1_init_timer_expire
4708 * Section: 4 Note: 2
4709 * Verification Tag:
4710 * Inputs
4711 * (endpoint, asoc)
4713 * RFC 2960 Section 4 Notes
4714 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
4715 * and re-start the T1-init timer without changing state. This MUST
4716 * be repeated up to 'Max.Init.Retransmits' times. After that, the
4717 * endpoint MUST abort the initialization process and report the
4718 * error to SCTP user.
4720 * Outputs
4721 * (timers, events)
4724 sctp_disposition_t sctp_sf_t1_init_timer_expire(const struct sctp_endpoint *ep,
4725 const struct sctp_association *asoc,
4726 const sctp_subtype_t type,
4727 void *arg,
4728 sctp_cmd_seq_t *commands)
4730 struct sctp_chunk *repl = NULL;
4731 struct sctp_bind_addr *bp;
4732 int attempts = asoc->init_err_counter + 1;
4734 SCTP_DEBUG_PRINTK("Timer T1 expired (INIT).\n");
4735 SCTP_INC_STATS(SCTP_MIB_T1_INIT_EXPIREDS);
4737 if (attempts <= asoc->max_init_attempts) {
4738 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
4739 repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0);
4740 if (!repl)
4741 return SCTP_DISPOSITION_NOMEM;
4743 /* Choose transport for INIT. */
4744 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
4745 SCTP_CHUNK(repl));
4747 /* Issue a sideeffect to do the needed accounting. */
4748 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART,
4749 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4751 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
4752 } else {
4753 SCTP_DEBUG_PRINTK("Giving up on INIT, attempts: %d"
4754 " max_init_attempts: %d\n",
4755 attempts, asoc->max_init_attempts);
4756 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4757 SCTP_ERROR(ETIMEDOUT));
4758 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4759 SCTP_PERR(SCTP_ERROR_NO_ERROR));
4760 return SCTP_DISPOSITION_DELETE_TCB;
4763 return SCTP_DISPOSITION_CONSUME;
4767 * sctp_sf_t1_cookie_timer_expire
4769 * Section: 4 Note: 2
4770 * Verification Tag:
4771 * Inputs
4772 * (endpoint, asoc)
4774 * RFC 2960 Section 4 Notes
4775 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
4776 * COOKIE ECHO and re-start the T1-cookie timer without changing
4777 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
4778 * After that, the endpoint MUST abort the initialization process and
4779 * report the error to SCTP user.
4781 * Outputs
4782 * (timers, events)
4785 sctp_disposition_t sctp_sf_t1_cookie_timer_expire(const struct sctp_endpoint *ep,
4786 const struct sctp_association *asoc,
4787 const sctp_subtype_t type,
4788 void *arg,
4789 sctp_cmd_seq_t *commands)
4791 struct sctp_chunk *repl = NULL;
4792 int attempts = asoc->init_err_counter + 1;
4794 SCTP_DEBUG_PRINTK("Timer T1 expired (COOKIE-ECHO).\n");
4795 SCTP_INC_STATS(SCTP_MIB_T1_COOKIE_EXPIREDS);
4797 if (attempts <= asoc->max_init_attempts) {
4798 repl = sctp_make_cookie_echo(asoc, NULL);
4799 if (!repl)
4800 return SCTP_DISPOSITION_NOMEM;
4802 /* Issue a sideeffect to do the needed accounting. */
4803 sctp_add_cmd_sf(commands, SCTP_CMD_COOKIEECHO_RESTART,
4804 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
4806 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
4807 } else {
4808 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4809 SCTP_ERROR(ETIMEDOUT));
4810 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4811 SCTP_PERR(SCTP_ERROR_NO_ERROR));
4812 return SCTP_DISPOSITION_DELETE_TCB;
4815 return SCTP_DISPOSITION_CONSUME;
4818 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
4819 * with the updated last sequential TSN received from its peer.
4821 * An endpoint should limit the number of retransmissions of the
4822 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
4823 * If this threshold is exceeded the endpoint should destroy the TCB and
4824 * MUST report the peer endpoint unreachable to the upper layer (and
4825 * thus the association enters the CLOSED state). The reception of any
4826 * packet from its peer (i.e. as the peer sends all of its queued DATA
4827 * chunks) should clear the endpoint's retransmission count and restart
4828 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
4829 * all of its queued DATA chunks that have not yet been sent.
4831 sctp_disposition_t sctp_sf_t2_timer_expire(const struct sctp_endpoint *ep,
4832 const struct sctp_association *asoc,
4833 const sctp_subtype_t type,
4834 void *arg,
4835 sctp_cmd_seq_t *commands)
4837 struct sctp_chunk *reply = NULL;
4839 SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
4840 SCTP_INC_STATS(SCTP_MIB_T2_SHUTDOWN_EXPIREDS);
4842 if (asoc->overall_error_count >= asoc->max_retrans) {
4843 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4844 SCTP_ERROR(ETIMEDOUT));
4845 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
4846 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4847 SCTP_PERR(SCTP_ERROR_NO_ERROR));
4848 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4849 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4850 return SCTP_DISPOSITION_DELETE_TCB;
4853 switch (asoc->state) {
4854 case SCTP_STATE_SHUTDOWN_SENT:
4855 reply = sctp_make_shutdown(asoc, NULL);
4856 break;
4858 case SCTP_STATE_SHUTDOWN_ACK_SENT:
4859 reply = sctp_make_shutdown_ack(asoc, NULL);
4860 break;
4862 default:
4863 BUG();
4864 break;
4867 if (!reply)
4868 goto nomem;
4870 /* Do some failure management (Section 8.2). */
4871 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
4872 SCTP_TRANSPORT(asoc->shutdown_last_sent_to));
4874 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
4875 * the T2-shutdown timer.
4877 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4879 /* Restart the T2-shutdown timer. */
4880 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4881 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4882 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4883 return SCTP_DISPOSITION_CONSUME;
4885 nomem:
4886 return SCTP_DISPOSITION_NOMEM;
4890 * ADDIP Section 4.1 ASCONF CHunk Procedures
4891 * If the T4 RTO timer expires the endpoint should do B1 to B5
4893 sctp_disposition_t sctp_sf_t4_timer_expire(
4894 const struct sctp_endpoint *ep,
4895 const struct sctp_association *asoc,
4896 const sctp_subtype_t type,
4897 void *arg,
4898 sctp_cmd_seq_t *commands)
4900 struct sctp_chunk *chunk = asoc->addip_last_asconf;
4901 struct sctp_transport *transport = chunk->transport;
4903 SCTP_INC_STATS(SCTP_MIB_T4_RTO_EXPIREDS);
4905 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
4906 * detection on the appropriate destination address as defined in
4907 * RFC2960 [5] section 8.1 and 8.2.
4909 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
4911 /* Reconfig T4 timer and transport. */
4912 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
4914 /* ADDIP 4.1 B2) Increment the association error counters and perform
4915 * endpoint failure detection on the association as defined in
4916 * RFC2960 [5] section 8.1 and 8.2.
4917 * association error counter is incremented in SCTP_CMD_STRIKE.
4919 if (asoc->overall_error_count >= asoc->max_retrans) {
4920 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4921 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4922 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4923 SCTP_ERROR(ETIMEDOUT));
4924 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4925 SCTP_PERR(SCTP_ERROR_NO_ERROR));
4926 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4927 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
4928 return SCTP_DISPOSITION_ABORT;
4931 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
4932 * the ASCONF chunk was sent by doubling the RTO timer value.
4933 * This is done in SCTP_CMD_STRIKE.
4936 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
4937 * choose an alternate destination address (please refer to RFC2960
4938 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
4939 * chunk, it MUST be the same (including its serial number) as the last
4940 * ASCONF sent.
4942 sctp_chunk_hold(asoc->addip_last_asconf);
4943 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4944 SCTP_CHUNK(asoc->addip_last_asconf));
4946 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
4947 * destination is selected, then the RTO used will be that of the new
4948 * destination address.
4950 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4951 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4953 return SCTP_DISPOSITION_CONSUME;
4956 /* sctpimpguide-05 Section 2.12.2
4957 * The sender of the SHUTDOWN MAY also start an overall guard timer
4958 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4959 * At the expiration of this timer the sender SHOULD abort the association
4960 * by sending an ABORT chunk.
4962 sctp_disposition_t sctp_sf_t5_timer_expire(const struct sctp_endpoint *ep,
4963 const struct sctp_association *asoc,
4964 const sctp_subtype_t type,
4965 void *arg,
4966 sctp_cmd_seq_t *commands)
4968 struct sctp_chunk *reply = NULL;
4970 SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
4971 SCTP_INC_STATS(SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS);
4973 reply = sctp_make_abort(asoc, NULL, 0);
4974 if (!reply)
4975 goto nomem;
4977 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4978 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4979 SCTP_ERROR(ETIMEDOUT));
4980 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4981 SCTP_PERR(SCTP_ERROR_NO_ERROR));
4983 return SCTP_DISPOSITION_DELETE_TCB;
4984 nomem:
4985 return SCTP_DISPOSITION_NOMEM;
4988 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
4989 * the association is automatically closed by starting the shutdown process.
4990 * The work that needs to be done is same as when SHUTDOWN is initiated by
4991 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
4993 sctp_disposition_t sctp_sf_autoclose_timer_expire(
4994 const struct sctp_endpoint *ep,
4995 const struct sctp_association *asoc,
4996 const sctp_subtype_t type,
4997 void *arg,
4998 sctp_cmd_seq_t *commands)
5000 int disposition;
5002 SCTP_INC_STATS(SCTP_MIB_AUTOCLOSE_EXPIREDS);
5004 /* From 9.2 Shutdown of an Association
5005 * Upon receipt of the SHUTDOWN primitive from its upper
5006 * layer, the endpoint enters SHUTDOWN-PENDING state and
5007 * remains there until all outstanding data has been
5008 * acknowledged by its peer. The endpoint accepts no new data
5009 * from its upper layer, but retransmits data to the far end
5010 * if necessary to fill gaps.
5012 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
5013 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
5015 /* sctpimpguide-05 Section 2.12.2
5016 * The sender of the SHUTDOWN MAY also start an overall guard timer
5017 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5019 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
5020 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
5021 disposition = SCTP_DISPOSITION_CONSUME;
5022 if (sctp_outq_is_empty(&asoc->outqueue)) {
5023 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
5024 arg, commands);
5026 return disposition;
5029 /*****************************************************************************
5030 * These are sa state functions which could apply to all types of events.
5031 ****************************************************************************/
5034 * This table entry is not implemented.
5036 * Inputs
5037 * (endpoint, asoc, chunk)
5039 * The return value is the disposition of the chunk.
5041 sctp_disposition_t sctp_sf_not_impl(const struct sctp_endpoint *ep,
5042 const struct sctp_association *asoc,
5043 const sctp_subtype_t type,
5044 void *arg,
5045 sctp_cmd_seq_t *commands)
5047 return SCTP_DISPOSITION_NOT_IMPL;
5051 * This table entry represents a bug.
5053 * Inputs
5054 * (endpoint, asoc, chunk)
5056 * The return value is the disposition of the chunk.
5058 sctp_disposition_t sctp_sf_bug(const struct sctp_endpoint *ep,
5059 const struct sctp_association *asoc,
5060 const sctp_subtype_t type,
5061 void *arg,
5062 sctp_cmd_seq_t *commands)
5064 return SCTP_DISPOSITION_BUG;
5068 * This table entry represents the firing of a timer in the wrong state.
5069 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
5070 * when the association is in the wrong state. This event should
5071 * be ignored, so as to prevent any rearming of the timer.
5073 * Inputs
5074 * (endpoint, asoc, chunk)
5076 * The return value is the disposition of the chunk.
5078 sctp_disposition_t sctp_sf_timer_ignore(const struct sctp_endpoint *ep,
5079 const struct sctp_association *asoc,
5080 const sctp_subtype_t type,
5081 void *arg,
5082 sctp_cmd_seq_t *commands)
5084 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type.chunk);
5085 return SCTP_DISPOSITION_CONSUME;
5088 /********************************************************************
5089 * 2nd Level Abstractions
5090 ********************************************************************/
5092 /* Pull the SACK chunk based on the SACK header. */
5093 static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk)
5095 struct sctp_sackhdr *sack;
5096 unsigned int len;
5097 __u16 num_blocks;
5098 __u16 num_dup_tsns;
5100 /* Protect ourselves from reading too far into
5101 * the skb from a bogus sender.
5103 sack = (struct sctp_sackhdr *) chunk->skb->data;
5105 num_blocks = ntohs(sack->num_gap_ack_blocks);
5106 num_dup_tsns = ntohs(sack->num_dup_tsns);
5107 len = sizeof(struct sctp_sackhdr);
5108 len += (num_blocks + num_dup_tsns) * sizeof(__u32);
5109 if (len > chunk->skb->len)
5110 return NULL;
5112 skb_pull(chunk->skb, len);
5114 return sack;
5117 /* Create an ABORT packet to be sent as a response, with the specified
5118 * error causes.
5120 static struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep,
5121 const struct sctp_association *asoc,
5122 struct sctp_chunk *chunk,
5123 const void *payload,
5124 size_t paylen)
5126 struct sctp_packet *packet;
5127 struct sctp_chunk *abort;
5129 packet = sctp_ootb_pkt_new(asoc, chunk);
5131 if (packet) {
5132 /* Make an ABORT.
5133 * The T bit will be set if the asoc is NULL.
5135 abort = sctp_make_abort(asoc, chunk, paylen);
5136 if (!abort) {
5137 sctp_ootb_pkt_free(packet);
5138 return NULL;
5141 /* Reflect vtag if T-Bit is set */
5142 if (sctp_test_T_bit(abort))
5143 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
5145 /* Add specified error causes, i.e., payload, to the
5146 * end of the chunk.
5148 sctp_addto_chunk(abort, paylen, payload);
5150 /* Set the skb to the belonging sock for accounting. */
5151 abort->skb->sk = ep->base.sk;
5153 sctp_packet_append_chunk(packet, abort);
5157 return packet;
5160 /* Allocate a packet for responding in the OOTB conditions. */
5161 static struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc,
5162 const struct sctp_chunk *chunk)
5164 struct sctp_packet *packet;
5165 struct sctp_transport *transport;
5166 __u16 sport;
5167 __u16 dport;
5168 __u32 vtag;
5170 /* Get the source and destination port from the inbound packet. */
5171 sport = ntohs(chunk->sctp_hdr->dest);
5172 dport = ntohs(chunk->sctp_hdr->source);
5174 /* The V-tag is going to be the same as the inbound packet if no
5175 * association exists, otherwise, use the peer's vtag.
5177 if (asoc) {
5178 vtag = asoc->peer.i.init_tag;
5179 } else {
5180 /* Special case the INIT and stale COOKIE_ECHO as there is no
5181 * vtag yet.
5183 switch(chunk->chunk_hdr->type) {
5184 case SCTP_CID_INIT:
5186 sctp_init_chunk_t *init;
5188 init = (sctp_init_chunk_t *)chunk->chunk_hdr;
5189 vtag = ntohl(init->init_hdr.init_tag);
5190 break;
5192 default:
5193 vtag = ntohl(chunk->sctp_hdr->vtag);
5194 break;
5198 /* Make a transport for the bucket, Eliza... */
5199 transport = sctp_transport_new(sctp_source(chunk), GFP_ATOMIC);
5200 if (!transport)
5201 goto nomem;
5203 /* Cache a route for the transport with the chunk's destination as
5204 * the source address.
5206 sctp_transport_route(transport, (union sctp_addr *)&chunk->dest,
5207 sctp_sk(sctp_get_ctl_sock()));
5209 packet = sctp_packet_init(&transport->packet, transport, sport, dport);
5210 packet = sctp_packet_config(packet, vtag, 0);
5212 return packet;
5214 nomem:
5215 return NULL;
5218 /* Free the packet allocated earlier for responding in the OOTB condition. */
5219 void sctp_ootb_pkt_free(struct sctp_packet *packet)
5221 sctp_transport_free(packet->transport);
5224 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
5225 static void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep,
5226 const struct sctp_association *asoc,
5227 const struct sctp_chunk *chunk,
5228 sctp_cmd_seq_t *commands,
5229 struct sctp_chunk *err_chunk)
5231 struct sctp_packet *packet;
5233 if (err_chunk) {
5234 packet = sctp_ootb_pkt_new(asoc, chunk);
5235 if (packet) {
5236 struct sctp_signed_cookie *cookie;
5238 /* Override the OOTB vtag from the cookie. */
5239 cookie = chunk->subh.cookie_hdr;
5240 packet->vtag = cookie->c.peer_vtag;
5242 /* Set the skb to the belonging sock for accounting. */
5243 err_chunk->skb->sk = ep->base.sk;
5244 sctp_packet_append_chunk(packet, err_chunk);
5245 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
5246 SCTP_PACKET(packet));
5247 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
5248 } else
5249 sctp_chunk_free (err_chunk);
5254 /* Process a data chunk */
5255 static int sctp_eat_data(const struct sctp_association *asoc,
5256 struct sctp_chunk *chunk,
5257 sctp_cmd_seq_t *commands)
5259 sctp_datahdr_t *data_hdr;
5260 struct sctp_chunk *err;
5261 size_t datalen;
5262 sctp_verb_t deliver;
5263 int tmp;
5264 __u32 tsn;
5265 int account_value;
5266 struct sctp_tsnmap *map = (struct sctp_tsnmap *)&asoc->peer.tsn_map;
5267 struct sock *sk = asoc->base.sk;
5268 int rcvbuf_over = 0;
5270 data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *)chunk->skb->data;
5271 skb_pull(chunk->skb, sizeof(sctp_datahdr_t));
5273 tsn = ntohl(data_hdr->tsn);
5274 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn);
5276 /* ASSERT: Now skb->data is really the user data. */
5279 * If we are established, and we have used up our receive buffer
5280 * memory, think about droping the frame.
5281 * Note that we have an opportunity to improve performance here.
5282 * If we accept one chunk from an skbuff, we have to keep all the
5283 * memory of that skbuff around until the chunk is read into user
5284 * space. Therefore, once we accept 1 chunk we may as well accept all
5285 * remaining chunks in the skbuff. The data_accepted flag helps us do
5286 * that.
5288 if ((asoc->state == SCTP_STATE_ESTABLISHED) && (!chunk->data_accepted)) {
5290 * If the receive buffer policy is 1, then each
5291 * association can allocate up to sk_rcvbuf bytes
5292 * otherwise, all the associations in aggregate
5293 * may allocate up to sk_rcvbuf bytes
5295 if (asoc->ep->rcvbuf_policy)
5296 account_value = atomic_read(&asoc->rmem_alloc);
5297 else
5298 account_value = atomic_read(&sk->sk_rmem_alloc);
5299 if (account_value > sk->sk_rcvbuf) {
5301 * We need to make forward progress, even when we are
5302 * under memory pressure, so we always allow the
5303 * next tsn after the ctsn ack point to be accepted.
5304 * This lets us avoid deadlocks in which we have to
5305 * drop frames that would otherwise let us drain the
5306 * receive queue.
5308 if ((sctp_tsnmap_get_ctsn(map) + 1) != tsn)
5309 return SCTP_IERROR_IGNORE_TSN;
5312 * We're going to accept the frame but we should renege
5313 * to make space for it. This will send us down that
5314 * path later in this function.
5316 rcvbuf_over = 1;
5320 /* Process ECN based congestion.
5322 * Since the chunk structure is reused for all chunks within
5323 * a packet, we use ecn_ce_done to track if we've already
5324 * done CE processing for this packet.
5326 * We need to do ECN processing even if we plan to discard the
5327 * chunk later.
5330 if (!chunk->ecn_ce_done) {
5331 struct sctp_af *af;
5332 chunk->ecn_ce_done = 1;
5334 af = sctp_get_af_specific(
5335 ipver2af(ip_hdr(chunk->skb)->version));
5337 if (af && af->is_ce(chunk->skb) && asoc->peer.ecn_capable) {
5338 /* Do real work as sideffect. */
5339 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
5340 SCTP_U32(tsn));
5344 tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
5345 if (tmp < 0) {
5346 /* The TSN is too high--silently discard the chunk and
5347 * count on it getting retransmitted later.
5349 return SCTP_IERROR_HIGH_TSN;
5350 } else if (tmp > 0) {
5351 /* This is a duplicate. Record it. */
5352 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
5353 return SCTP_IERROR_DUP_TSN;
5356 /* This is a new TSN. */
5358 /* Discard if there is no room in the receive window.
5359 * Actually, allow a little bit of overflow (up to a MTU).
5361 datalen = ntohs(chunk->chunk_hdr->length);
5362 datalen -= sizeof(sctp_data_chunk_t);
5364 deliver = SCTP_CMD_CHUNK_ULP;
5366 /* Think about partial delivery. */
5367 if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) {
5369 /* Even if we don't accept this chunk there is
5370 * memory pressure.
5372 sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL());
5375 /* Spill over rwnd a little bit. Note: While allowed, this spill over
5376 * seems a bit troublesome in that frag_point varies based on
5377 * PMTU. In cases, such as loopback, this might be a rather
5378 * large spill over.
5379 * NOTE: If we have a full receive buffer here, we only renege if
5380 * our receiver can still make progress without the tsn being
5381 * received. We do this because in the event that the associations
5382 * receive queue is empty we are filling a leading gap, and since
5383 * reneging moves the gap to the end of the tsn stream, we are likely
5384 * to stall again very shortly. Avoiding the renege when we fill a
5385 * leading gap is a good heuristic for avoiding such steady state
5386 * stalls.
5388 if (!asoc->rwnd || asoc->rwnd_over ||
5389 (datalen > asoc->rwnd + asoc->frag_point) ||
5390 (rcvbuf_over && (!skb_queue_len(&sk->sk_receive_queue)))) {
5392 /* If this is the next TSN, consider reneging to make
5393 * room. Note: Playing nice with a confused sender. A
5394 * malicious sender can still eat up all our buffer
5395 * space and in the future we may want to detect and
5396 * do more drastic reneging.
5398 if (sctp_tsnmap_has_gap(map) &&
5399 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
5400 SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn);
5401 deliver = SCTP_CMD_RENEGE;
5402 } else {
5403 SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
5404 "rwnd: %d\n", tsn, datalen,
5405 asoc->rwnd);
5406 return SCTP_IERROR_IGNORE_TSN;
5411 * Section 3.3.10.9 No User Data (9)
5413 * Cause of error
5414 * ---------------
5415 * No User Data: This error cause is returned to the originator of a
5416 * DATA chunk if a received DATA chunk has no user data.
5418 if (unlikely(0 == datalen)) {
5419 err = sctp_make_abort_no_data(asoc, chunk, tsn);
5420 if (err) {
5421 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
5422 SCTP_CHUNK(err));
5424 /* We are going to ABORT, so we might as well stop
5425 * processing the rest of the chunks in the packet.
5427 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
5428 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5429 SCTP_ERROR(ECONNABORTED));
5430 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5431 SCTP_PERR(SCTP_ERROR_NO_DATA));
5432 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
5433 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
5434 return SCTP_IERROR_NO_DATA;
5437 /* If definately accepting the DATA chunk, record its TSN, otherwise
5438 * wait for renege processing.
5440 if (SCTP_CMD_CHUNK_ULP == deliver)
5441 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
5443 chunk->data_accepted = 1;
5445 /* Note: Some chunks may get overcounted (if we drop) or overcounted
5446 * if we renege and the chunk arrives again.
5448 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
5449 SCTP_INC_STATS(SCTP_MIB_INUNORDERCHUNKS);
5450 else
5451 SCTP_INC_STATS(SCTP_MIB_INORDERCHUNKS);
5453 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
5455 * If an endpoint receive a DATA chunk with an invalid stream
5456 * identifier, it shall acknowledge the reception of the DATA chunk
5457 * following the normal procedure, immediately send an ERROR chunk
5458 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
5459 * and discard the DATA chunk.
5461 if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) {
5462 err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
5463 &data_hdr->stream,
5464 sizeof(data_hdr->stream));
5465 if (err)
5466 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
5467 SCTP_CHUNK(err));
5468 return SCTP_IERROR_BAD_STREAM;
5471 /* Send the data up to the user. Note: Schedule the
5472 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
5473 * chunk needs the updated rwnd.
5475 sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk));
5477 return SCTP_IERROR_NO_ERROR;