1 /* SCTP kernel implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001-2002 Intel Corp.
6 * Copyright (c) 2002 Nokia Corp.
8 * This is part of the SCTP Linux Kernel Implementation.
10 * These are the state functions for the state machine.
12 * This SCTP implementation is free software;
13 * you can redistribute it and/or modify it under the terms of
14 * the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * This SCTP implementation is distributed in the hope that it
19 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
20 * ************************
21 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 * See the GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with GNU CC; see the file COPYING. If not, write to
26 * the Free Software Foundation, 59 Temple Place - Suite 330,
27 * Boston, MA 02111-1307, USA.
29 * Please send any bug reports or fixes you make to the
31 * lksctp developers <lksctp-developers@lists.sourceforge.net>
33 * Or submit a bug report through the following website:
34 * http://www.sf.net/projects/lksctp
36 * Written or modified by:
37 * La Monte H.P. Yarroll <piggy@acm.org>
38 * Karl Knutson <karl@athena.chicago.il.us>
39 * Mathew Kotowsky <kotowsky@sctp.org>
40 * Sridhar Samudrala <samudrala@us.ibm.com>
41 * Jon Grimm <jgrimm@us.ibm.com>
42 * Hui Huang <hui.huang@nokia.com>
43 * Dajiang Zhang <dajiang.zhang@nokia.com>
44 * Daisy Chang <daisyc@us.ibm.com>
45 * Ardelle Fan <ardelle.fan@intel.com>
46 * Ryan Layer <rmlayer@us.ibm.com>
47 * Kevin Gao <kevin.gao@intel.com>
49 * Any bugs reported given to us we will try to fix... any fixes shared will
50 * be incorporated into the next SCTP release.
53 #include <linux/types.h>
54 #include <linux/kernel.h>
56 #include <linux/ipv6.h>
57 #include <linux/net.h>
58 #include <linux/inet.h>
60 #include <net/inet_ecn.h>
61 #include <linux/skbuff.h>
62 #include <net/sctp/sctp.h>
63 #include <net/sctp/sm.h>
64 #include <net/sctp/structs.h>
66 static struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep,
67 const struct sctp_association *asoc,
68 struct sctp_chunk *chunk,
71 static int sctp_eat_data(const struct sctp_association *asoc,
72 struct sctp_chunk *chunk,
73 sctp_cmd_seq_t *commands);
74 static struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc,
75 const struct sctp_chunk *chunk);
76 static void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep,
77 const struct sctp_association *asoc,
78 const struct sctp_chunk *chunk,
79 sctp_cmd_seq_t *commands,
80 struct sctp_chunk *err_chunk);
81 static sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep,
82 const struct sctp_association *asoc,
83 const sctp_subtype_t type,
85 sctp_cmd_seq_t *commands);
86 static sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep,
87 const struct sctp_association *asoc,
88 const sctp_subtype_t type,
90 sctp_cmd_seq_t *commands);
91 static sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep,
92 const struct sctp_association *asoc,
93 const sctp_subtype_t type,
95 sctp_cmd_seq_t *commands);
96 static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk);
98 static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands,
99 __be16 error, int sk_err,
100 const struct sctp_association *asoc,
101 struct sctp_transport *transport);
103 static sctp_disposition_t sctp_sf_abort_violation(
104 const struct sctp_endpoint *ep,
105 const struct sctp_association *asoc,
107 sctp_cmd_seq_t *commands,
109 const size_t paylen);
111 static sctp_disposition_t sctp_sf_violation_chunklen(
112 const struct sctp_endpoint *ep,
113 const struct sctp_association *asoc,
114 const sctp_subtype_t type,
116 sctp_cmd_seq_t *commands);
118 static sctp_disposition_t sctp_sf_violation_paramlen(
119 const struct sctp_endpoint *ep,
120 const struct sctp_association *asoc,
121 const sctp_subtype_t type,
123 sctp_cmd_seq_t *commands);
125 static sctp_disposition_t sctp_sf_violation_ctsn(
126 const struct sctp_endpoint *ep,
127 const struct sctp_association *asoc,
128 const sctp_subtype_t type,
130 sctp_cmd_seq_t *commands);
132 static sctp_disposition_t sctp_sf_violation_chunk(
133 const struct sctp_endpoint *ep,
134 const struct sctp_association *asoc,
135 const sctp_subtype_t type,
137 sctp_cmd_seq_t *commands);
139 static sctp_ierror_t sctp_sf_authenticate(const struct sctp_endpoint *ep,
140 const struct sctp_association *asoc,
141 const sctp_subtype_t type,
142 struct sctp_chunk *chunk);
144 static sctp_disposition_t __sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep,
145 const struct sctp_association *asoc,
146 const sctp_subtype_t type,
148 sctp_cmd_seq_t *commands);
150 /* Small helper function that checks if the chunk length
151 * is of the appropriate length. The 'required_length' argument
152 * is set to be the size of a specific chunk we are testing.
153 * Return Values: 1 = Valid length
158 sctp_chunk_length_valid(struct sctp_chunk *chunk,
159 __u16 required_length)
161 __u16 chunk_length = ntohs(chunk->chunk_hdr->length);
163 if (unlikely(chunk_length < required_length))
169 /**********************************************************
170 * These are the state functions for handling chunk events.
171 **********************************************************/
174 * Process the final SHUTDOWN COMPLETE.
176 * Section: 4 (C) (diagram), 9.2
177 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
178 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
179 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
180 * should stop the T2-shutdown timer and remove all knowledge of the
181 * association (and thus the association enters the CLOSED state).
183 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
184 * C) Rules for packet carrying SHUTDOWN COMPLETE:
186 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
187 * if the Verification Tag field of the packet matches its own tag and
188 * the T bit is not set
190 * it is set to its peer's tag and the T bit is set in the Chunk
192 * Otherwise, the receiver MUST silently discard the packet
193 * and take no further action. An endpoint MUST ignore the
194 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
197 * (endpoint, asoc, chunk)
200 * (asoc, reply_msg, msg_up, timers, counters)
202 * The return value is the disposition of the chunk.
204 sctp_disposition_t sctp_sf_do_4_C(const struct sctp_endpoint *ep,
205 const struct sctp_association *asoc,
206 const sctp_subtype_t type,
208 sctp_cmd_seq_t *commands)
210 struct sctp_chunk *chunk = arg;
211 struct sctp_ulpevent *ev;
213 if (!sctp_vtag_verify_either(chunk, asoc))
214 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
216 /* RFC 2960 6.10 Bundling
218 * An endpoint MUST NOT bundle INIT, INIT ACK or
219 * SHUTDOWN COMPLETE with any other chunks.
221 if (!chunk->singleton)
222 return sctp_sf_violation_chunk(ep, asoc, type, arg, commands);
224 /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */
225 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
226 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
229 /* RFC 2960 10.2 SCTP-to-ULP
231 * H) SHUTDOWN COMPLETE notification
233 * When SCTP completes the shutdown procedures (section 9.2) this
234 * notification is passed to the upper layer.
236 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
237 0, 0, 0, NULL, GFP_ATOMIC);
239 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
242 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
243 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
244 * not the chunk should be discarded. If the endpoint is in
245 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
246 * T2-shutdown timer and remove all knowledge of the
247 * association (and thus the association enters the CLOSED
250 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
251 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
253 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
254 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
256 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
257 SCTP_STATE(SCTP_STATE_CLOSED));
259 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
260 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
262 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
264 return SCTP_DISPOSITION_DELETE_TCB;
268 * Respond to a normal INIT chunk.
269 * We are the side that is being asked for an association.
271 * Section: 5.1 Normal Establishment of an Association, B
272 * B) "Z" shall respond immediately with an INIT ACK chunk. The
273 * destination IP address of the INIT ACK MUST be set to the source
274 * IP address of the INIT to which this INIT ACK is responding. In
275 * the response, besides filling in other parameters, "Z" must set the
276 * Verification Tag field to Tag_A, and also provide its own
277 * Verification Tag (Tag_Z) in the Initiate Tag field.
279 * Verification Tag: Must be 0.
282 * (endpoint, asoc, chunk)
285 * (asoc, reply_msg, msg_up, timers, counters)
287 * The return value is the disposition of the chunk.
289 sctp_disposition_t sctp_sf_do_5_1B_init(const struct sctp_endpoint *ep,
290 const struct sctp_association *asoc,
291 const sctp_subtype_t type,
293 sctp_cmd_seq_t *commands)
295 struct sctp_chunk *chunk = arg;
296 struct sctp_chunk *repl;
297 struct sctp_association *new_asoc;
298 struct sctp_chunk *err_chunk;
299 struct sctp_packet *packet;
300 sctp_unrecognized_param_t *unk_param;
304 * An endpoint MUST NOT bundle INIT, INIT ACK or
305 * SHUTDOWN COMPLETE with any other chunks.
308 * Furthermore, we require that the receiver of an INIT chunk MUST
309 * enforce these rules by silently discarding an arriving packet
310 * with an INIT chunk that is bundled with other chunks.
312 if (!chunk->singleton)
313 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
315 /* If the packet is an OOTB packet which is temporarily on the
316 * control endpoint, respond with an ABORT.
318 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
319 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
321 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
324 if (chunk->sctp_hdr->vtag != 0)
325 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
327 /* Make sure that the INIT chunk has a valid length.
328 * Normally, this would cause an ABORT with a Protocol Violation
329 * error, but since we don't have an association, we'll
330 * just discard the packet.
332 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
333 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
335 /* Verify the INIT chunk before processing it. */
337 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
338 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
340 /* This chunk contains fatal error. It is to be discarded.
341 * Send an ABORT, with causes if there is any.
344 packet = sctp_abort_pkt_new(ep, asoc, arg,
345 (__u8 *)(err_chunk->chunk_hdr) +
346 sizeof(sctp_chunkhdr_t),
347 ntohs(err_chunk->chunk_hdr->length) -
348 sizeof(sctp_chunkhdr_t));
350 sctp_chunk_free(err_chunk);
353 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
354 SCTP_PACKET(packet));
355 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
356 return SCTP_DISPOSITION_CONSUME;
358 return SCTP_DISPOSITION_NOMEM;
361 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
366 /* Grab the INIT header. */
367 chunk->subh.init_hdr = (sctp_inithdr_t *)chunk->skb->data;
369 /* Tag the variable length parameters. */
370 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
372 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
376 /* The call, sctp_process_init(), can fail on memory allocation. */
377 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
379 (sctp_init_chunk_t *)chunk->chunk_hdr,
383 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
385 /* If there are errors need to be reported for unknown parameters,
386 * make sure to reserve enough room in the INIT ACK for them.
390 len = ntohs(err_chunk->chunk_hdr->length) -
391 sizeof(sctp_chunkhdr_t);
393 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
396 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
400 /* If there are errors need to be reported for unknown parameters,
401 * include them in the outgoing INIT ACK as "Unrecognized parameter"
405 /* Get the "Unrecognized parameter" parameter(s) out of the
406 * ERROR chunk generated by sctp_verify_init(). Since the
407 * error cause code for "unknown parameter" and the
408 * "Unrecognized parameter" type is the same, we can
409 * construct the parameters in INIT ACK by copying the
412 unk_param = (sctp_unrecognized_param_t *)
413 ((__u8 *)(err_chunk->chunk_hdr) +
414 sizeof(sctp_chunkhdr_t));
415 /* Replace the cause code with the "Unrecognized parameter"
418 sctp_addto_chunk(repl, len, unk_param);
419 sctp_chunk_free(err_chunk);
422 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
424 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
427 * Note: After sending out INIT ACK with the State Cookie parameter,
428 * "Z" MUST NOT allocate any resources, nor keep any states for the
429 * new association. Otherwise, "Z" will be vulnerable to resource
432 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
434 return SCTP_DISPOSITION_DELETE_TCB;
437 sctp_association_free(new_asoc);
440 sctp_chunk_free(err_chunk);
441 return SCTP_DISPOSITION_NOMEM;
445 * Respond to a normal INIT ACK chunk.
446 * We are the side that is initiating the association.
448 * Section: 5.1 Normal Establishment of an Association, C
449 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
450 * timer and leave COOKIE-WAIT state. "A" shall then send the State
451 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
452 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
454 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
455 * DATA chunks, but it MUST be the first chunk in the packet and
456 * until the COOKIE ACK is returned the sender MUST NOT send any
457 * other packets to the peer.
459 * Verification Tag: 3.3.3
460 * If the value of the Initiate Tag in a received INIT ACK chunk is
461 * found to be 0, the receiver MUST treat it as an error and close the
462 * association by transmitting an ABORT.
465 * (endpoint, asoc, chunk)
468 * (asoc, reply_msg, msg_up, timers, counters)
470 * The return value is the disposition of the chunk.
472 sctp_disposition_t sctp_sf_do_5_1C_ack(const struct sctp_endpoint *ep,
473 const struct sctp_association *asoc,
474 const sctp_subtype_t type,
476 sctp_cmd_seq_t *commands)
478 struct sctp_chunk *chunk = arg;
479 sctp_init_chunk_t *initchunk;
480 struct sctp_chunk *err_chunk;
481 struct sctp_packet *packet;
483 if (!sctp_vtag_verify(chunk, asoc))
484 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
487 * An endpoint MUST NOT bundle INIT, INIT ACK or
488 * SHUTDOWN COMPLETE with any other chunks.
490 if (!chunk->singleton)
491 return sctp_sf_violation_chunk(ep, asoc, type, arg, commands);
493 /* Make sure that the INIT-ACK chunk has a valid length */
494 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_initack_chunk_t)))
495 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
497 /* Grab the INIT header. */
498 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
500 /* Verify the INIT chunk before processing it. */
502 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
503 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
506 sctp_error_t error = SCTP_ERROR_NO_RESOURCE;
508 /* This chunk contains fatal error. It is to be discarded.
509 * Send an ABORT, with causes. If there are no causes,
510 * then there wasn't enough memory. Just terminate
514 packet = sctp_abort_pkt_new(ep, asoc, arg,
515 (__u8 *)(err_chunk->chunk_hdr) +
516 sizeof(sctp_chunkhdr_t),
517 ntohs(err_chunk->chunk_hdr->length) -
518 sizeof(sctp_chunkhdr_t));
520 sctp_chunk_free(err_chunk);
523 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
524 SCTP_PACKET(packet));
525 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
526 error = SCTP_ERROR_INV_PARAM;
530 /* SCTP-AUTH, Section 6.3:
531 * It should be noted that if the receiver wants to tear
532 * down an association in an authenticated way only, the
533 * handling of malformed packets should not result in
534 * tearing down the association.
536 * This means that if we only want to abort associations
537 * in an authenticated way (i.e AUTH+ABORT), then we
538 * can't destroy this association just becuase the packet
541 if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
542 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
544 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
545 return sctp_stop_t1_and_abort(commands, error, ECONNREFUSED,
546 asoc, chunk->transport);
549 /* Tag the variable length parameters. Note that we never
550 * convert the parameters in an INIT chunk.
552 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
554 initchunk = (sctp_init_chunk_t *) chunk->chunk_hdr;
556 sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT,
557 SCTP_PEER_INIT(initchunk));
559 /* Reset init error count upon receipt of INIT-ACK. */
560 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
562 /* 5.1 C) "A" shall stop the T1-init timer and leave
563 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
564 * timer, and enter the COOKIE-ECHOED state.
566 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
567 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
568 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
569 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
570 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
571 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED));
573 /* SCTP-AUTH: genereate the assocition shared keys so that
574 * we can potentially signe the COOKIE-ECHO.
576 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_SHKEY, SCTP_NULL());
578 /* 5.1 C) "A" shall then send the State Cookie received in the
579 * INIT ACK chunk in a COOKIE ECHO chunk, ...
581 /* If there is any errors to report, send the ERROR chunk generated
582 * for unknown parameters as well.
584 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO,
585 SCTP_CHUNK(err_chunk));
587 return SCTP_DISPOSITION_CONSUME;
591 * Respond to a normal COOKIE ECHO chunk.
592 * We are the side that is being asked for an association.
594 * Section: 5.1 Normal Establishment of an Association, D
595 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
596 * with a COOKIE ACK chunk after building a TCB and moving to
597 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
598 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
599 * chunk MUST be the first chunk in the packet.
601 * IMPLEMENTATION NOTE: An implementation may choose to send the
602 * Communication Up notification to the SCTP user upon reception
603 * of a valid COOKIE ECHO chunk.
605 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
606 * D) Rules for packet carrying a COOKIE ECHO
608 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
609 * Initial Tag received in the INIT ACK.
611 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
614 * (endpoint, asoc, chunk)
617 * (asoc, reply_msg, msg_up, timers, counters)
619 * The return value is the disposition of the chunk.
621 sctp_disposition_t sctp_sf_do_5_1D_ce(const struct sctp_endpoint *ep,
622 const struct sctp_association *asoc,
623 const sctp_subtype_t type, void *arg,
624 sctp_cmd_seq_t *commands)
626 struct sctp_chunk *chunk = arg;
627 struct sctp_association *new_asoc;
628 sctp_init_chunk_t *peer_init;
629 struct sctp_chunk *repl;
630 struct sctp_ulpevent *ev, *ai_ev = NULL;
632 struct sctp_chunk *err_chk_p;
635 /* If the packet is an OOTB packet which is temporarily on the
636 * control endpoint, respond with an ABORT.
638 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
639 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
641 /* Make sure that the COOKIE_ECHO chunk has a valid length.
642 * In this case, we check that we have enough for at least a
643 * chunk header. More detailed verification is done
644 * in sctp_unpack_cookie().
646 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
647 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
649 /* If the endpoint is not listening or if the number of associations
650 * on the TCP-style socket exceed the max backlog, respond with an
654 if (!sctp_sstate(sk, LISTENING) ||
655 (sctp_style(sk, TCP) && sk_acceptq_is_full(sk)))
656 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
658 /* "Decode" the chunk. We have no optional parameters so we
661 chunk->subh.cookie_hdr =
662 (struct sctp_signed_cookie *)chunk->skb->data;
663 if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
664 sizeof(sctp_chunkhdr_t)))
667 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
668 * "Z" will reply with a COOKIE ACK chunk after building a TCB
669 * and moving to the ESTABLISHED state.
671 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
675 * If the re-build failed, what is the proper error path
678 * [We should abort the association. --piggy]
681 /* FIXME: Several errors are possible. A bad cookie should
682 * be silently discarded, but think about logging it too.
685 case -SCTP_IERROR_NOMEM:
688 case -SCTP_IERROR_STALE_COOKIE:
689 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
691 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
693 case -SCTP_IERROR_BAD_SIG:
695 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
700 /* Delay state machine commands until later.
702 * Re-build the bind address for the association is done in
703 * the sctp_unpack_cookie() already.
705 /* This is a brand-new association, so these are not yet side
706 * effects--it is safe to run them here.
708 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
710 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
711 &chunk->subh.cookie_hdr->c.peer_addr,
712 peer_init, GFP_ATOMIC))
715 /* SCTP-AUTH: Now that we've populate required fields in
716 * sctp_process_init, set up the assocaition shared keys as
717 * necessary so that we can potentially authenticate the ACK
719 error = sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC);
723 /* SCTP-AUTH: auth_chunk pointer is only set when the cookie-echo
724 * is supposed to be authenticated and we have to do delayed
725 * authentication. We've just recreated the association using
726 * the information in the cookie and now it's much easier to
727 * do the authentication.
729 if (chunk->auth_chunk) {
730 struct sctp_chunk auth;
733 /* set-up our fake chunk so that we can process it */
734 auth.skb = chunk->auth_chunk;
735 auth.asoc = chunk->asoc;
736 auth.sctp_hdr = chunk->sctp_hdr;
737 auth.chunk_hdr = (sctp_chunkhdr_t *)skb_push(chunk->auth_chunk,
738 sizeof(sctp_chunkhdr_t));
739 skb_pull(chunk->auth_chunk, sizeof(sctp_chunkhdr_t));
740 auth.transport = chunk->transport;
742 ret = sctp_sf_authenticate(ep, new_asoc, type, &auth);
744 /* We can now safely free the auth_chunk clone */
745 kfree_skb(chunk->auth_chunk);
747 if (ret != SCTP_IERROR_NO_ERROR) {
748 sctp_association_free(new_asoc);
749 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
753 repl = sctp_make_cookie_ack(new_asoc, chunk);
757 /* RFC 2960 5.1 Normal Establishment of an Association
759 * D) IMPLEMENTATION NOTE: An implementation may choose to
760 * send the Communication Up notification to the SCTP user
761 * upon reception of a valid COOKIE ECHO chunk.
763 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0,
764 new_asoc->c.sinit_num_ostreams,
765 new_asoc->c.sinit_max_instreams,
770 /* Sockets API Draft Section 5.3.1.6
771 * When a peer sends a Adaptation Layer Indication parameter , SCTP
772 * delivers this notification to inform the application that of the
773 * peers requested adaptation layer.
775 if (new_asoc->peer.adaptation_ind) {
776 ai_ev = sctp_ulpevent_make_adaptation_indication(new_asoc,
782 /* Add all the state machine commands now since we've created
783 * everything. This way we don't introduce memory corruptions
784 * during side-effect processing and correclty count established
787 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
788 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
789 SCTP_STATE(SCTP_STATE_ESTABLISHED));
790 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
791 SCTP_INC_STATS(SCTP_MIB_PASSIVEESTABS);
792 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
794 if (new_asoc->autoclose)
795 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
796 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
798 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
800 /* This will send the COOKIE ACK */
801 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
803 /* Queue the ASSOC_CHANGE event */
804 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
806 /* Send up the Adaptation Layer Indication event */
808 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
809 SCTP_ULPEVENT(ai_ev));
811 return SCTP_DISPOSITION_CONSUME;
814 sctp_ulpevent_free(ev);
816 sctp_chunk_free(repl);
818 sctp_association_free(new_asoc);
820 return SCTP_DISPOSITION_NOMEM;
824 * Respond to a normal COOKIE ACK chunk.
825 * We are the side that is being asked for an association.
827 * RFC 2960 5.1 Normal Establishment of an Association
829 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
830 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
831 * timer. It may also notify its ULP about the successful
832 * establishment of the association with a Communication Up
833 * notification (see Section 10).
837 * (endpoint, asoc, chunk)
840 * (asoc, reply_msg, msg_up, timers, counters)
842 * The return value is the disposition of the chunk.
844 sctp_disposition_t sctp_sf_do_5_1E_ca(const struct sctp_endpoint *ep,
845 const struct sctp_association *asoc,
846 const sctp_subtype_t type, void *arg,
847 sctp_cmd_seq_t *commands)
849 struct sctp_chunk *chunk = arg;
850 struct sctp_ulpevent *ev;
852 if (!sctp_vtag_verify(chunk, asoc))
853 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
855 /* Verify that the chunk length for the COOKIE-ACK is OK.
856 * If we don't do this, any bundled chunks may be junked.
858 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
859 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
862 /* Reset init error count upon receipt of COOKIE-ACK,
863 * to avoid problems with the managemement of this
864 * counter in stale cookie situations when a transition back
865 * from the COOKIE-ECHOED state to the COOKIE-WAIT
866 * state is performed.
868 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
870 /* RFC 2960 5.1 Normal Establishment of an Association
872 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
873 * from the COOKIE-ECHOED state to the ESTABLISHED state,
874 * stopping the T1-cookie timer.
876 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
877 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
878 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
879 SCTP_STATE(SCTP_STATE_ESTABLISHED));
880 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
881 SCTP_INC_STATS(SCTP_MIB_ACTIVEESTABS);
882 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
884 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
885 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
886 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
888 /* It may also notify its ULP about the successful
889 * establishment of the association with a Communication Up
890 * notification (see Section 10).
892 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP,
893 0, asoc->c.sinit_num_ostreams,
894 asoc->c.sinit_max_instreams,
900 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
902 /* Sockets API Draft Section 5.3.1.6
903 * When a peer sends a Adaptation Layer Indication parameter , SCTP
904 * delivers this notification to inform the application that of the
905 * peers requested adaptation layer.
907 if (asoc->peer.adaptation_ind) {
908 ev = sctp_ulpevent_make_adaptation_indication(asoc, GFP_ATOMIC);
912 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
916 return SCTP_DISPOSITION_CONSUME;
918 return SCTP_DISPOSITION_NOMEM;
921 /* Generate and sendout a heartbeat packet. */
922 static sctp_disposition_t sctp_sf_heartbeat(const struct sctp_endpoint *ep,
923 const struct sctp_association *asoc,
924 const sctp_subtype_t type,
926 sctp_cmd_seq_t *commands)
928 struct sctp_transport *transport = (struct sctp_transport *) arg;
929 struct sctp_chunk *reply;
930 sctp_sender_hb_info_t hbinfo;
933 hbinfo.param_hdr.type = SCTP_PARAM_HEARTBEAT_INFO;
934 hbinfo.param_hdr.length = htons(sizeof(sctp_sender_hb_info_t));
935 hbinfo.daddr = transport->ipaddr;
936 hbinfo.sent_at = jiffies;
937 hbinfo.hb_nonce = transport->hb_nonce;
939 /* Send a heartbeat to our peer. */
940 paylen = sizeof(sctp_sender_hb_info_t);
941 reply = sctp_make_heartbeat(asoc, transport, &hbinfo, paylen);
943 return SCTP_DISPOSITION_NOMEM;
945 /* Set rto_pending indicating that an RTT measurement
946 * is started with this heartbeat chunk.
948 sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING,
949 SCTP_TRANSPORT(transport));
951 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
952 return SCTP_DISPOSITION_CONSUME;
955 /* Generate a HEARTBEAT packet on the given transport. */
956 sctp_disposition_t sctp_sf_sendbeat_8_3(const struct sctp_endpoint *ep,
957 const struct sctp_association *asoc,
958 const sctp_subtype_t type,
960 sctp_cmd_seq_t *commands)
962 struct sctp_transport *transport = (struct sctp_transport *) arg;
964 if (asoc->overall_error_count > asoc->max_retrans) {
965 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
966 SCTP_ERROR(ETIMEDOUT));
967 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
968 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
969 SCTP_PERR(SCTP_ERROR_NO_ERROR));
970 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
971 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
972 return SCTP_DISPOSITION_DELETE_TCB;
976 * The Sender-specific Heartbeat Info field should normally include
977 * information about the sender's current time when this HEARTBEAT
978 * chunk is sent and the destination transport address to which this
979 * HEARTBEAT is sent (see Section 8.3).
982 if (transport->param_flags & SPP_HB_ENABLE) {
983 if (SCTP_DISPOSITION_NOMEM ==
984 sctp_sf_heartbeat(ep, asoc, type, arg,
986 return SCTP_DISPOSITION_NOMEM;
987 /* Set transport error counter and association error counter
988 * when sending heartbeat.
990 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET,
991 SCTP_TRANSPORT(transport));
993 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE,
994 SCTP_TRANSPORT(transport));
996 return SCTP_DISPOSITION_CONSUME;
1000 * Process an heartbeat request.
1002 * Section: 8.3 Path Heartbeat
1003 * The receiver of the HEARTBEAT should immediately respond with a
1004 * HEARTBEAT ACK that contains the Heartbeat Information field copied
1005 * from the received HEARTBEAT chunk.
1007 * Verification Tag: 8.5 Verification Tag [Normal verification]
1008 * When receiving an SCTP packet, the endpoint MUST ensure that the
1009 * value in the Verification Tag field of the received SCTP packet
1010 * matches its own Tag. If the received Verification Tag value does not
1011 * match the receiver's own tag value, the receiver shall silently
1012 * discard the packet and shall not process it any further except for
1013 * those cases listed in Section 8.5.1 below.
1016 * (endpoint, asoc, chunk)
1019 * (asoc, reply_msg, msg_up, timers, counters)
1021 * The return value is the disposition of the chunk.
1023 sctp_disposition_t sctp_sf_beat_8_3(const struct sctp_endpoint *ep,
1024 const struct sctp_association *asoc,
1025 const sctp_subtype_t type,
1027 sctp_cmd_seq_t *commands)
1029 struct sctp_chunk *chunk = arg;
1030 struct sctp_chunk *reply;
1033 if (!sctp_vtag_verify(chunk, asoc))
1034 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1036 /* Make sure that the HEARTBEAT chunk has a valid length. */
1037 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t)))
1038 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1041 /* 8.3 The receiver of the HEARTBEAT should immediately
1042 * respond with a HEARTBEAT ACK that contains the Heartbeat
1043 * Information field copied from the received HEARTBEAT chunk.
1045 chunk->subh.hb_hdr = (sctp_heartbeathdr_t *) chunk->skb->data;
1046 paylen = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t);
1047 if (!pskb_pull(chunk->skb, paylen))
1050 reply = sctp_make_heartbeat_ack(asoc, chunk,
1051 chunk->subh.hb_hdr, paylen);
1055 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
1056 return SCTP_DISPOSITION_CONSUME;
1059 return SCTP_DISPOSITION_NOMEM;
1063 * Process the returning HEARTBEAT ACK.
1065 * Section: 8.3 Path Heartbeat
1066 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
1067 * should clear the error counter of the destination transport
1068 * address to which the HEARTBEAT was sent, and mark the destination
1069 * transport address as active if it is not so marked. The endpoint may
1070 * optionally report to the upper layer when an inactive destination
1071 * address is marked as active due to the reception of the latest
1072 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
1073 * clear the association overall error count as well (as defined
1076 * The receiver of the HEARTBEAT ACK should also perform an RTT
1077 * measurement for that destination transport address using the time
1078 * value carried in the HEARTBEAT ACK chunk.
1080 * Verification Tag: 8.5 Verification Tag [Normal verification]
1083 * (endpoint, asoc, chunk)
1086 * (asoc, reply_msg, msg_up, timers, counters)
1088 * The return value is the disposition of the chunk.
1090 sctp_disposition_t sctp_sf_backbeat_8_3(const struct sctp_endpoint *ep,
1091 const struct sctp_association *asoc,
1092 const sctp_subtype_t type,
1094 sctp_cmd_seq_t *commands)
1096 struct sctp_chunk *chunk = arg;
1097 union sctp_addr from_addr;
1098 struct sctp_transport *link;
1099 sctp_sender_hb_info_t *hbinfo;
1100 unsigned long max_interval;
1102 if (!sctp_vtag_verify(chunk, asoc))
1103 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1105 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1106 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t)))
1107 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1110 hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data;
1111 /* Make sure that the length of the parameter is what we expect */
1112 if (ntohs(hbinfo->param_hdr.length) !=
1113 sizeof(sctp_sender_hb_info_t)) {
1114 return SCTP_DISPOSITION_DISCARD;
1117 from_addr = hbinfo->daddr;
1118 link = sctp_assoc_lookup_paddr(asoc, &from_addr);
1120 /* This should never happen, but lets log it if so. */
1121 if (unlikely(!link)) {
1122 if (from_addr.sa.sa_family == AF_INET6) {
1123 if (net_ratelimit())
1125 "%s association %p could not find address "
1129 NIP6(from_addr.v6.sin6_addr));
1131 if (net_ratelimit())
1133 "%s association %p could not find address "
1137 NIPQUAD(from_addr.v4.sin_addr.s_addr));
1139 return SCTP_DISPOSITION_DISCARD;
1142 /* Validate the 64-bit random nonce. */
1143 if (hbinfo->hb_nonce != link->hb_nonce)
1144 return SCTP_DISPOSITION_DISCARD;
1146 max_interval = link->hbinterval + link->rto;
1148 /* Check if the timestamp looks valid. */
1149 if (time_after(hbinfo->sent_at, jiffies) ||
1150 time_after(jiffies, hbinfo->sent_at + max_interval)) {
1151 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp "
1152 "received for transport: %p\n",
1154 return SCTP_DISPOSITION_DISCARD;
1157 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1158 * the HEARTBEAT should clear the error counter of the
1159 * destination transport address to which the HEARTBEAT was
1160 * sent and mark the destination transport address as active if
1161 * it is not so marked.
1163 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link));
1165 return SCTP_DISPOSITION_CONSUME;
1168 /* Helper function to send out an abort for the restart
1171 static int sctp_sf_send_restart_abort(union sctp_addr *ssa,
1172 struct sctp_chunk *init,
1173 sctp_cmd_seq_t *commands)
1176 struct sctp_packet *pkt;
1177 union sctp_addr_param *addrparm;
1178 struct sctp_errhdr *errhdr;
1179 struct sctp_endpoint *ep;
1180 char buffer[sizeof(struct sctp_errhdr)+sizeof(union sctp_addr_param)];
1181 struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family);
1183 /* Build the error on the stack. We are way to malloc crazy
1184 * throughout the code today.
1186 errhdr = (struct sctp_errhdr *)buffer;
1187 addrparm = (union sctp_addr_param *)errhdr->variable;
1189 /* Copy into a parm format. */
1190 len = af->to_addr_param(ssa, addrparm);
1191 len += sizeof(sctp_errhdr_t);
1193 errhdr->cause = SCTP_ERROR_RESTART;
1194 errhdr->length = htons(len);
1196 /* Assign to the control socket. */
1197 ep = sctp_sk((sctp_get_ctl_sock()))->ep;
1199 /* Association is NULL since this may be a restart attack and we
1200 * want to send back the attacker's vtag.
1202 pkt = sctp_abort_pkt_new(ep, NULL, init, errhdr, len);
1206 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt));
1208 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1210 /* Discard the rest of the inbound packet. */
1211 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
1214 /* Even if there is no memory, treat as a failure so
1215 * the packet will get dropped.
1220 /* A restart is occurring, check to make sure no new addresses
1221 * are being added as we may be under a takeover attack.
1223 static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc,
1224 const struct sctp_association *asoc,
1225 struct sctp_chunk *init,
1226 sctp_cmd_seq_t *commands)
1228 struct sctp_transport *new_addr, *addr;
1229 struct list_head *pos, *pos2;
1232 /* Implementor's Guide - Sectin 5.2.2
1234 * Before responding the endpoint MUST check to see if the
1235 * unexpected INIT adds new addresses to the association. If new
1236 * addresses are added to the association, the endpoint MUST respond
1240 /* Search through all current addresses and make sure
1241 * we aren't adding any new ones.
1246 list_for_each(pos, &new_asoc->peer.transport_addr_list) {
1247 new_addr = list_entry(pos, struct sctp_transport, transports);
1249 list_for_each(pos2, &asoc->peer.transport_addr_list) {
1250 addr = list_entry(pos2, struct sctp_transport,
1252 if (sctp_cmp_addr_exact(&new_addr->ipaddr,
1262 /* If a new address was added, ABORT the sender. */
1263 if (!found && new_addr) {
1264 sctp_sf_send_restart_abort(&new_addr->ipaddr, init, commands);
1267 /* Return success if all addresses were found. */
1271 /* Populate the verification/tie tags based on overlapping INIT
1274 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1276 static void sctp_tietags_populate(struct sctp_association *new_asoc,
1277 const struct sctp_association *asoc)
1279 switch (asoc->state) {
1281 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1283 case SCTP_STATE_COOKIE_WAIT:
1284 new_asoc->c.my_vtag = asoc->c.my_vtag;
1285 new_asoc->c.my_ttag = asoc->c.my_vtag;
1286 new_asoc->c.peer_ttag = 0;
1289 case SCTP_STATE_COOKIE_ECHOED:
1290 new_asoc->c.my_vtag = asoc->c.my_vtag;
1291 new_asoc->c.my_ttag = asoc->c.my_vtag;
1292 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1295 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1296 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1299 new_asoc->c.my_ttag = asoc->c.my_vtag;
1300 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1304 /* Other parameters for the endpoint SHOULD be copied from the
1305 * existing parameters of the association (e.g. number of
1306 * outbound streams) into the INIT ACK and cookie.
1308 new_asoc->rwnd = asoc->rwnd;
1309 new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams;
1310 new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams;
1311 new_asoc->c.initial_tsn = asoc->c.initial_tsn;
1315 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1318 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1320 * Returns value representing action to be taken. These action values
1321 * correspond to Action/Description values in RFC 2960, Table 2.
1323 static char sctp_tietags_compare(struct sctp_association *new_asoc,
1324 const struct sctp_association *asoc)
1326 /* In this case, the peer may have restarted. */
1327 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1328 (asoc->c.peer_vtag != new_asoc->c.peer_vtag) &&
1329 (asoc->c.my_vtag == new_asoc->c.my_ttag) &&
1330 (asoc->c.peer_vtag == new_asoc->c.peer_ttag))
1333 /* Collision case B. */
1334 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1335 ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) ||
1336 (0 == asoc->c.peer_vtag))) {
1340 /* Collision case D. */
1341 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1342 (asoc->c.peer_vtag == new_asoc->c.peer_vtag))
1345 /* Collision case C. */
1346 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1347 (asoc->c.peer_vtag == new_asoc->c.peer_vtag) &&
1348 (0 == new_asoc->c.my_ttag) &&
1349 (0 == new_asoc->c.peer_ttag))
1352 /* No match to any of the special cases; discard this packet. */
1356 /* Common helper routine for both duplicate and simulataneous INIT
1359 static sctp_disposition_t sctp_sf_do_unexpected_init(
1360 const struct sctp_endpoint *ep,
1361 const struct sctp_association *asoc,
1362 const sctp_subtype_t type,
1363 void *arg, sctp_cmd_seq_t *commands)
1365 sctp_disposition_t retval;
1366 struct sctp_chunk *chunk = arg;
1367 struct sctp_chunk *repl;
1368 struct sctp_association *new_asoc;
1369 struct sctp_chunk *err_chunk;
1370 struct sctp_packet *packet;
1371 sctp_unrecognized_param_t *unk_param;
1375 * An endpoint MUST NOT bundle INIT, INIT ACK or
1376 * SHUTDOWN COMPLETE with any other chunks.
1379 * Furthermore, we require that the receiver of an INIT chunk MUST
1380 * enforce these rules by silently discarding an arriving packet
1381 * with an INIT chunk that is bundled with other chunks.
1383 if (!chunk->singleton)
1384 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1386 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1389 if (chunk->sctp_hdr->vtag != 0)
1390 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
1392 /* Make sure that the INIT chunk has a valid length.
1393 * In this case, we generate a protocol violation since we have
1394 * an association established.
1396 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
1397 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1399 /* Grab the INIT header. */
1400 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
1402 /* Tag the variable length parameters. */
1403 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
1405 /* Verify the INIT chunk before processing it. */
1407 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
1408 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
1410 /* This chunk contains fatal error. It is to be discarded.
1411 * Send an ABORT, with causes if there is any.
1414 packet = sctp_abort_pkt_new(ep, asoc, arg,
1415 (__u8 *)(err_chunk->chunk_hdr) +
1416 sizeof(sctp_chunkhdr_t),
1417 ntohs(err_chunk->chunk_hdr->length) -
1418 sizeof(sctp_chunkhdr_t));
1421 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
1422 SCTP_PACKET(packet));
1423 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1424 retval = SCTP_DISPOSITION_CONSUME;
1426 retval = SCTP_DISPOSITION_NOMEM;
1430 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
1436 * Other parameters for the endpoint SHOULD be copied from the
1437 * existing parameters of the association (e.g. number of
1438 * outbound streams) into the INIT ACK and cookie.
1439 * FIXME: We are copying parameters from the endpoint not the
1442 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
1446 /* In the outbound INIT ACK the endpoint MUST copy its current
1447 * Verification Tag and Peers Verification tag into a reserved
1448 * place (local tie-tag and per tie-tag) within the state cookie.
1450 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1452 (sctp_init_chunk_t *)chunk->chunk_hdr,
1456 /* Make sure no new addresses are being added during the
1457 * restart. Do not do this check for COOKIE-WAIT state,
1458 * since there are no peer addresses to check against.
1459 * Upon return an ABORT will have been sent if needed.
1461 if (!sctp_state(asoc, COOKIE_WAIT)) {
1462 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
1464 retval = SCTP_DISPOSITION_CONSUME;
1469 sctp_tietags_populate(new_asoc, asoc);
1471 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1473 /* If there are errors need to be reported for unknown parameters,
1474 * make sure to reserve enough room in the INIT ACK for them.
1478 len = ntohs(err_chunk->chunk_hdr->length) -
1479 sizeof(sctp_chunkhdr_t);
1482 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
1485 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
1489 /* If there are errors need to be reported for unknown parameters,
1490 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1494 /* Get the "Unrecognized parameter" parameter(s) out of the
1495 * ERROR chunk generated by sctp_verify_init(). Since the
1496 * error cause code for "unknown parameter" and the
1497 * "Unrecognized parameter" type is the same, we can
1498 * construct the parameters in INIT ACK by copying the
1499 * ERROR causes over.
1501 unk_param = (sctp_unrecognized_param_t *)
1502 ((__u8 *)(err_chunk->chunk_hdr) +
1503 sizeof(sctp_chunkhdr_t));
1504 /* Replace the cause code with the "Unrecognized parameter"
1507 sctp_addto_chunk(repl, len, unk_param);
1510 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1511 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1514 * Note: After sending out INIT ACK with the State Cookie parameter,
1515 * "Z" MUST NOT allocate any resources for this new association.
1516 * Otherwise, "Z" will be vulnerable to resource attacks.
1518 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1519 retval = SCTP_DISPOSITION_CONSUME;
1524 retval = SCTP_DISPOSITION_NOMEM;
1527 sctp_association_free(new_asoc);
1530 sctp_chunk_free(err_chunk);
1535 * Handle simultanous INIT.
1536 * This means we started an INIT and then we got an INIT request from
1539 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1540 * This usually indicates an initialization collision, i.e., each
1541 * endpoint is attempting, at about the same time, to establish an
1542 * association with the other endpoint.
1544 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1545 * endpoint MUST respond with an INIT ACK using the same parameters it
1546 * sent in its original INIT chunk (including its Verification Tag,
1547 * unchanged). These original parameters are combined with those from the
1548 * newly received INIT chunk. The endpoint shall also generate a State
1549 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1550 * INIT to calculate the State Cookie.
1552 * After that, the endpoint MUST NOT change its state, the T1-init
1553 * timer shall be left running and the corresponding TCB MUST NOT be
1554 * destroyed. The normal procedures for handling State Cookies when
1555 * a TCB exists will resolve the duplicate INITs to a single association.
1557 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1558 * its Tie-Tags with the Tag information of itself and its peer (see
1559 * section 5.2.2 for a description of the Tie-Tags).
1561 * Verification Tag: Not explicit, but an INIT can not have a valid
1562 * verification tag, so we skip the check.
1565 * (endpoint, asoc, chunk)
1568 * (asoc, reply_msg, msg_up, timers, counters)
1570 * The return value is the disposition of the chunk.
1572 sctp_disposition_t sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint *ep,
1573 const struct sctp_association *asoc,
1574 const sctp_subtype_t type,
1576 sctp_cmd_seq_t *commands)
1578 /* Call helper to do the real work for both simulataneous and
1579 * duplicate INIT chunk handling.
1581 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1585 * Handle duplicated INIT messages. These are usually delayed
1588 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1589 * COOKIE-ECHOED and COOKIE-WAIT
1591 * Unless otherwise stated, upon reception of an unexpected INIT for
1592 * this association, the endpoint shall generate an INIT ACK with a
1593 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1594 * current Verification Tag and peer's Verification Tag into a reserved
1595 * place within the state cookie. We shall refer to these locations as
1596 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1597 * containing this INIT ACK MUST carry a Verification Tag value equal to
1598 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1599 * MUST contain a new Initiation Tag (randomly generated see Section
1600 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1601 * existing parameters of the association (e.g. number of outbound
1602 * streams) into the INIT ACK and cookie.
1604 * After sending out the INIT ACK, the endpoint shall take no further
1605 * actions, i.e., the existing association, including its current state,
1606 * and the corresponding TCB MUST NOT be changed.
1608 * Note: Only when a TCB exists and the association is not in a COOKIE-
1609 * WAIT state are the Tie-Tags populated. For a normal association INIT
1610 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1611 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1612 * State Cookie are populated as specified in section 5.2.1.
1614 * Verification Tag: Not specified, but an INIT has no way of knowing
1615 * what the verification tag could be, so we ignore it.
1618 * (endpoint, asoc, chunk)
1621 * (asoc, reply_msg, msg_up, timers, counters)
1623 * The return value is the disposition of the chunk.
1625 sctp_disposition_t sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint *ep,
1626 const struct sctp_association *asoc,
1627 const sctp_subtype_t type,
1629 sctp_cmd_seq_t *commands)
1631 /* Call helper to do the real work for both simulataneous and
1632 * duplicate INIT chunk handling.
1634 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1639 * Unexpected INIT-ACK handler.
1642 * If an INIT ACK received by an endpoint in any state other than the
1643 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1644 * An unexpected INIT ACK usually indicates the processing of an old or
1645 * duplicated INIT chunk.
1647 sctp_disposition_t sctp_sf_do_5_2_3_initack(const struct sctp_endpoint *ep,
1648 const struct sctp_association *asoc,
1649 const sctp_subtype_t type,
1650 void *arg, sctp_cmd_seq_t *commands)
1652 /* Per the above section, we'll discard the chunk if we have an
1653 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1655 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
1656 return sctp_sf_ootb(ep, asoc, type, arg, commands);
1658 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
1661 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1664 * A) In this case, the peer may have restarted.
1666 static sctp_disposition_t sctp_sf_do_dupcook_a(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_ulpevent *ev;
1674 struct sctp_chunk *repl;
1675 struct sctp_chunk *err;
1676 sctp_disposition_t disposition;
1678 /* new_asoc is a brand-new association, so these are not yet
1679 * side effects--it is safe to run them here.
1681 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1683 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1684 sctp_source(chunk), peer_init,
1688 /* Make sure no new addresses are being added during the
1689 * restart. Though this is a pretty complicated attack
1690 * since you'd have to get inside the cookie.
1692 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) {
1693 return SCTP_DISPOSITION_CONSUME;
1696 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1697 * the peer has restarted (Action A), it MUST NOT setup a new
1698 * association but instead resend the SHUTDOWN ACK and send an ERROR
1699 * chunk with a "Cookie Received while Shutting Down" error cause to
1702 if (sctp_state(asoc, SHUTDOWN_ACK_SENT)) {
1703 disposition = sctp_sf_do_9_2_reshutack(ep, asoc,
1704 SCTP_ST_CHUNK(chunk->chunk_hdr->type),
1706 if (SCTP_DISPOSITION_NOMEM == disposition)
1709 err = sctp_make_op_error(asoc, chunk,
1710 SCTP_ERROR_COOKIE_IN_SHUTDOWN,
1713 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1716 return SCTP_DISPOSITION_CONSUME;
1719 /* For now, fail any unsent/unacked data. Consider the optional
1720 * choice of resending of this data.
1722 sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL());
1724 repl = sctp_make_cookie_ack(new_asoc, chunk);
1728 /* Report association restart to upper layer. */
1729 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0,
1730 new_asoc->c.sinit_num_ostreams,
1731 new_asoc->c.sinit_max_instreams,
1736 /* Update the content of current association. */
1737 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1738 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1739 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1740 return SCTP_DISPOSITION_CONSUME;
1743 sctp_chunk_free(repl);
1745 return SCTP_DISPOSITION_NOMEM;
1748 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1751 * B) In this case, both sides may be attempting to start an association
1752 * at about the same time but the peer endpoint started its INIT
1753 * after responding to the local endpoint's INIT
1755 /* This case represents an initialization collision. */
1756 static sctp_disposition_t sctp_sf_do_dupcook_b(const struct sctp_endpoint *ep,
1757 const struct sctp_association *asoc,
1758 struct sctp_chunk *chunk,
1759 sctp_cmd_seq_t *commands,
1760 struct sctp_association *new_asoc)
1762 sctp_init_chunk_t *peer_init;
1763 struct sctp_chunk *repl;
1765 /* new_asoc is a brand-new association, so these are not yet
1766 * side effects--it is safe to run them here.
1768 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1769 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1770 sctp_source(chunk), peer_init,
1774 /* Update the content of current association. */
1775 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1776 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1777 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1778 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
1779 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
1781 repl = sctp_make_cookie_ack(new_asoc, chunk);
1785 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1786 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1788 /* RFC 2960 5.1 Normal Establishment of an Association
1790 * D) IMPLEMENTATION NOTE: An implementation may choose to
1791 * send the Communication Up notification to the SCTP user
1792 * upon reception of a valid COOKIE ECHO chunk.
1794 * Sadly, this needs to be implemented as a side-effect, because
1795 * we are not guaranteed to have set the association id of the real
1796 * association and so these notifications need to be delayed until
1797 * the association id is allocated.
1800 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_CHANGE, SCTP_U8(SCTP_COMM_UP));
1802 /* Sockets API Draft Section 5.3.1.6
1803 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1804 * delivers this notification to inform the application that of the
1805 * peers requested adaptation layer.
1807 * This also needs to be done as a side effect for the same reason as
1810 if (asoc->peer.adaptation_ind)
1811 sctp_add_cmd_sf(commands, SCTP_CMD_ADAPTATION_IND, SCTP_NULL());
1813 return SCTP_DISPOSITION_CONSUME;
1816 return SCTP_DISPOSITION_NOMEM;
1819 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1822 * C) In this case, the local endpoint's cookie has arrived late.
1823 * Before it arrived, the local endpoint sent an INIT and received an
1824 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1825 * but a new tag of its own.
1827 /* This case represents an initialization collision. */
1828 static sctp_disposition_t sctp_sf_do_dupcook_c(const struct sctp_endpoint *ep,
1829 const struct sctp_association *asoc,
1830 struct sctp_chunk *chunk,
1831 sctp_cmd_seq_t *commands,
1832 struct sctp_association *new_asoc)
1834 /* The cookie should be silently discarded.
1835 * The endpoint SHOULD NOT change states and should leave
1836 * any timers running.
1838 return SCTP_DISPOSITION_DISCARD;
1841 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1845 * D) When both local and remote tags match the endpoint should always
1846 * enter the ESTABLISHED state, if it has not already done so.
1848 /* This case represents an initialization collision. */
1849 static sctp_disposition_t sctp_sf_do_dupcook_d(const struct sctp_endpoint *ep,
1850 const struct sctp_association *asoc,
1851 struct sctp_chunk *chunk,
1852 sctp_cmd_seq_t *commands,
1853 struct sctp_association *new_asoc)
1855 struct sctp_ulpevent *ev = NULL, *ai_ev = NULL;
1856 struct sctp_chunk *repl;
1858 /* Clarification from Implementor's Guide:
1859 * D) When both local and remote tags match the endpoint should
1860 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1861 * It should stop any cookie timer that may be running and send
1865 /* Don't accidentally move back into established state. */
1866 if (asoc->state < SCTP_STATE_ESTABLISHED) {
1867 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1868 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
1869 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1870 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1871 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
1872 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START,
1875 /* RFC 2960 5.1 Normal Establishment of an Association
1877 * D) IMPLEMENTATION NOTE: An implementation may choose
1878 * to send the Communication Up notification to the
1879 * SCTP user upon reception of a valid COOKIE
1882 ev = sctp_ulpevent_make_assoc_change(asoc, 0,
1884 asoc->c.sinit_num_ostreams,
1885 asoc->c.sinit_max_instreams,
1890 /* Sockets API Draft Section 5.3.1.6
1891 * When a peer sends a Adaptation Layer Indication parameter,
1892 * SCTP delivers this notification to inform the application
1893 * that of the peers requested adaptation layer.
1895 if (asoc->peer.adaptation_ind) {
1896 ai_ev = sctp_ulpevent_make_adaptation_indication(asoc,
1903 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1905 repl = sctp_make_cookie_ack(new_asoc, chunk);
1910 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1913 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1914 SCTP_ULPEVENT(ai_ev));
1916 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1917 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1919 return SCTP_DISPOSITION_CONSUME;
1923 sctp_ulpevent_free(ai_ev);
1925 sctp_ulpevent_free(ev);
1926 return SCTP_DISPOSITION_NOMEM;
1930 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1931 * chunk was retransmitted and then delayed in the network.
1933 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1935 * Verification Tag: None. Do cookie validation.
1938 * (endpoint, asoc, chunk)
1941 * (asoc, reply_msg, msg_up, timers, counters)
1943 * The return value is the disposition of the chunk.
1945 sctp_disposition_t sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint *ep,
1946 const struct sctp_association *asoc,
1947 const sctp_subtype_t type,
1949 sctp_cmd_seq_t *commands)
1951 sctp_disposition_t retval;
1952 struct sctp_chunk *chunk = arg;
1953 struct sctp_association *new_asoc;
1956 struct sctp_chunk *err_chk_p;
1958 /* Make sure that the chunk has a valid length from the protocol
1959 * perspective. In this case check to make sure we have at least
1960 * enough for the chunk header. Cookie length verification is
1963 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
1964 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1967 /* "Decode" the chunk. We have no optional parameters so we
1968 * are in good shape.
1970 chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data;
1971 if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
1972 sizeof(sctp_chunkhdr_t)))
1975 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
1976 * of a duplicate COOKIE ECHO match the Verification Tags of the
1977 * current association, consider the State Cookie valid even if
1978 * the lifespan is exceeded.
1980 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
1984 * If the re-build failed, what is the proper error path
1987 * [We should abort the association. --piggy]
1990 /* FIXME: Several errors are possible. A bad cookie should
1991 * be silently discarded, but think about logging it too.
1994 case -SCTP_IERROR_NOMEM:
1997 case -SCTP_IERROR_STALE_COOKIE:
1998 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
2000 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2001 case -SCTP_IERROR_BAD_SIG:
2003 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2007 /* Compare the tie_tag in cookie with the verification tag of
2008 * current association.
2010 action = sctp_tietags_compare(new_asoc, asoc);
2013 case 'A': /* Association restart. */
2014 retval = sctp_sf_do_dupcook_a(ep, asoc, chunk, commands,
2018 case 'B': /* Collision case B. */
2019 retval = sctp_sf_do_dupcook_b(ep, asoc, chunk, commands,
2023 case 'C': /* Collision case C. */
2024 retval = sctp_sf_do_dupcook_c(ep, asoc, chunk, commands,
2028 case 'D': /* Collision case D. */
2029 retval = sctp_sf_do_dupcook_d(ep, asoc, chunk, commands,
2033 default: /* Discard packet for all others. */
2034 retval = sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2038 /* Delete the tempory new association. */
2039 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
2040 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
2045 return SCTP_DISPOSITION_NOMEM;
2049 * Process an ABORT. (SHUTDOWN-PENDING state)
2051 * See sctp_sf_do_9_1_abort().
2053 sctp_disposition_t sctp_sf_shutdown_pending_abort(
2054 const struct sctp_endpoint *ep,
2055 const struct sctp_association *asoc,
2056 const sctp_subtype_t type,
2058 sctp_cmd_seq_t *commands)
2060 struct sctp_chunk *chunk = arg;
2062 if (!sctp_vtag_verify_either(chunk, asoc))
2063 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2065 /* Make sure that the ABORT chunk has a valid length.
2066 * Since this is an ABORT chunk, we have to discard it
2067 * because of the following text:
2068 * RFC 2960, Section 3.3.7
2069 * If an endpoint receives an ABORT with a format error or for an
2070 * association that doesn't exist, it MUST silently discard it.
2071 * Becasue the length is "invalid", we can't really discard just
2072 * as we do not know its true length. So, to be safe, discard the
2075 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2076 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2078 /* ADD-IP: Special case for ABORT chunks
2079 * F4) One special consideration is that ABORT Chunks arriving
2080 * destined to the IP address being deleted MUST be
2081 * ignored (see Section 5.3.1 for further details).
2083 if (SCTP_ADDR_DEL ==
2084 sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
2085 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
2087 /* Stop the T5-shutdown guard timer. */
2088 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2089 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
2091 return __sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
2095 * Process an ABORT. (SHUTDOWN-SENT state)
2097 * See sctp_sf_do_9_1_abort().
2099 sctp_disposition_t sctp_sf_shutdown_sent_abort(const struct sctp_endpoint *ep,
2100 const struct sctp_association *asoc,
2101 const sctp_subtype_t type,
2103 sctp_cmd_seq_t *commands)
2105 struct sctp_chunk *chunk = arg;
2107 if (!sctp_vtag_verify_either(chunk, asoc))
2108 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2110 /* Make sure that the ABORT chunk has a valid length.
2111 * Since this is an ABORT chunk, we have to discard it
2112 * because of the following text:
2113 * RFC 2960, Section 3.3.7
2114 * If an endpoint receives an ABORT with a format error or for an
2115 * association that doesn't exist, it MUST silently discard it.
2116 * Becasue the length is "invalid", we can't really discard just
2117 * as we do not know its true length. So, to be safe, discard the
2120 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2121 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2123 /* ADD-IP: Special case for ABORT chunks
2124 * F4) One special consideration is that ABORT Chunks arriving
2125 * destined to the IP address being deleted MUST be
2126 * ignored (see Section 5.3.1 for further details).
2128 if (SCTP_ADDR_DEL ==
2129 sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
2130 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
2132 /* Stop the T2-shutdown timer. */
2133 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2134 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2136 /* Stop the T5-shutdown guard timer. */
2137 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2138 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
2140 return __sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
2144 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2146 * See sctp_sf_do_9_1_abort().
2148 sctp_disposition_t sctp_sf_shutdown_ack_sent_abort(
2149 const struct sctp_endpoint *ep,
2150 const struct sctp_association *asoc,
2151 const sctp_subtype_t type,
2153 sctp_cmd_seq_t *commands)
2155 /* The same T2 timer, so we should be able to use
2156 * common function with the SHUTDOWN-SENT state.
2158 return sctp_sf_shutdown_sent_abort(ep, asoc, type, arg, commands);
2162 * Handle an Error received in COOKIE_ECHOED state.
2164 * Only handle the error type of stale COOKIE Error, the other errors will
2168 * (endpoint, asoc, chunk)
2171 * (asoc, reply_msg, msg_up, timers, counters)
2173 * The return value is the disposition of the chunk.
2175 sctp_disposition_t sctp_sf_cookie_echoed_err(const struct sctp_endpoint *ep,
2176 const struct sctp_association *asoc,
2177 const sctp_subtype_t type,
2179 sctp_cmd_seq_t *commands)
2181 struct sctp_chunk *chunk = arg;
2184 if (!sctp_vtag_verify(chunk, asoc))
2185 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2187 /* Make sure that the ERROR chunk has a valid length.
2188 * The parameter walking depends on this as well.
2190 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t)))
2191 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2194 /* Process the error here */
2195 /* FUTURE FIXME: When PR-SCTP related and other optional
2196 * parms are emitted, this will have to change to handle multiple
2199 sctp_walk_errors(err, chunk->chunk_hdr) {
2200 if (SCTP_ERROR_STALE_COOKIE == err->cause)
2201 return sctp_sf_do_5_2_6_stale(ep, asoc, type,
2205 /* It is possible to have malformed error causes, and that
2206 * will cause us to end the walk early. However, since
2207 * we are discarding the packet, there should be no adverse
2210 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2214 * Handle a Stale COOKIE Error
2216 * Section: 5.2.6 Handle Stale COOKIE Error
2217 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2218 * one of the following three alternatives.
2220 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2221 * Preservative parameter requesting an extension to the lifetime of
2222 * the State Cookie. When calculating the time extension, an
2223 * implementation SHOULD use the RTT information measured based on the
2224 * previous COOKIE ECHO / ERROR exchange, and should add no more
2225 * than 1 second beyond the measured RTT, due to long State Cookie
2226 * lifetimes making the endpoint more subject to a replay attack.
2228 * Verification Tag: Not explicit, but safe to ignore.
2231 * (endpoint, asoc, chunk)
2234 * (asoc, reply_msg, msg_up, timers, counters)
2236 * The return value is the disposition of the chunk.
2238 static sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep,
2239 const struct sctp_association *asoc,
2240 const sctp_subtype_t type,
2242 sctp_cmd_seq_t *commands)
2244 struct sctp_chunk *chunk = arg;
2246 sctp_cookie_preserve_param_t bht;
2248 struct sctp_chunk *reply;
2249 struct sctp_bind_addr *bp;
2250 int attempts = asoc->init_err_counter + 1;
2252 if (attempts > asoc->max_init_attempts) {
2253 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
2254 SCTP_ERROR(ETIMEDOUT));
2255 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2256 SCTP_PERR(SCTP_ERROR_STALE_COOKIE));
2257 return SCTP_DISPOSITION_DELETE_TCB;
2260 err = (sctp_errhdr_t *)(chunk->skb->data);
2262 /* When calculating the time extension, an implementation
2263 * SHOULD use the RTT information measured based on the
2264 * previous COOKIE ECHO / ERROR exchange, and should add no
2265 * more than 1 second beyond the measured RTT, due to long
2266 * State Cookie lifetimes making the endpoint more subject to
2268 * Measure of Staleness's unit is usec. (1/1000000 sec)
2269 * Suggested Cookie Life-span Increment's unit is msec.
2271 * In general, if you use the suggested cookie life, the value
2272 * found in the field of measure of staleness should be doubled
2273 * to give ample time to retransmit the new cookie and thus
2274 * yield a higher probability of success on the reattempt.
2276 stale = ntohl(*(__be32 *)((u8 *)err + sizeof(sctp_errhdr_t)));
2277 stale = (stale * 2) / 1000;
2279 bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE;
2280 bht.param_hdr.length = htons(sizeof(bht));
2281 bht.lifespan_increment = htonl(stale);
2283 /* Build that new INIT chunk. */
2284 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
2285 reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht));
2289 sctp_addto_chunk(reply, sizeof(bht), &bht);
2291 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2292 sctp_add_cmd_sf(commands, SCTP_CMD_CLEAR_INIT_TAG, SCTP_NULL());
2294 /* Stop pending T3-rtx and heartbeat timers */
2295 sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL());
2296 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
2298 /* Delete non-primary peer ip addresses since we are transitioning
2299 * back to the COOKIE-WAIT state
2301 sctp_add_cmd_sf(commands, SCTP_CMD_DEL_NON_PRIMARY, SCTP_NULL());
2303 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2306 sctp_add_cmd_sf(commands, SCTP_CMD_T1_RETRAN,
2307 SCTP_TRANSPORT(asoc->peer.primary_path));
2309 /* Cast away the const modifier, as we want to just
2310 * rerun it through as a sideffect.
2312 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_INC, SCTP_NULL());
2314 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2315 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
2316 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2317 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
2318 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
2319 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2321 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2323 return SCTP_DISPOSITION_CONSUME;
2326 return SCTP_DISPOSITION_NOMEM;
2333 * After checking the Verification Tag, the receiving endpoint shall
2334 * remove the association from its record, and shall report the
2335 * termination to its upper layer.
2337 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2338 * B) Rules for packet carrying ABORT:
2340 * - The endpoint shall always fill in the Verification Tag field of the
2341 * outbound packet with the destination endpoint's tag value if it
2344 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2345 * MUST follow the procedure described in Section 8.4.
2347 * - The receiver MUST accept the packet if the Verification Tag
2348 * matches either its own tag, OR the tag of its peer. Otherwise, the
2349 * receiver MUST silently discard the packet and take no further
2353 * (endpoint, asoc, chunk)
2356 * (asoc, reply_msg, msg_up, timers, counters)
2358 * The return value is the disposition of the chunk.
2360 sctp_disposition_t sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep,
2361 const struct sctp_association *asoc,
2362 const sctp_subtype_t type,
2364 sctp_cmd_seq_t *commands)
2366 struct sctp_chunk *chunk = arg;
2368 if (!sctp_vtag_verify_either(chunk, asoc))
2369 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2371 /* Make sure that the ABORT chunk has a valid length.
2372 * Since this is an ABORT chunk, we have to discard it
2373 * because of the following text:
2374 * RFC 2960, Section 3.3.7
2375 * If an endpoint receives an ABORT with a format error or for an
2376 * association that doesn't exist, it MUST silently discard it.
2377 * Becasue the length is "invalid", we can't really discard just
2378 * as we do not know its true length. So, to be safe, discard the
2381 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2382 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2384 /* ADD-IP: Special case for ABORT chunks
2385 * F4) One special consideration is that ABORT Chunks arriving
2386 * destined to the IP address being deleted MUST be
2387 * ignored (see Section 5.3.1 for further details).
2389 if (SCTP_ADDR_DEL ==
2390 sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
2391 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
2393 return __sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
2396 static sctp_disposition_t __sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep,
2397 const struct sctp_association *asoc,
2398 const sctp_subtype_t type,
2400 sctp_cmd_seq_t *commands)
2402 struct sctp_chunk *chunk = arg;
2404 __be16 error = SCTP_ERROR_NO_ERROR;
2406 /* See if we have an error cause code in the chunk. */
2407 len = ntohs(chunk->chunk_hdr->length);
2408 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2409 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2411 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNRESET));
2412 /* ASSOC_FAILED will DELETE_TCB. */
2413 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_PERR(error));
2414 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
2415 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
2417 return SCTP_DISPOSITION_ABORT;
2421 * Process an ABORT. (COOKIE-WAIT state)
2423 * See sctp_sf_do_9_1_abort() above.
2425 sctp_disposition_t sctp_sf_cookie_wait_abort(const struct sctp_endpoint *ep,
2426 const struct sctp_association *asoc,
2427 const sctp_subtype_t type,
2429 sctp_cmd_seq_t *commands)
2431 struct sctp_chunk *chunk = arg;
2433 __be16 error = SCTP_ERROR_NO_ERROR;
2435 if (!sctp_vtag_verify_either(chunk, asoc))
2436 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2438 /* Make sure that the ABORT chunk has a valid length.
2439 * Since this is an ABORT chunk, we have to discard it
2440 * because of the following text:
2441 * RFC 2960, Section 3.3.7
2442 * If an endpoint receives an ABORT with a format error or for an
2443 * association that doesn't exist, it MUST silently discard it.
2444 * Becasue the length is "invalid", we can't really discard just
2445 * as we do not know its true length. So, to be safe, discard the
2448 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2449 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2451 /* See if we have an error cause code in the chunk. */
2452 len = ntohs(chunk->chunk_hdr->length);
2453 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2454 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2456 return sctp_stop_t1_and_abort(commands, error, ECONNREFUSED, asoc,
2461 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2463 sctp_disposition_t sctp_sf_cookie_wait_icmp_abort(const struct sctp_endpoint *ep,
2464 const struct sctp_association *asoc,
2465 const sctp_subtype_t type,
2467 sctp_cmd_seq_t *commands)
2469 return sctp_stop_t1_and_abort(commands, SCTP_ERROR_NO_ERROR,
2471 (struct sctp_transport *)arg);
2475 * Process an ABORT. (COOKIE-ECHOED state)
2477 sctp_disposition_t sctp_sf_cookie_echoed_abort(const struct sctp_endpoint *ep,
2478 const struct sctp_association *asoc,
2479 const sctp_subtype_t type,
2481 sctp_cmd_seq_t *commands)
2483 /* There is a single T1 timer, so we should be able to use
2484 * common function with the COOKIE-WAIT state.
2486 return sctp_sf_cookie_wait_abort(ep, asoc, type, arg, commands);
2490 * Stop T1 timer and abort association with "INIT failed".
2492 * This is common code called by several sctp_sf_*_abort() functions above.
2494 static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands,
2495 __be16 error, int sk_err,
2496 const struct sctp_association *asoc,
2497 struct sctp_transport *transport)
2499 SCTP_DEBUG_PRINTK("ABORT received (INIT).\n");
2500 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2501 SCTP_STATE(SCTP_STATE_CLOSED));
2502 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
2503 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2504 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2505 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(sk_err));
2506 /* CMD_INIT_FAILED will DELETE_TCB. */
2507 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2509 return SCTP_DISPOSITION_ABORT;
2513 * sctp_sf_do_9_2_shut
2516 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2517 * - enter the SHUTDOWN-RECEIVED state,
2519 * - stop accepting new data from its SCTP user
2521 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2522 * that all its outstanding DATA chunks have been received by the
2525 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2526 * send a SHUTDOWN in response to a ULP request. And should discard
2527 * subsequent SHUTDOWN chunks.
2529 * If there are still outstanding DATA chunks left, the SHUTDOWN
2530 * receiver shall continue to follow normal data transmission
2531 * procedures defined in Section 6 until all outstanding DATA chunks
2532 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2533 * new data from its SCTP user.
2535 * Verification Tag: 8.5 Verification Tag [Normal verification]
2538 * (endpoint, asoc, chunk)
2541 * (asoc, reply_msg, msg_up, timers, counters)
2543 * The return value is the disposition of the chunk.
2545 sctp_disposition_t sctp_sf_do_9_2_shutdown(const struct sctp_endpoint *ep,
2546 const struct sctp_association *asoc,
2547 const sctp_subtype_t type,
2549 sctp_cmd_seq_t *commands)
2551 struct sctp_chunk *chunk = arg;
2552 sctp_shutdownhdr_t *sdh;
2553 sctp_disposition_t disposition;
2554 struct sctp_ulpevent *ev;
2556 if (!sctp_vtag_verify(chunk, asoc))
2557 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2559 /* Make sure that the SHUTDOWN chunk has a valid length. */
2560 if (!sctp_chunk_length_valid(chunk,
2561 sizeof(struct sctp_shutdown_chunk_t)))
2562 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2565 /* Convert the elaborate header. */
2566 sdh = (sctp_shutdownhdr_t *)chunk->skb->data;
2567 skb_pull(chunk->skb, sizeof(sctp_shutdownhdr_t));
2568 chunk->subh.shutdown_hdr = sdh;
2570 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2571 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2572 * inform the application that it should cease sending data.
2574 ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC);
2576 disposition = SCTP_DISPOSITION_NOMEM;
2579 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
2581 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2582 * - enter the SHUTDOWN-RECEIVED state,
2583 * - stop accepting new data from its SCTP user
2585 * [This is implicit in the new state.]
2587 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2588 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED));
2589 disposition = SCTP_DISPOSITION_CONSUME;
2591 if (sctp_outq_is_empty(&asoc->outqueue)) {
2592 disposition = sctp_sf_do_9_2_shutdown_ack(ep, asoc, type,
2596 if (SCTP_DISPOSITION_NOMEM == disposition)
2599 /* - verify, by checking the Cumulative TSN Ack field of the
2600 * chunk, that all its outstanding DATA chunks have been
2601 * received by the SHUTDOWN sender.
2603 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
2604 SCTP_BE32(chunk->subh.shutdown_hdr->cum_tsn_ack));
2611 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2612 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2613 * transport addresses (either in the IP addresses or in the INIT chunk)
2614 * that belong to this association, it should discard the INIT chunk and
2615 * retransmit the SHUTDOWN ACK chunk.
2617 sctp_disposition_t sctp_sf_do_9_2_reshutack(const struct sctp_endpoint *ep,
2618 const struct sctp_association *asoc,
2619 const sctp_subtype_t type,
2621 sctp_cmd_seq_t *commands)
2623 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
2624 struct sctp_chunk *reply;
2626 /* Make sure that the chunk has a valid length */
2627 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
2628 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2631 /* Since we are not going to really process this INIT, there
2632 * is no point in verifying chunk boundries. Just generate
2635 reply = sctp_make_shutdown_ack(asoc, chunk);
2639 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2640 * the T2-SHUTDOWN timer.
2642 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
2644 /* and restart the T2-shutdown timer. */
2645 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2646 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2648 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2650 return SCTP_DISPOSITION_CONSUME;
2652 return SCTP_DISPOSITION_NOMEM;
2656 * sctp_sf_do_ecn_cwr
2658 * Section: Appendix A: Explicit Congestion Notification
2662 * RFC 2481 details a specific bit for a sender to send in the header of
2663 * its next outbound TCP segment to indicate to its peer that it has
2664 * reduced its congestion window. This is termed the CWR bit. For
2665 * SCTP the same indication is made by including the CWR chunk.
2666 * This chunk contains one data element, i.e. the TSN number that
2667 * was sent in the ECNE chunk. This element represents the lowest
2668 * TSN number in the datagram that was originally marked with the
2671 * Verification Tag: 8.5 Verification Tag [Normal verification]
2673 * (endpoint, asoc, chunk)
2676 * (asoc, reply_msg, msg_up, timers, counters)
2678 * The return value is the disposition of the chunk.
2680 sctp_disposition_t sctp_sf_do_ecn_cwr(const struct sctp_endpoint *ep,
2681 const struct sctp_association *asoc,
2682 const sctp_subtype_t type,
2684 sctp_cmd_seq_t *commands)
2687 struct sctp_chunk *chunk = arg;
2690 if (!sctp_vtag_verify(chunk, asoc))
2691 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2693 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t)))
2694 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2697 cwr = (sctp_cwrhdr_t *) chunk->skb->data;
2698 skb_pull(chunk->skb, sizeof(sctp_cwrhdr_t));
2700 lowest_tsn = ntohl(cwr->lowest_tsn);
2702 /* Does this CWR ack the last sent congestion notification? */
2703 if (TSN_lte(asoc->last_ecne_tsn, lowest_tsn)) {
2704 /* Stop sending ECNE. */
2705 sctp_add_cmd_sf(commands,
2707 SCTP_U32(lowest_tsn));
2709 return SCTP_DISPOSITION_CONSUME;
2715 * Section: Appendix A: Explicit Congestion Notification
2719 * RFC 2481 details a specific bit for a receiver to send back in its
2720 * TCP acknowledgements to notify the sender of the Congestion
2721 * Experienced (CE) bit having arrived from the network. For SCTP this
2722 * same indication is made by including the ECNE chunk. This chunk
2723 * contains one data element, i.e. the lowest TSN associated with the IP
2724 * datagram marked with the CE bit.....
2726 * Verification Tag: 8.5 Verification Tag [Normal verification]
2728 * (endpoint, asoc, chunk)
2731 * (asoc, reply_msg, msg_up, timers, counters)
2733 * The return value is the disposition of the chunk.
2735 sctp_disposition_t sctp_sf_do_ecne(const struct sctp_endpoint *ep,
2736 const struct sctp_association *asoc,
2737 const sctp_subtype_t type,
2739 sctp_cmd_seq_t *commands)
2741 sctp_ecnehdr_t *ecne;
2742 struct sctp_chunk *chunk = arg;
2744 if (!sctp_vtag_verify(chunk, asoc))
2745 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2747 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t)))
2748 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2751 ecne = (sctp_ecnehdr_t *) chunk->skb->data;
2752 skb_pull(chunk->skb, sizeof(sctp_ecnehdr_t));
2754 /* If this is a newer ECNE than the last CWR packet we sent out */
2755 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE,
2756 SCTP_U32(ntohl(ecne->lowest_tsn)));
2758 return SCTP_DISPOSITION_CONSUME;
2762 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2764 * The SCTP endpoint MUST always acknowledge the reception of each valid
2767 * The guidelines on delayed acknowledgement algorithm specified in
2768 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2769 * acknowledgement SHOULD be generated for at least every second packet
2770 * (not every second DATA chunk) received, and SHOULD be generated within
2771 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2772 * situations it may be beneficial for an SCTP transmitter to be more
2773 * conservative than the algorithms detailed in this document allow.
2774 * However, an SCTP transmitter MUST NOT be more aggressive than the
2775 * following algorithms allow.
2777 * A SCTP receiver MUST NOT generate more than one SACK for every
2778 * incoming packet, other than to update the offered window as the
2779 * receiving application consumes new data.
2781 * Verification Tag: 8.5 Verification Tag [Normal verification]
2784 * (endpoint, asoc, chunk)
2787 * (asoc, reply_msg, msg_up, timers, counters)
2789 * The return value is the disposition of the chunk.
2791 sctp_disposition_t sctp_sf_eat_data_6_2(const struct sctp_endpoint *ep,
2792 const struct sctp_association *asoc,
2793 const sctp_subtype_t type,
2795 sctp_cmd_seq_t *commands)
2797 struct sctp_chunk *chunk = arg;
2800 if (!sctp_vtag_verify(chunk, asoc)) {
2801 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2803 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2806 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t)))
2807 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2810 error = sctp_eat_data(asoc, chunk, commands );
2812 case SCTP_IERROR_NO_ERROR:
2814 case SCTP_IERROR_HIGH_TSN:
2815 case SCTP_IERROR_BAD_STREAM:
2816 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
2817 goto discard_noforce;
2818 case SCTP_IERROR_DUP_TSN:
2819 case SCTP_IERROR_IGNORE_TSN:
2820 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
2822 case SCTP_IERROR_NO_DATA:
2828 if (asoc->autoclose) {
2829 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2830 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
2833 /* If this is the last chunk in a packet, we need to count it
2834 * toward sack generation. Note that we need to SACK every
2835 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2836 * THEM. We elect to NOT generate SACK's if the chunk fails
2837 * the verification tag test.
2839 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2841 * The SCTP endpoint MUST always acknowledge the reception of
2842 * each valid DATA chunk.
2844 * The guidelines on delayed acknowledgement algorithm
2845 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2846 * Specifically, an acknowledgement SHOULD be generated for at
2847 * least every second packet (not every second DATA chunk)
2848 * received, and SHOULD be generated within 200 ms of the
2849 * arrival of any unacknowledged DATA chunk. In some
2850 * situations it may be beneficial for an SCTP transmitter to
2851 * be more conservative than the algorithms detailed in this
2852 * document allow. However, an SCTP transmitter MUST NOT be
2853 * more aggressive than the following algorithms allow.
2855 if (chunk->end_of_packet)
2856 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2858 return SCTP_DISPOSITION_CONSUME;
2861 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2863 * When a packet arrives with duplicate DATA chunk(s) and with
2864 * no new DATA chunk(s), the endpoint MUST immediately send a
2865 * SACK with no delay. If a packet arrives with duplicate
2866 * DATA chunk(s) bundled with new DATA chunks, the endpoint
2867 * MAY immediately send a SACK. Normally receipt of duplicate
2868 * DATA chunks will occur when the original SACK chunk was lost
2869 * and the peer's RTO has expired. The duplicate TSN number(s)
2870 * SHOULD be reported in the SACK as duplicate.
2872 /* In our case, we split the MAY SACK advice up whether or not
2873 * the last chunk is a duplicate.'
2875 if (chunk->end_of_packet)
2876 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2877 return SCTP_DISPOSITION_DISCARD;
2880 if (chunk->end_of_packet)
2881 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2883 return SCTP_DISPOSITION_DISCARD;
2885 return SCTP_DISPOSITION_CONSUME;
2890 * sctp_sf_eat_data_fast_4_4
2893 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
2894 * DATA chunks without delay.
2896 * Verification Tag: 8.5 Verification Tag [Normal verification]
2898 * (endpoint, asoc, chunk)
2901 * (asoc, reply_msg, msg_up, timers, counters)
2903 * The return value is the disposition of the chunk.
2905 sctp_disposition_t sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint *ep,
2906 const struct sctp_association *asoc,
2907 const sctp_subtype_t type,
2909 sctp_cmd_seq_t *commands)
2911 struct sctp_chunk *chunk = arg;
2914 if (!sctp_vtag_verify(chunk, asoc)) {
2915 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2917 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2920 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t)))
2921 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2924 error = sctp_eat_data(asoc, chunk, commands );
2926 case SCTP_IERROR_NO_ERROR:
2927 case SCTP_IERROR_HIGH_TSN:
2928 case SCTP_IERROR_DUP_TSN:
2929 case SCTP_IERROR_IGNORE_TSN:
2930 case SCTP_IERROR_BAD_STREAM:
2932 case SCTP_IERROR_NO_DATA:
2938 /* Go a head and force a SACK, since we are shutting down. */
2940 /* Implementor's Guide.
2942 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
2943 * respond to each received packet containing one or more DATA chunk(s)
2944 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
2946 if (chunk->end_of_packet) {
2947 /* We must delay the chunk creation since the cumulative
2948 * TSN has not been updated yet.
2950 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
2951 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2952 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2953 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2957 return SCTP_DISPOSITION_CONSUME;
2961 * Section: 6.2 Processing a Received SACK
2962 * D) Any time a SACK arrives, the endpoint performs the following:
2964 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
2965 * then drop the SACK. Since Cumulative TSN Ack is monotonically
2966 * increasing, a SACK whose Cumulative TSN Ack is less than the
2967 * Cumulative TSN Ack Point indicates an out-of-order SACK.
2969 * ii) Set rwnd equal to the newly received a_rwnd minus the number
2970 * of bytes still outstanding after processing the Cumulative TSN Ack
2971 * and the Gap Ack Blocks.
2973 * iii) If the SACK is missing a TSN that was previously
2974 * acknowledged via a Gap Ack Block (e.g., the data receiver
2975 * reneged on the data), then mark the corresponding DATA chunk
2976 * as available for retransmit: Mark it as missing for fast
2977 * retransmit as described in Section 7.2.4 and if no retransmit
2978 * timer is running for the destination address to which the DATA
2979 * chunk was originally transmitted, then T3-rtx is started for
2980 * that destination address.
2982 * Verification Tag: 8.5 Verification Tag [Normal verification]
2985 * (endpoint, asoc, chunk)
2988 * (asoc, reply_msg, msg_up, timers, counters)
2990 * The return value is the disposition of the chunk.
2992 sctp_disposition_t sctp_sf_eat_sack_6_2(const struct sctp_endpoint *ep,
2993 const struct sctp_association *asoc,
2994 const sctp_subtype_t type,
2996 sctp_cmd_seq_t *commands)
2998 struct sctp_chunk *chunk = arg;
2999 sctp_sackhdr_t *sackh;
3002 if (!sctp_vtag_verify(chunk, asoc))
3003 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3005 /* Make sure that the SACK chunk has a valid length. */
3006 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_sack_chunk_t)))
3007 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3010 /* Pull the SACK chunk from the data buffer */
3011 sackh = sctp_sm_pull_sack(chunk);
3012 /* Was this a bogus SACK? */
3014 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3015 chunk->subh.sack_hdr = sackh;
3016 ctsn = ntohl(sackh->cum_tsn_ack);
3018 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
3019 * Ack Point, then drop the SACK. Since Cumulative TSN
3020 * Ack is monotonically increasing, a SACK whose
3021 * Cumulative TSN Ack is less than the Cumulative TSN Ack
3022 * Point indicates an out-of-order SACK.
3024 if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
3025 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn);
3026 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc->ctsn_ack_point);
3027 return SCTP_DISPOSITION_DISCARD;
3030 /* If Cumulative TSN Ack beyond the max tsn currently
3031 * send, terminating the association and respond to the
3032 * sender with an ABORT.
3034 if (!TSN_lt(ctsn, asoc->next_tsn))
3035 return sctp_sf_violation_ctsn(ep, asoc, type, arg, commands);
3037 /* Return this SACK for further processing. */
3038 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_SACKH(sackh));
3040 /* Note: We do the rest of the work on the PROCESS_SACK
3043 return SCTP_DISPOSITION_CONSUME;
3047 * Generate an ABORT in response to a packet.
3049 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
3051 * 8) The receiver should respond to the sender of the OOTB packet with
3052 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3053 * MUST fill in the Verification Tag field of the outbound packet
3054 * with the value found in the Verification Tag field of the OOTB
3055 * packet and set the T-bit in the Chunk Flags to indicate that the
3056 * Verification Tag is reflected. After sending this ABORT, the
3057 * receiver of the OOTB packet shall discard the OOTB packet and take
3058 * no further action.
3062 * The return value is the disposition of the chunk.
3064 static sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep,
3065 const struct sctp_association *asoc,
3066 const sctp_subtype_t type,
3068 sctp_cmd_seq_t *commands)
3070 struct sctp_packet *packet = NULL;
3071 struct sctp_chunk *chunk = arg;
3072 struct sctp_chunk *abort;
3074 packet = sctp_ootb_pkt_new(asoc, chunk);
3077 /* Make an ABORT. The T bit will be set if the asoc
3080 abort = sctp_make_abort(asoc, chunk, 0);
3082 sctp_ootb_pkt_free(packet);
3083 return SCTP_DISPOSITION_NOMEM;
3086 /* Reflect vtag if T-Bit is set */
3087 if (sctp_test_T_bit(abort))
3088 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
3090 /* Set the skb to the belonging sock for accounting. */
3091 abort->skb->sk = ep->base.sk;
3093 sctp_packet_append_chunk(packet, abort);
3095 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
3096 SCTP_PACKET(packet));
3098 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
3100 sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3101 return SCTP_DISPOSITION_CONSUME;
3104 return SCTP_DISPOSITION_NOMEM;
3108 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
3109 * event as ULP notification for each cause included in the chunk.
3111 * API 5.3.1.3 - SCTP_REMOTE_ERROR
3113 * The return value is the disposition of the chunk.
3115 sctp_disposition_t sctp_sf_operr_notify(const struct sctp_endpoint *ep,
3116 const struct sctp_association *asoc,
3117 const sctp_subtype_t type,
3119 sctp_cmd_seq_t *commands)
3121 struct sctp_chunk *chunk = arg;
3122 struct sctp_ulpevent *ev;
3124 if (!sctp_vtag_verify(chunk, asoc))
3125 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3127 /* Make sure that the ERROR chunk has a valid length. */
3128 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t)))
3129 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3132 while (chunk->chunk_end > chunk->skb->data) {
3133 ev = sctp_ulpevent_make_remote_error(asoc, chunk, 0,
3138 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
3140 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR,
3143 return SCTP_DISPOSITION_CONSUME;
3146 return SCTP_DISPOSITION_NOMEM;
3150 * Process an inbound SHUTDOWN ACK.
3153 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3154 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3155 * peer, and remove all record of the association.
3157 * The return value is the disposition.
3159 sctp_disposition_t sctp_sf_do_9_2_final(const struct sctp_endpoint *ep,
3160 const struct sctp_association *asoc,
3161 const sctp_subtype_t type,
3163 sctp_cmd_seq_t *commands)
3165 struct sctp_chunk *chunk = arg;
3166 struct sctp_chunk *reply;
3167 struct sctp_ulpevent *ev;
3169 if (!sctp_vtag_verify(chunk, asoc))
3170 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3172 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3173 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3174 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3176 /* 10.2 H) SHUTDOWN COMPLETE notification
3178 * When SCTP completes the shutdown procedures (section 9.2) this
3179 * notification is passed to the upper layer.
3181 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
3182 0, 0, 0, NULL, GFP_ATOMIC);
3186 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3187 reply = sctp_make_shutdown_complete(asoc, chunk);
3191 /* Do all the commands now (after allocation), so that we
3192 * have consistent state if memory allocation failes
3194 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
3196 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3197 * stop the T2-shutdown timer,
3199 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3200 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3202 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3203 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3205 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3206 SCTP_STATE(SCTP_STATE_CLOSED));
3207 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
3208 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3209 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
3211 /* ...and remove all record of the association. */
3212 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
3213 return SCTP_DISPOSITION_DELETE_TCB;
3216 sctp_ulpevent_free(ev);
3218 return SCTP_DISPOSITION_NOMEM;
3222 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3224 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3225 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3226 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3227 * packet must fill in the Verification Tag field of the outbound
3228 * packet with the Verification Tag received in the SHUTDOWN ACK and
3229 * set the T-bit in the Chunk Flags to indicate that the Verification
3232 * 8) The receiver should respond to the sender of the OOTB packet with
3233 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3234 * MUST fill in the Verification Tag field of the outbound packet
3235 * with the value found in the Verification Tag field of the OOTB
3236 * packet and set the T-bit in the Chunk Flags to indicate that the
3237 * Verification Tag is reflected. After sending this ABORT, the
3238 * receiver of the OOTB packet shall discard the OOTB packet and take
3239 * no further action.
3241 sctp_disposition_t sctp_sf_ootb(const struct sctp_endpoint *ep,
3242 const struct sctp_association *asoc,
3243 const sctp_subtype_t type,
3245 sctp_cmd_seq_t *commands)
3247 struct sctp_chunk *chunk = arg;
3248 struct sk_buff *skb = chunk->skb;
3249 sctp_chunkhdr_t *ch;
3251 int ootb_shut_ack = 0;
3253 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES);
3255 ch = (sctp_chunkhdr_t *) chunk->chunk_hdr;
3257 /* Report violation if the chunk is less then minimal */
3258 if (ntohs(ch->length) < sizeof(sctp_chunkhdr_t))
3259 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3262 /* Now that we know we at least have a chunk header,
3263 * do things that are type appropriate.
3265 if (SCTP_CID_SHUTDOWN_ACK == ch->type)
3268 /* RFC 2960, Section 3.3.7
3269 * Moreover, under any circumstances, an endpoint that
3270 * receives an ABORT MUST NOT respond to that ABORT by
3271 * sending an ABORT of its own.
3273 if (SCTP_CID_ABORT == ch->type)
3274 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3276 /* Report violation if chunk len overflows */
3277 ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length));
3278 if (ch_end > skb_tail_pointer(skb))
3279 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3282 ch = (sctp_chunkhdr_t *) ch_end;
3283 } while (ch_end < skb_tail_pointer(skb));
3286 return sctp_sf_shut_8_4_5(ep, asoc, type, arg, commands);
3288 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
3292 * Handle an "Out of the blue" SHUTDOWN ACK.
3294 * Section: 8.4 5, sctpimpguide 2.41.
3296 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3297 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3298 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3299 * packet must fill in the Verification Tag field of the outbound
3300 * packet with the Verification Tag received in the SHUTDOWN ACK and
3301 * set the T-bit in the Chunk Flags to indicate that the Verification
3305 * (endpoint, asoc, type, arg, commands)
3308 * (sctp_disposition_t)
3310 * The return value is the disposition of the chunk.
3312 static sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep,
3313 const struct sctp_association *asoc,
3314 const sctp_subtype_t type,
3316 sctp_cmd_seq_t *commands)
3318 struct sctp_packet *packet = NULL;
3319 struct sctp_chunk *chunk = arg;
3320 struct sctp_chunk *shut;
3322 packet = sctp_ootb_pkt_new(asoc, chunk);
3325 /* Make an SHUTDOWN_COMPLETE.
3326 * The T bit will be set if the asoc is NULL.
3328 shut = sctp_make_shutdown_complete(asoc, chunk);
3330 sctp_ootb_pkt_free(packet);
3331 return SCTP_DISPOSITION_NOMEM;
3334 /* Reflect vtag if T-Bit is set */
3335 if (sctp_test_T_bit(shut))
3336 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
3338 /* Set the skb to the belonging sock for accounting. */
3339 shut->skb->sk = ep->base.sk;
3341 sctp_packet_append_chunk(packet, shut);
3343 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
3344 SCTP_PACKET(packet));
3346 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
3348 /* If the chunk length is invalid, we don't want to process
3349 * the reset of the packet.
3351 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3352 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3354 /* We need to discard the rest of the packet to prevent
3355 * potential bomming attacks from additional bundled chunks.
3356 * This is documented in SCTP Threats ID.
3358 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3361 return SCTP_DISPOSITION_NOMEM;
3365 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3367 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3368 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3369 * procedures in section 8.4 SHOULD be followed, in other words it
3370 * should be treated as an Out Of The Blue packet.
3371 * [This means that we do NOT check the Verification Tag on these
3375 sctp_disposition_t sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint *ep,
3376 const struct sctp_association *asoc,
3377 const sctp_subtype_t type,
3379 sctp_cmd_seq_t *commands)
3381 struct sctp_chunk *chunk = arg;
3383 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3384 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3385 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3388 /* Although we do have an association in this case, it corresponds
3389 * to a restarted association. So the packet is treated as an OOTB
3390 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3391 * called with a NULL association.
3393 return sctp_sf_shut_8_4_5(ep, NULL, type, arg, commands);
3396 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3397 sctp_disposition_t sctp_sf_do_asconf(const struct sctp_endpoint *ep,
3398 const struct sctp_association *asoc,
3399 const sctp_subtype_t type, void *arg,
3400 sctp_cmd_seq_t *commands)
3402 struct sctp_chunk *chunk = arg;
3403 struct sctp_chunk *asconf_ack = NULL;
3404 struct sctp_paramhdr *err_param = NULL;
3405 sctp_addiphdr_t *hdr;
3406 union sctp_addr_param *addr_param;
3410 if (!sctp_vtag_verify(chunk, asoc)) {
3411 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3413 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3416 /* ADD-IP: Section 4.1.1
3417 * This chunk MUST be sent in an authenticated way by using
3418 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3419 * is received unauthenticated it MUST be silently discarded as
3420 * described in [I-D.ietf-tsvwg-sctp-auth].
3422 if (!sctp_addip_noauth && !chunk->auth)
3423 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
3425 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3426 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_addip_chunk_t)))
3427 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3430 hdr = (sctp_addiphdr_t *)chunk->skb->data;
3431 serial = ntohl(hdr->serial);
3433 addr_param = (union sctp_addr_param *)hdr->params;
3434 length = ntohs(addr_param->p.length);
3435 if (length < sizeof(sctp_paramhdr_t))
3436 return sctp_sf_violation_paramlen(ep, asoc, type,
3437 (void *)addr_param, commands);
3439 /* Verify the ASCONF chunk before processing it. */
3440 if (!sctp_verify_asconf(asoc,
3441 (sctp_paramhdr_t *)((void *)addr_param + length),
3442 (void *)chunk->chunk_end,
3444 return sctp_sf_violation_paramlen(ep, asoc, type,
3445 (void *)&err_param, commands);
3447 /* ADDIP 5.2 E1) Compare the value of the serial number to the value
3448 * the endpoint stored in a new association variable
3449 * 'Peer-Serial-Number'.
3451 if (serial == asoc->peer.addip_serial + 1) {
3452 /* If this is the first instance of ASCONF in the packet,
3453 * we can clean our old ASCONF-ACKs.
3455 if (!chunk->has_asconf)
3456 sctp_assoc_clean_asconf_ack_cache(asoc);
3458 /* ADDIP 5.2 E4) When the Sequence Number matches the next one
3459 * expected, process the ASCONF as described below and after
3460 * processing the ASCONF Chunk, append an ASCONF-ACK Chunk to
3461 * the response packet and cache a copy of it (in the event it
3462 * later needs to be retransmitted).
3464 * Essentially, do V1-V5.
3466 asconf_ack = sctp_process_asconf((struct sctp_association *)
3469 return SCTP_DISPOSITION_NOMEM;
3470 } else if (serial < asoc->peer.addip_serial + 1) {
3472 * If the value found in the Sequence Number is less than the
3473 * ('Peer- Sequence-Number' + 1), simply skip to the next
3474 * ASCONF, and include in the outbound response packet
3475 * any previously cached ASCONF-ACK response that was
3476 * sent and saved that matches the Sequence Number of the
3477 * ASCONF. Note: It is possible that no cached ASCONF-ACK
3478 * Chunk exists. This will occur when an older ASCONF
3479 * arrives out of order. In such a case, the receiver
3480 * should skip the ASCONF Chunk and not include ASCONF-ACK
3481 * Chunk for that chunk.
3483 asconf_ack = sctp_assoc_lookup_asconf_ack(asoc, hdr->serial);
3485 return SCTP_DISPOSITION_DISCARD;
3487 /* ADDIP 5.2 E5) Otherwise, the ASCONF Chunk is discarded since
3488 * it must be either a stale packet or from an attacker.
3490 return SCTP_DISPOSITION_DISCARD;
3493 /* ADDIP 5.2 E6) The destination address of the SCTP packet
3494 * containing the ASCONF-ACK Chunks MUST be the source address of
3495 * the SCTP packet that held the ASCONF Chunks.
3497 * To do this properly, we'll set the destination address of the chunk
3498 * and at the transmit time, will try look up the transport to use.
3499 * Since ASCONFs may be bundled, the correct transport may not be
3500 * created untill we process the entire packet, thus this workaround.
3502 asconf_ack->dest = chunk->source;
3503 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack));
3505 return SCTP_DISPOSITION_CONSUME;
3509 * ADDIP Section 4.3 General rules for address manipulation
3510 * When building TLV parameters for the ASCONF Chunk that will add or
3511 * delete IP addresses the D0 to D13 rules should be applied:
3513 sctp_disposition_t sctp_sf_do_asconf_ack(const struct sctp_endpoint *ep,
3514 const struct sctp_association *asoc,
3515 const sctp_subtype_t type, void *arg,
3516 sctp_cmd_seq_t *commands)
3518 struct sctp_chunk *asconf_ack = arg;
3519 struct sctp_chunk *last_asconf = asoc->addip_last_asconf;
3520 struct sctp_chunk *abort;
3521 struct sctp_paramhdr *err_param = NULL;
3522 sctp_addiphdr_t *addip_hdr;
3523 __u32 sent_serial, rcvd_serial;
3525 if (!sctp_vtag_verify(asconf_ack, asoc)) {
3526 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3528 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3531 /* ADD-IP, Section 4.1.2:
3532 * This chunk MUST be sent in an authenticated way by using
3533 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3534 * is received unauthenticated it MUST be silently discarded as
3535 * described in [I-D.ietf-tsvwg-sctp-auth].
3537 if (!sctp_addip_noauth && !asconf_ack->auth)
3538 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
3540 /* Make sure that the ADDIP chunk has a valid length. */
3541 if (!sctp_chunk_length_valid(asconf_ack, sizeof(sctp_addip_chunk_t)))
3542 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3545 addip_hdr = (sctp_addiphdr_t *)asconf_ack->skb->data;
3546 rcvd_serial = ntohl(addip_hdr->serial);
3548 /* Verify the ASCONF-ACK chunk before processing it. */
3549 if (!sctp_verify_asconf(asoc,
3550 (sctp_paramhdr_t *)addip_hdr->params,
3551 (void *)asconf_ack->chunk_end,
3553 return sctp_sf_violation_paramlen(ep, asoc, type,
3554 (void *)&err_param, commands);
3557 addip_hdr = (sctp_addiphdr_t *)last_asconf->subh.addip_hdr;
3558 sent_serial = ntohl(addip_hdr->serial);
3560 sent_serial = asoc->addip_serial - 1;
3563 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3564 * equal to the next serial number to be used but no ASCONF chunk is
3565 * outstanding the endpoint MUST ABORT the association. Note that a
3566 * sequence number is greater than if it is no more than 2^^31-1
3567 * larger than the current sequence number (using serial arithmetic).
3569 if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) &&
3570 !(asoc->addip_last_asconf)) {
3571 abort = sctp_make_abort(asoc, asconf_ack,
3572 sizeof(sctp_errhdr_t));
3574 sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, 0);
3575 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3578 /* We are going to ABORT, so we might as well stop
3579 * processing the rest of the chunks in the packet.
3581 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3582 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3583 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3584 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3585 SCTP_ERROR(ECONNABORTED));
3586 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3587 SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
3588 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3589 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3590 return SCTP_DISPOSITION_ABORT;
3593 if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) {
3594 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3595 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3597 if (!sctp_process_asconf_ack((struct sctp_association *)asoc,
3599 return SCTP_DISPOSITION_CONSUME;
3601 abort = sctp_make_abort(asoc, asconf_ack,
3602 sizeof(sctp_errhdr_t));
3604 sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, 0);
3605 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3608 /* We are going to ABORT, so we might as well stop
3609 * processing the rest of the chunks in the packet.
3611 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3612 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3613 SCTP_ERROR(ECONNABORTED));
3614 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3615 SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
3616 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3617 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3618 return SCTP_DISPOSITION_ABORT;
3621 return SCTP_DISPOSITION_DISCARD;
3625 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3627 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3628 * its cumulative TSN point to the value carried in the FORWARD TSN
3629 * chunk, and then MUST further advance its cumulative TSN point locally
3631 * After the above processing, the data receiver MUST stop reporting any
3632 * missing TSNs earlier than or equal to the new cumulative TSN point.
3634 * Verification Tag: 8.5 Verification Tag [Normal verification]
3636 * The return value is the disposition of the chunk.
3638 sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep,
3639 const struct sctp_association *asoc,
3640 const sctp_subtype_t type,
3642 sctp_cmd_seq_t *commands)
3644 struct sctp_chunk *chunk = arg;
3645 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3649 if (!sctp_vtag_verify(chunk, asoc)) {
3650 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3652 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3655 /* Make sure that the FORWARD_TSN chunk has valid length. */
3656 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk)))
3657 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3660 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3661 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3662 len = ntohs(chunk->chunk_hdr->length);
3663 len -= sizeof(struct sctp_chunkhdr);
3664 skb_pull(chunk->skb, len);
3666 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3667 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __func__, tsn);
3669 /* The TSN is too high--silently discard the chunk and count on it
3670 * getting retransmitted later.
3672 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3673 goto discard_noforce;
3675 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3676 if (len > sizeof(struct sctp_fwdtsn_hdr))
3677 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3680 /* Count this as receiving DATA. */
3681 if (asoc->autoclose) {
3682 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3683 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
3686 /* FIXME: For now send a SACK, but DATA processing may
3689 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
3691 return SCTP_DISPOSITION_CONSUME;
3694 return SCTP_DISPOSITION_DISCARD;
3697 sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(
3698 const struct sctp_endpoint *ep,
3699 const struct sctp_association *asoc,
3700 const sctp_subtype_t type,
3702 sctp_cmd_seq_t *commands)
3704 struct sctp_chunk *chunk = arg;
3705 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3709 if (!sctp_vtag_verify(chunk, asoc)) {
3710 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3712 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3715 /* Make sure that the FORWARD_TSN chunk has a valid length. */
3716 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk)))
3717 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3720 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3721 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3722 len = ntohs(chunk->chunk_hdr->length);
3723 len -= sizeof(struct sctp_chunkhdr);
3724 skb_pull(chunk->skb, len);
3726 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3727 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __func__, tsn);
3729 /* The TSN is too high--silently discard the chunk and count on it
3730 * getting retransmitted later.
3732 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3735 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3736 if (len > sizeof(struct sctp_fwdtsn_hdr))
3737 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3740 /* Go a head and force a SACK, since we are shutting down. */
3742 /* Implementor's Guide.
3744 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3745 * respond to each received packet containing one or more DATA chunk(s)
3746 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3748 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
3749 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
3750 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3751 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3753 return SCTP_DISPOSITION_CONSUME;
3757 * SCTP-AUTH Section 6.3 Receving authenticated chukns
3759 * The receiver MUST use the HMAC algorithm indicated in the HMAC
3760 * Identifier field. If this algorithm was not specified by the
3761 * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk
3762 * during association setup, the AUTH chunk and all chunks after it MUST
3763 * be discarded and an ERROR chunk SHOULD be sent with the error cause
3764 * defined in Section 4.1.
3766 * If an endpoint with no shared key receives a Shared Key Identifier
3767 * other than 0, it MUST silently discard all authenticated chunks. If
3768 * the endpoint has at least one endpoint pair shared key for the peer,
3769 * it MUST use the key specified by the Shared Key Identifier if a
3770 * key has been configured for that Shared Key Identifier. If no
3771 * endpoint pair shared key has been configured for that Shared Key
3772 * Identifier, all authenticated chunks MUST be silently discarded.
3774 * Verification Tag: 8.5 Verification Tag [Normal verification]
3776 * The return value is the disposition of the chunk.
3778 static sctp_ierror_t sctp_sf_authenticate(const struct sctp_endpoint *ep,
3779 const struct sctp_association *asoc,
3780 const sctp_subtype_t type,
3781 struct sctp_chunk *chunk)
3783 struct sctp_authhdr *auth_hdr;
3784 struct sctp_hmac *hmac;
3785 unsigned int sig_len;
3790 /* Pull in the auth header, so we can do some more verification */
3791 auth_hdr = (struct sctp_authhdr *)chunk->skb->data;
3792 chunk->subh.auth_hdr = auth_hdr;
3793 skb_pull(chunk->skb, sizeof(struct sctp_authhdr));
3795 /* Make sure that we suport the HMAC algorithm from the auth
3798 if (!sctp_auth_asoc_verify_hmac_id(asoc, auth_hdr->hmac_id))
3799 return SCTP_IERROR_AUTH_BAD_HMAC;
3801 /* Make sure that the provided shared key identifier has been
3804 key_id = ntohs(auth_hdr->shkey_id);
3805 if (key_id != asoc->active_key_id && !sctp_auth_get_shkey(asoc, key_id))
3806 return SCTP_IERROR_AUTH_BAD_KEYID;
3809 /* Make sure that the length of the signature matches what
3812 sig_len = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_auth_chunk_t);
3813 hmac = sctp_auth_get_hmac(ntohs(auth_hdr->hmac_id));
3814 if (sig_len != hmac->hmac_len)
3815 return SCTP_IERROR_PROTO_VIOLATION;
3817 /* Now that we've done validation checks, we can compute and
3818 * verify the hmac. The steps involved are:
3819 * 1. Save the digest from the chunk.
3820 * 2. Zero out the digest in the chunk.
3821 * 3. Compute the new digest
3822 * 4. Compare saved and new digests.
3824 digest = auth_hdr->hmac;
3825 skb_pull(chunk->skb, sig_len);
3827 save_digest = kmemdup(digest, sig_len, GFP_ATOMIC);
3831 memset(digest, 0, sig_len);
3833 sctp_auth_calculate_hmac(asoc, chunk->skb,
3834 (struct sctp_auth_chunk *)chunk->chunk_hdr,
3837 /* Discard the packet if the digests do not match */
3838 if (memcmp(save_digest, digest, sig_len)) {
3840 return SCTP_IERROR_BAD_SIG;
3846 return SCTP_IERROR_NO_ERROR;
3848 return SCTP_IERROR_NOMEM;
3851 sctp_disposition_t sctp_sf_eat_auth(const struct sctp_endpoint *ep,
3852 const struct sctp_association *asoc,
3853 const sctp_subtype_t type,
3855 sctp_cmd_seq_t *commands)
3857 struct sctp_authhdr *auth_hdr;
3858 struct sctp_chunk *chunk = arg;
3859 struct sctp_chunk *err_chunk;
3860 sctp_ierror_t error;
3862 /* Make sure that the peer has AUTH capable */
3863 if (!asoc->peer.auth_capable)
3864 return sctp_sf_unk_chunk(ep, asoc, type, arg, commands);
3866 if (!sctp_vtag_verify(chunk, asoc)) {
3867 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3869 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3872 /* Make sure that the AUTH chunk has valid length. */
3873 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_auth_chunk)))
3874 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3877 auth_hdr = (struct sctp_authhdr *)chunk->skb->data;
3878 error = sctp_sf_authenticate(ep, asoc, type, chunk);
3880 case SCTP_IERROR_AUTH_BAD_HMAC:
3881 /* Generate the ERROR chunk and discard the rest
3884 err_chunk = sctp_make_op_error(asoc, chunk,
3885 SCTP_ERROR_UNSUP_HMAC,
3889 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3890 SCTP_CHUNK(err_chunk));
3893 case SCTP_IERROR_AUTH_BAD_KEYID:
3894 case SCTP_IERROR_BAD_SIG:
3895 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3897 case SCTP_IERROR_PROTO_VIOLATION:
3898 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3901 case SCTP_IERROR_NOMEM:
3902 return SCTP_DISPOSITION_NOMEM;
3907 if (asoc->active_key_id != ntohs(auth_hdr->shkey_id)) {
3908 struct sctp_ulpevent *ev;
3910 ev = sctp_ulpevent_make_authkey(asoc, ntohs(auth_hdr->shkey_id),
3911 SCTP_AUTH_NEWKEY, GFP_ATOMIC);
3916 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
3920 return SCTP_DISPOSITION_CONSUME;
3924 * Process an unknown chunk.
3926 * Section: 3.2. Also, 2.1 in the implementor's guide.
3928 * Chunk Types are encoded such that the highest-order two bits specify
3929 * the action that must be taken if the processing endpoint does not
3930 * recognize the Chunk Type.
3932 * 00 - Stop processing this SCTP packet and discard it, do not process
3933 * any further chunks within it.
3935 * 01 - Stop processing this SCTP packet and discard it, do not process
3936 * any further chunks within it, and report the unrecognized
3937 * chunk in an 'Unrecognized Chunk Type'.
3939 * 10 - Skip this chunk and continue processing.
3941 * 11 - Skip this chunk and continue processing, but report in an ERROR
3942 * Chunk using the 'Unrecognized Chunk Type' cause of error.
3944 * The return value is the disposition of the chunk.
3946 sctp_disposition_t sctp_sf_unk_chunk(const struct sctp_endpoint *ep,
3947 const struct sctp_association *asoc,
3948 const sctp_subtype_t type,
3950 sctp_cmd_seq_t *commands)
3952 struct sctp_chunk *unk_chunk = arg;
3953 struct sctp_chunk *err_chunk;
3954 sctp_chunkhdr_t *hdr;
3956 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type.chunk);
3958 if (!sctp_vtag_verify(unk_chunk, asoc))
3959 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3961 /* Make sure that the chunk has a valid length.
3962 * Since we don't know the chunk type, we use a general
3963 * chunkhdr structure to make a comparison.
3965 if (!sctp_chunk_length_valid(unk_chunk, sizeof(sctp_chunkhdr_t)))
3966 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3969 switch (type.chunk & SCTP_CID_ACTION_MASK) {
3970 case SCTP_CID_ACTION_DISCARD:
3971 /* Discard the packet. */
3972 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3974 case SCTP_CID_ACTION_DISCARD_ERR:
3975 /* Discard the packet. */
3976 sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3978 /* Generate an ERROR chunk as response. */
3979 hdr = unk_chunk->chunk_hdr;
3980 err_chunk = sctp_make_op_error(asoc, unk_chunk,
3981 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
3982 WORD_ROUND(ntohs(hdr->length)));
3984 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3985 SCTP_CHUNK(err_chunk));
3987 return SCTP_DISPOSITION_CONSUME;
3989 case SCTP_CID_ACTION_SKIP:
3990 /* Skip the chunk. */
3991 return SCTP_DISPOSITION_DISCARD;
3993 case SCTP_CID_ACTION_SKIP_ERR:
3994 /* Generate an ERROR chunk as response. */
3995 hdr = unk_chunk->chunk_hdr;
3996 err_chunk = sctp_make_op_error(asoc, unk_chunk,
3997 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
3998 WORD_ROUND(ntohs(hdr->length)));
4000 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4001 SCTP_CHUNK(err_chunk));
4003 /* Skip the chunk. */
4004 return SCTP_DISPOSITION_CONSUME;
4010 return SCTP_DISPOSITION_DISCARD;
4014 * Discard the chunk.
4016 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
4017 * [Too numerous to mention...]
4018 * Verification Tag: No verification needed.
4020 * (endpoint, asoc, chunk)
4023 * (asoc, reply_msg, msg_up, timers, counters)
4025 * The return value is the disposition of the chunk.
4027 sctp_disposition_t sctp_sf_discard_chunk(const struct sctp_endpoint *ep,
4028 const struct sctp_association *asoc,
4029 const sctp_subtype_t type,
4031 sctp_cmd_seq_t *commands)
4033 struct sctp_chunk *chunk = arg;
4035 /* Make sure that the chunk has a valid length.
4036 * Since we don't know the chunk type, we use a general
4037 * chunkhdr structure to make a comparison.
4039 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
4040 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
4043 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type.chunk);
4044 return SCTP_DISPOSITION_DISCARD;
4048 * Discard the whole packet.
4052 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
4053 * silently discard the OOTB packet and take no further action.
4055 * Verification Tag: No verification necessary
4058 * (endpoint, asoc, chunk)
4061 * (asoc, reply_msg, msg_up, timers, counters)
4063 * The return value is the disposition of the chunk.
4065 sctp_disposition_t sctp_sf_pdiscard(const struct sctp_endpoint *ep,
4066 const struct sctp_association *asoc,
4067 const sctp_subtype_t type,
4069 sctp_cmd_seq_t *commands)
4071 SCTP_INC_STATS(SCTP_MIB_IN_PKT_DISCARDS);
4072 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
4074 return SCTP_DISPOSITION_CONSUME;
4079 * The other end is violating protocol.
4081 * Section: Not specified
4082 * Verification Tag: Not specified
4084 * (endpoint, asoc, chunk)
4087 * (asoc, reply_msg, msg_up, timers, counters)
4089 * We simply tag the chunk as a violation. The state machine will log
4090 * the violation and continue.
4092 sctp_disposition_t sctp_sf_violation(const struct sctp_endpoint *ep,
4093 const struct sctp_association *asoc,
4094 const sctp_subtype_t type,
4096 sctp_cmd_seq_t *commands)
4098 struct sctp_chunk *chunk = arg;
4100 /* Make sure that the chunk has a valid length. */
4101 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
4102 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
4105 return SCTP_DISPOSITION_VIOLATION;
4109 * Common function to handle a protocol violation.
4111 static sctp_disposition_t sctp_sf_abort_violation(
4112 const struct sctp_endpoint *ep,
4113 const struct sctp_association *asoc,
4115 sctp_cmd_seq_t *commands,
4116 const __u8 *payload,
4117 const size_t paylen)
4119 struct sctp_packet *packet = NULL;
4120 struct sctp_chunk *chunk = arg;
4121 struct sctp_chunk *abort = NULL;
4123 /* SCTP-AUTH, Section 6.3:
4124 * It should be noted that if the receiver wants to tear
4125 * down an association in an authenticated way only, the
4126 * handling of malformed packets should not result in
4127 * tearing down the association.
4129 * This means that if we only want to abort associations
4130 * in an authenticated way (i.e AUTH+ABORT), then we
4131 * can't destroy this association just becuase the packet
4134 if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
4137 /* Make the abort chunk. */
4138 abort = sctp_make_abort_violation(asoc, chunk, payload, paylen);
4143 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4144 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
4146 if (asoc->state <= SCTP_STATE_COOKIE_ECHOED) {
4147 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4148 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4149 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4150 SCTP_ERROR(ECONNREFUSED));
4151 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4152 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
4154 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4155 SCTP_ERROR(ECONNABORTED));
4156 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4157 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
4158 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4161 packet = sctp_ootb_pkt_new(asoc, chunk);
4166 if (sctp_test_T_bit(abort))
4167 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
4169 abort->skb->sk = ep->base.sk;
4171 sctp_packet_append_chunk(packet, abort);
4173 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
4174 SCTP_PACKET(packet));
4176 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
4180 sctp_sf_pdiscard(ep, asoc, SCTP_ST_CHUNK(0), arg, commands);
4182 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4184 return SCTP_DISPOSITION_ABORT;
4187 sctp_chunk_free(abort);
4189 return SCTP_DISPOSITION_NOMEM;
4193 * Handle a protocol violation when the chunk length is invalid.
4194 * "Invalid" length is identified as smaller then the minimal length a
4195 * given chunk can be. For example, a SACK chunk has invalid length
4196 * if it's length is set to be smaller then the size of sctp_sack_chunk_t.
4198 * We inform the other end by sending an ABORT with a Protocol Violation
4201 * Section: Not specified
4202 * Verification Tag: Nothing to do
4204 * (endpoint, asoc, chunk)
4207 * (reply_msg, msg_up, counters)
4209 * Generate an ABORT chunk and terminate the association.
4211 static sctp_disposition_t sctp_sf_violation_chunklen(
4212 const struct sctp_endpoint *ep,
4213 const struct sctp_association *asoc,
4214 const sctp_subtype_t type,
4216 sctp_cmd_seq_t *commands)
4218 static const char err_str[]="The following chunk had invalid length:";
4220 return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str,
4225 * Handle a protocol violation when the parameter length is invalid.
4226 * "Invalid" length is identified as smaller then the minimal length a
4227 * given parameter can be.
4229 static sctp_disposition_t sctp_sf_violation_paramlen(
4230 const struct sctp_endpoint *ep,
4231 const struct sctp_association *asoc,
4232 const sctp_subtype_t type,
4234 sctp_cmd_seq_t *commands) {
4235 static const char err_str[] = "The following parameter had invalid length:";
4237 return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str,
4241 /* Handle a protocol violation when the peer trying to advance the
4242 * cumulative tsn ack to a point beyond the max tsn currently sent.
4244 * We inform the other end by sending an ABORT with a Protocol Violation
4247 static sctp_disposition_t sctp_sf_violation_ctsn(
4248 const struct sctp_endpoint *ep,
4249 const struct sctp_association *asoc,
4250 const sctp_subtype_t type,
4252 sctp_cmd_seq_t *commands)
4254 static const char err_str[]="The cumulative tsn ack beyond the max tsn currently sent:";
4256 return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str,
4260 /* Handle protocol violation of an invalid chunk bundling. For example,
4261 * when we have an association and we recieve bundled INIT-ACK, or
4262 * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle"
4263 * statement from the specs. Additinally, there might be an attacker
4264 * on the path and we may not want to continue this communication.
4266 static sctp_disposition_t sctp_sf_violation_chunk(
4267 const struct sctp_endpoint *ep,
4268 const struct sctp_association *asoc,
4269 const sctp_subtype_t type,
4271 sctp_cmd_seq_t *commands)
4273 static const char err_str[]="The following chunk violates protocol:";
4276 return sctp_sf_violation(ep, asoc, type, arg, commands);
4278 return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str,
4281 /***************************************************************************
4282 * These are the state functions for handling primitive (Section 10) events.
4283 ***************************************************************************/
4285 * sctp_sf_do_prm_asoc
4287 * Section: 10.1 ULP-to-SCTP
4290 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
4291 * outbound stream count)
4292 * -> association id [,destination transport addr list] [,outbound stream
4295 * This primitive allows the upper layer to initiate an association to a
4296 * specific peer endpoint.
4298 * The peer endpoint shall be specified by one of the transport addresses
4299 * which defines the endpoint (see Section 1.4). If the local SCTP
4300 * instance has not been initialized, the ASSOCIATE is considered an
4302 * [This is not relevant for the kernel implementation since we do all
4303 * initialization at boot time. It we hadn't initialized we wouldn't
4304 * get anywhere near this code.]
4306 * An association id, which is a local handle to the SCTP association,
4307 * will be returned on successful establishment of the association. If
4308 * SCTP is not able to open an SCTP association with the peer endpoint,
4309 * an error is returned.
4310 * [In the kernel implementation, the struct sctp_association needs to
4311 * be created BEFORE causing this primitive to run.]
4313 * Other association parameters may be returned, including the
4314 * complete destination transport addresses of the peer as well as the
4315 * outbound stream count of the local endpoint. One of the transport
4316 * address from the returned destination addresses will be selected by
4317 * the local endpoint as default primary path for sending SCTP packets
4318 * to this peer. The returned "destination transport addr list" can
4319 * be used by the ULP to change the default primary path or to force
4320 * sending a packet to a specific transport address. [All of this
4321 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
4324 * Mandatory attributes:
4326 * o local SCTP instance name - obtained from the INITIALIZE operation.
4327 * [This is the argument asoc.]
4328 * o destination transport addr - specified as one of the transport
4329 * addresses of the peer endpoint with which the association is to be
4331 * [This is asoc->peer.active_path.]
4332 * o outbound stream count - the number of outbound streams the ULP
4333 * would like to open towards this peer endpoint.
4334 * [BUG: This is not currently implemented.]
4335 * Optional attributes:
4339 * The return value is a disposition.
4341 sctp_disposition_t sctp_sf_do_prm_asoc(const struct sctp_endpoint *ep,
4342 const struct sctp_association *asoc,
4343 const sctp_subtype_t type,
4345 sctp_cmd_seq_t *commands)
4347 struct sctp_chunk *repl;
4349 /* The comment below says that we enter COOKIE-WAIT AFTER
4350 * sending the INIT, but that doesn't actually work in our
4353 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4354 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
4356 /* RFC 2960 5.1 Normal Establishment of an Association
4358 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
4359 * must provide its Verification Tag (Tag_A) in the Initiate
4360 * Tag field. Tag_A SHOULD be a random number in the range of
4361 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
4364 repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0);
4368 /* Cast away the const modifier, as we want to just
4369 * rerun it through as a sideffect.
4371 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC,
4372 SCTP_ASOC((struct sctp_association *) asoc));
4374 /* Choose transport for INIT. */
4375 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
4378 /* After sending the INIT, "A" starts the T1-init timer and
4379 * enters the COOKIE-WAIT state.
4381 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4382 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4383 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
4384 return SCTP_DISPOSITION_CONSUME;
4387 return SCTP_DISPOSITION_NOMEM;
4391 * Process the SEND primitive.
4393 * Section: 10.1 ULP-to-SCTP
4396 * Format: SEND(association id, buffer address, byte count [,context]
4397 * [,stream id] [,life time] [,destination transport address]
4398 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
4401 * This is the main method to send user data via SCTP.
4403 * Mandatory attributes:
4405 * o association id - local handle to the SCTP association
4407 * o buffer address - the location where the user message to be
4408 * transmitted is stored;
4410 * o byte count - The size of the user data in number of bytes;
4412 * Optional attributes:
4414 * o context - an optional 32 bit integer that will be carried in the
4415 * sending failure notification to the ULP if the transportation of
4416 * this User Message fails.
4418 * o stream id - to indicate which stream to send the data on. If not
4419 * specified, stream 0 will be used.
4421 * o life time - specifies the life time of the user data. The user data
4422 * will not be sent by SCTP after the life time expires. This
4423 * parameter can be used to avoid efforts to transmit stale
4424 * user messages. SCTP notifies the ULP if the data cannot be
4425 * initiated to transport (i.e. sent to the destination via SCTP's
4426 * send primitive) within the life time variable. However, the
4427 * user data will be transmitted if SCTP has attempted to transmit a
4428 * chunk before the life time expired.
4430 * o destination transport address - specified as one of the destination
4431 * transport addresses of the peer endpoint to which this packet
4432 * should be sent. Whenever possible, SCTP should use this destination
4433 * transport address for sending the packets, instead of the current
4436 * o unorder flag - this flag, if present, indicates that the user
4437 * would like the data delivered in an unordered fashion to the peer
4438 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
4441 * o no-bundle flag - instructs SCTP not to bundle this user data with
4442 * other outbound DATA chunks. SCTP MAY still bundle even when
4443 * this flag is present, when faced with network congestion.
4445 * o payload protocol-id - A 32 bit unsigned integer that is to be
4446 * passed to the peer indicating the type of payload protocol data
4447 * being transmitted. This value is passed as opaque data by SCTP.
4449 * The return value is the disposition.
4451 sctp_disposition_t sctp_sf_do_prm_send(const struct sctp_endpoint *ep,
4452 const struct sctp_association *asoc,
4453 const sctp_subtype_t type,
4455 sctp_cmd_seq_t *commands)
4457 struct sctp_chunk *chunk = arg;
4459 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
4460 return SCTP_DISPOSITION_CONSUME;
4464 * Process the SHUTDOWN primitive.
4469 * Format: SHUTDOWN(association id)
4472 * Gracefully closes an association. Any locally queued user data
4473 * will be delivered to the peer. The association will be terminated only
4474 * after the peer acknowledges all the SCTP packets sent. A success code
4475 * will be returned on successful termination of the association. If
4476 * attempting to terminate the association results in a failure, an error
4477 * code shall be returned.
4479 * Mandatory attributes:
4481 * o association id - local handle to the SCTP association
4483 * Optional attributes:
4487 * The return value is the disposition.
4489 sctp_disposition_t sctp_sf_do_9_2_prm_shutdown(
4490 const struct sctp_endpoint *ep,
4491 const struct sctp_association *asoc,
4492 const sctp_subtype_t type,
4494 sctp_cmd_seq_t *commands)
4498 /* From 9.2 Shutdown of an Association
4499 * Upon receipt of the SHUTDOWN primitive from its upper
4500 * layer, the endpoint enters SHUTDOWN-PENDING state and
4501 * remains there until all outstanding data has been
4502 * acknowledged by its peer. The endpoint accepts no new data
4503 * from its upper layer, but retransmits data to the far end
4504 * if necessary to fill gaps.
4506 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4507 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
4509 /* sctpimpguide-05 Section 2.12.2
4510 * The sender of the SHUTDOWN MAY also start an overall guard timer
4511 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4513 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4514 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4516 disposition = SCTP_DISPOSITION_CONSUME;
4517 if (sctp_outq_is_empty(&asoc->outqueue)) {
4518 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
4525 * Process the ABORT primitive.
4530 * Format: Abort(association id [, cause code])
4533 * Ungracefully closes an association. Any locally queued user data
4534 * will be discarded and an ABORT chunk is sent to the peer. A success code
4535 * will be returned on successful abortion of the association. If
4536 * attempting to abort the association results in a failure, an error
4537 * code shall be returned.
4539 * Mandatory attributes:
4541 * o association id - local handle to the SCTP association
4543 * Optional attributes:
4545 * o cause code - reason of the abort to be passed to the peer
4549 * The return value is the disposition.
4551 sctp_disposition_t sctp_sf_do_9_1_prm_abort(
4552 const struct sctp_endpoint *ep,
4553 const struct sctp_association *asoc,
4554 const sctp_subtype_t type,
4556 sctp_cmd_seq_t *commands)
4558 /* From 9.1 Abort of an Association
4559 * Upon receipt of the ABORT primitive from its upper
4560 * layer, the endpoint enters CLOSED state and
4561 * discard all outstanding data has been
4562 * acknowledged by its peer. The endpoint accepts no new data
4563 * from its upper layer, but retransmits data to the far end
4564 * if necessary to fill gaps.
4566 struct sctp_chunk *abort = arg;
4567 sctp_disposition_t retval;
4569 retval = SCTP_DISPOSITION_CONSUME;
4571 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4573 /* Even if we can't send the ABORT due to low memory delete the
4574 * TCB. This is a departure from our typical NOMEM handling.
4577 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4578 SCTP_ERROR(ECONNABORTED));
4579 /* Delete the established association. */
4580 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4581 SCTP_PERR(SCTP_ERROR_USER_ABORT));
4583 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4584 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4589 /* We tried an illegal operation on an association which is closed. */
4590 sctp_disposition_t sctp_sf_error_closed(const struct sctp_endpoint *ep,
4591 const struct sctp_association *asoc,
4592 const sctp_subtype_t type,
4594 sctp_cmd_seq_t *commands)
4596 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL));
4597 return SCTP_DISPOSITION_CONSUME;
4600 /* We tried an illegal operation on an association which is shutting
4603 sctp_disposition_t sctp_sf_error_shutdown(const struct sctp_endpoint *ep,
4604 const struct sctp_association *asoc,
4605 const sctp_subtype_t type,
4607 sctp_cmd_seq_t *commands)
4609 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR,
4610 SCTP_ERROR(-ESHUTDOWN));
4611 return SCTP_DISPOSITION_CONSUME;
4615 * sctp_cookie_wait_prm_shutdown
4617 * Section: 4 Note: 2
4622 * The RFC does not explicitly address this issue, but is the route through the
4623 * state table when someone issues a shutdown while in COOKIE_WAIT state.
4628 sctp_disposition_t sctp_sf_cookie_wait_prm_shutdown(
4629 const struct sctp_endpoint *ep,
4630 const struct sctp_association *asoc,
4631 const sctp_subtype_t type,
4633 sctp_cmd_seq_t *commands)
4635 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4636 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4638 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4639 SCTP_STATE(SCTP_STATE_CLOSED));
4641 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
4643 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
4645 return SCTP_DISPOSITION_DELETE_TCB;
4649 * sctp_cookie_echoed_prm_shutdown
4651 * Section: 4 Note: 2
4656 * The RFC does not explcitly address this issue, but is the route through the
4657 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
4662 sctp_disposition_t sctp_sf_cookie_echoed_prm_shutdown(
4663 const struct sctp_endpoint *ep,
4664 const struct sctp_association *asoc,
4665 const sctp_subtype_t type,
4666 void *arg, sctp_cmd_seq_t *commands)
4668 /* There is a single T1 timer, so we should be able to use
4669 * common function with the COOKIE-WAIT state.
4671 return sctp_sf_cookie_wait_prm_shutdown(ep, asoc, type, arg, commands);
4675 * sctp_sf_cookie_wait_prm_abort
4677 * Section: 4 Note: 2
4682 * The RFC does not explicitly address this issue, but is the route through the
4683 * state table when someone issues an abort while in COOKIE_WAIT state.
4688 sctp_disposition_t sctp_sf_cookie_wait_prm_abort(
4689 const struct sctp_endpoint *ep,
4690 const struct sctp_association *asoc,
4691 const sctp_subtype_t type,
4693 sctp_cmd_seq_t *commands)
4695 struct sctp_chunk *abort = arg;
4696 sctp_disposition_t retval;
4698 /* Stop T1-init timer */
4699 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4700 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4701 retval = SCTP_DISPOSITION_CONSUME;
4703 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4705 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4706 SCTP_STATE(SCTP_STATE_CLOSED));
4708 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4710 /* Even if we can't send the ABORT due to low memory delete the
4711 * TCB. This is a departure from our typical NOMEM handling.
4714 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4715 SCTP_ERROR(ECONNREFUSED));
4716 /* Delete the established association. */
4717 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4718 SCTP_PERR(SCTP_ERROR_USER_ABORT));
4724 * sctp_sf_cookie_echoed_prm_abort
4726 * Section: 4 Note: 3
4731 * The RFC does not explcitly address this issue, but is the route through the
4732 * state table when someone issues an abort while in COOKIE_ECHOED state.
4737 sctp_disposition_t sctp_sf_cookie_echoed_prm_abort(
4738 const struct sctp_endpoint *ep,
4739 const struct sctp_association *asoc,
4740 const sctp_subtype_t type,
4742 sctp_cmd_seq_t *commands)
4744 /* There is a single T1 timer, so we should be able to use
4745 * common function with the COOKIE-WAIT state.
4747 return sctp_sf_cookie_wait_prm_abort(ep, asoc, type, arg, commands);
4751 * sctp_sf_shutdown_pending_prm_abort
4756 * The RFC does not explicitly address this issue, but is the route through the
4757 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
4762 sctp_disposition_t sctp_sf_shutdown_pending_prm_abort(
4763 const struct sctp_endpoint *ep,
4764 const struct sctp_association *asoc,
4765 const sctp_subtype_t type,
4767 sctp_cmd_seq_t *commands)
4769 /* Stop the T5-shutdown guard timer. */
4770 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4771 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4773 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
4777 * sctp_sf_shutdown_sent_prm_abort
4782 * The RFC does not explicitly address this issue, but is the route through the
4783 * state table when someone issues an abort while in SHUTDOWN-SENT state.
4788 sctp_disposition_t sctp_sf_shutdown_sent_prm_abort(
4789 const struct sctp_endpoint *ep,
4790 const struct sctp_association *asoc,
4791 const sctp_subtype_t type,
4793 sctp_cmd_seq_t *commands)
4795 /* Stop the T2-shutdown timer. */
4796 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4797 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4799 /* Stop the T5-shutdown guard timer. */
4800 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4801 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4803 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
4807 * sctp_sf_cookie_echoed_prm_abort
4812 * The RFC does not explcitly address this issue, but is the route through the
4813 * state table when someone issues an abort while in COOKIE_ECHOED state.
4818 sctp_disposition_t sctp_sf_shutdown_ack_sent_prm_abort(
4819 const struct sctp_endpoint *ep,
4820 const struct sctp_association *asoc,
4821 const sctp_subtype_t type,
4823 sctp_cmd_seq_t *commands)
4825 /* The same T2 timer, so we should be able to use
4826 * common function with the SHUTDOWN-SENT state.
4828 return sctp_sf_shutdown_sent_prm_abort(ep, asoc, type, arg, commands);
4832 * Process the REQUESTHEARTBEAT primitive
4835 * J) Request Heartbeat
4837 * Format: REQUESTHEARTBEAT(association id, destination transport address)
4841 * Instructs the local endpoint to perform a HeartBeat on the specified
4842 * destination transport address of the given association. The returned
4843 * result should indicate whether the transmission of the HEARTBEAT
4844 * chunk to the destination address is successful.
4846 * Mandatory attributes:
4848 * o association id - local handle to the SCTP association
4850 * o destination transport address - the transport address of the
4851 * association on which a heartbeat should be issued.
4853 sctp_disposition_t sctp_sf_do_prm_requestheartbeat(
4854 const struct sctp_endpoint *ep,
4855 const struct sctp_association *asoc,
4856 const sctp_subtype_t type,
4858 sctp_cmd_seq_t *commands)
4860 if (SCTP_DISPOSITION_NOMEM == sctp_sf_heartbeat(ep, asoc, type,
4861 (struct sctp_transport *)arg, commands))
4862 return SCTP_DISPOSITION_NOMEM;
4865 * RFC 2960 (bis), section 8.3
4867 * D) Request an on-demand HEARTBEAT on a specific destination
4868 * transport address of a given association.
4870 * The endpoint should increment the respective error counter of
4871 * the destination transport address each time a HEARTBEAT is sent
4872 * to that address and not acknowledged within one RTO.
4875 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET,
4876 SCTP_TRANSPORT(arg));
4877 return SCTP_DISPOSITION_CONSUME;
4881 * ADDIP Section 4.1 ASCONF Chunk Procedures
4882 * When an endpoint has an ASCONF signaled change to be sent to the
4883 * remote endpoint it should do A1 to A9
4885 sctp_disposition_t sctp_sf_do_prm_asconf(const struct sctp_endpoint *ep,
4886 const struct sctp_association *asoc,
4887 const sctp_subtype_t type,
4889 sctp_cmd_seq_t *commands)
4891 struct sctp_chunk *chunk = arg;
4893 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
4894 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4895 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4896 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
4897 return SCTP_DISPOSITION_CONSUME;
4901 * Ignore the primitive event
4903 * The return value is the disposition of the primitive.
4905 sctp_disposition_t sctp_sf_ignore_primitive(
4906 const struct sctp_endpoint *ep,
4907 const struct sctp_association *asoc,
4908 const sctp_subtype_t type,
4910 sctp_cmd_seq_t *commands)
4912 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type.primitive);
4913 return SCTP_DISPOSITION_DISCARD;
4916 /***************************************************************************
4917 * These are the state functions for the OTHER events.
4918 ***************************************************************************/
4921 * Start the shutdown negotiation.
4924 * Once all its outstanding data has been acknowledged, the endpoint
4925 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
4926 * TSN Ack field the last sequential TSN it has received from the peer.
4927 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
4928 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
4929 * with the updated last sequential TSN received from its peer.
4931 * The return value is the disposition.
4933 sctp_disposition_t sctp_sf_do_9_2_start_shutdown(
4934 const struct sctp_endpoint *ep,
4935 const struct sctp_association *asoc,
4936 const sctp_subtype_t type,
4938 sctp_cmd_seq_t *commands)
4940 struct sctp_chunk *reply;
4942 /* Once all its outstanding data has been acknowledged, the
4943 * endpoint shall send a SHUTDOWN chunk to its peer including
4944 * in the Cumulative TSN Ack field the last sequential TSN it
4945 * has received from the peer.
4947 reply = sctp_make_shutdown(asoc, NULL);
4951 /* Set the transport for the SHUTDOWN chunk and the timeout for the
4952 * T2-shutdown timer.
4954 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4956 /* It shall then start the T2-shutdown timer */
4957 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4958 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4960 if (asoc->autoclose)
4961 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4962 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
4964 /* and enter the SHUTDOWN-SENT state. */
4965 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4966 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT));
4968 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4970 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4973 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
4975 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4977 return SCTP_DISPOSITION_CONSUME;
4980 return SCTP_DISPOSITION_NOMEM;
4984 * Generate a SHUTDOWN ACK now that everything is SACK'd.
4988 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4989 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
4990 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
4991 * endpoint must re-send the SHUTDOWN ACK.
4993 * The return value is the disposition.
4995 sctp_disposition_t sctp_sf_do_9_2_shutdown_ack(
4996 const struct sctp_endpoint *ep,
4997 const struct sctp_association *asoc,
4998 const sctp_subtype_t type,
5000 sctp_cmd_seq_t *commands)
5002 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
5003 struct sctp_chunk *reply;
5005 /* There are 2 ways of getting here:
5006 * 1) called in response to a SHUTDOWN chunk
5007 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
5009 * For the case (2), the arg parameter is set to NULL. We need
5010 * to check that we have a chunk before accessing it's fields.
5013 if (!sctp_vtag_verify(chunk, asoc))
5014 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
5016 /* Make sure that the SHUTDOWN chunk has a valid length. */
5017 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk_t)))
5018 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
5022 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5023 * shall send a SHUTDOWN ACK ...
5025 reply = sctp_make_shutdown_ack(asoc, chunk);
5029 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
5030 * the T2-shutdown timer.
5032 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
5034 /* and start/restart a T2-shutdown timer of its own, */
5035 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
5036 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
5038 if (asoc->autoclose)
5039 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5040 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
5042 /* Enter the SHUTDOWN-ACK-SENT state. */
5043 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
5044 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT));
5046 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5048 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5051 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
5053 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
5055 return SCTP_DISPOSITION_CONSUME;
5058 return SCTP_DISPOSITION_NOMEM;
5062 * Ignore the event defined as other
5064 * The return value is the disposition of the event.
5066 sctp_disposition_t sctp_sf_ignore_other(const struct sctp_endpoint *ep,
5067 const struct sctp_association *asoc,
5068 const sctp_subtype_t type,
5070 sctp_cmd_seq_t *commands)
5072 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type.other);
5073 return SCTP_DISPOSITION_DISCARD;
5076 /************************************************************
5077 * These are the state functions for handling timeout events.
5078 ************************************************************/
5083 * Section: 6.3.3 Handle T3-rtx Expiration
5085 * Whenever the retransmission timer T3-rtx expires for a destination
5086 * address, do the following:
5089 * The return value is the disposition of the chunk.
5091 sctp_disposition_t sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint *ep,
5092 const struct sctp_association *asoc,
5093 const sctp_subtype_t type,
5095 sctp_cmd_seq_t *commands)
5097 struct sctp_transport *transport = arg;
5099 SCTP_INC_STATS(SCTP_MIB_T3_RTX_EXPIREDS);
5101 if (asoc->overall_error_count >= asoc->max_retrans) {
5102 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5103 SCTP_ERROR(ETIMEDOUT));
5104 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5105 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5106 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5107 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
5108 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
5109 return SCTP_DISPOSITION_DELETE_TCB;
5112 /* E1) For the destination address for which the timer
5113 * expires, adjust its ssthresh with rules defined in Section
5114 * 7.2.3 and set the cwnd <- MTU.
5117 /* E2) For the destination address for which the timer
5118 * expires, set RTO <- RTO * 2 ("back off the timer"). The
5119 * maximum value discussed in rule C7 above (RTO.max) may be
5120 * used to provide an upper bound to this doubling operation.
5123 /* E3) Determine how many of the earliest (i.e., lowest TSN)
5124 * outstanding DATA chunks for the address for which the
5125 * T3-rtx has expired will fit into a single packet, subject
5126 * to the MTU constraint for the path corresponding to the
5127 * destination transport address to which the retransmission
5128 * is being sent (this may be different from the address for
5129 * which the timer expires [see Section 6.4]). Call this
5130 * value K. Bundle and retransmit those K DATA chunks in a
5131 * single packet to the destination endpoint.
5133 * Note: Any DATA chunks that were sent to the address for
5134 * which the T3-rtx timer expired but did not fit in one MTU
5135 * (rule E3 above), should be marked for retransmission and
5136 * sent as soon as cwnd allows (normally when a SACK arrives).
5139 /* Do some failure management (Section 8.2). */
5140 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
5142 /* NB: Rules E4 and F1 are implicit in R1. */
5143 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport));
5145 return SCTP_DISPOSITION_CONSUME;
5149 * Generate delayed SACK on timeout
5151 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
5153 * The guidelines on delayed acknowledgement algorithm specified in
5154 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
5155 * acknowledgement SHOULD be generated for at least every second packet
5156 * (not every second DATA chunk) received, and SHOULD be generated
5157 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
5158 * some situations it may be beneficial for an SCTP transmitter to be
5159 * more conservative than the algorithms detailed in this document
5160 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
5161 * the following algorithms allow.
5163 sctp_disposition_t sctp_sf_do_6_2_sack(const struct sctp_endpoint *ep,
5164 const struct sctp_association *asoc,
5165 const sctp_subtype_t type,
5167 sctp_cmd_seq_t *commands)
5169 SCTP_INC_STATS(SCTP_MIB_DELAY_SACK_EXPIREDS);
5170 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
5171 return SCTP_DISPOSITION_CONSUME;
5175 * sctp_sf_t1_init_timer_expire
5177 * Section: 4 Note: 2
5182 * RFC 2960 Section 4 Notes
5183 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
5184 * and re-start the T1-init timer without changing state. This MUST
5185 * be repeated up to 'Max.Init.Retransmits' times. After that, the
5186 * endpoint MUST abort the initialization process and report the
5187 * error to SCTP user.
5193 sctp_disposition_t sctp_sf_t1_init_timer_expire(const struct sctp_endpoint *ep,
5194 const struct sctp_association *asoc,
5195 const sctp_subtype_t type,
5197 sctp_cmd_seq_t *commands)
5199 struct sctp_chunk *repl = NULL;
5200 struct sctp_bind_addr *bp;
5201 int attempts = asoc->init_err_counter + 1;
5203 SCTP_DEBUG_PRINTK("Timer T1 expired (INIT).\n");
5204 SCTP_INC_STATS(SCTP_MIB_T1_INIT_EXPIREDS);
5206 if (attempts <= asoc->max_init_attempts) {
5207 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
5208 repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0);
5210 return SCTP_DISPOSITION_NOMEM;
5212 /* Choose transport for INIT. */
5213 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
5216 /* Issue a sideeffect to do the needed accounting. */
5217 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART,
5218 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
5220 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
5222 SCTP_DEBUG_PRINTK("Giving up on INIT, attempts: %d"
5223 " max_init_attempts: %d\n",
5224 attempts, asoc->max_init_attempts);
5225 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5226 SCTP_ERROR(ETIMEDOUT));
5227 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
5228 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5229 return SCTP_DISPOSITION_DELETE_TCB;
5232 return SCTP_DISPOSITION_CONSUME;
5236 * sctp_sf_t1_cookie_timer_expire
5238 * Section: 4 Note: 2
5243 * RFC 2960 Section 4 Notes
5244 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
5245 * COOKIE ECHO and re-start the T1-cookie timer without changing
5246 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
5247 * After that, the endpoint MUST abort the initialization process and
5248 * report the error to SCTP user.
5254 sctp_disposition_t sctp_sf_t1_cookie_timer_expire(const struct sctp_endpoint *ep,
5255 const struct sctp_association *asoc,
5256 const sctp_subtype_t type,
5258 sctp_cmd_seq_t *commands)
5260 struct sctp_chunk *repl = NULL;
5261 int attempts = asoc->init_err_counter + 1;
5263 SCTP_DEBUG_PRINTK("Timer T1 expired (COOKIE-ECHO).\n");
5264 SCTP_INC_STATS(SCTP_MIB_T1_COOKIE_EXPIREDS);
5266 if (attempts <= asoc->max_init_attempts) {
5267 repl = sctp_make_cookie_echo(asoc, NULL);
5269 return SCTP_DISPOSITION_NOMEM;
5271 /* Issue a sideeffect to do the needed accounting. */
5272 sctp_add_cmd_sf(commands, SCTP_CMD_COOKIEECHO_RESTART,
5273 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
5275 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
5277 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5278 SCTP_ERROR(ETIMEDOUT));
5279 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
5280 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5281 return SCTP_DISPOSITION_DELETE_TCB;
5284 return SCTP_DISPOSITION_CONSUME;
5287 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
5288 * with the updated last sequential TSN received from its peer.
5290 * An endpoint should limit the number of retransmissions of the
5291 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
5292 * If this threshold is exceeded the endpoint should destroy the TCB and
5293 * MUST report the peer endpoint unreachable to the upper layer (and
5294 * thus the association enters the CLOSED state). The reception of any
5295 * packet from its peer (i.e. as the peer sends all of its queued DATA
5296 * chunks) should clear the endpoint's retransmission count and restart
5297 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
5298 * all of its queued DATA chunks that have not yet been sent.
5300 sctp_disposition_t sctp_sf_t2_timer_expire(const struct sctp_endpoint *ep,
5301 const struct sctp_association *asoc,
5302 const sctp_subtype_t type,
5304 sctp_cmd_seq_t *commands)
5306 struct sctp_chunk *reply = NULL;
5308 SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
5309 SCTP_INC_STATS(SCTP_MIB_T2_SHUTDOWN_EXPIREDS);
5311 ((struct sctp_association *)asoc)->shutdown_retries++;
5313 if (asoc->overall_error_count >= asoc->max_retrans) {
5314 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5315 SCTP_ERROR(ETIMEDOUT));
5316 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5317 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5318 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5319 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
5320 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
5321 return SCTP_DISPOSITION_DELETE_TCB;
5324 switch (asoc->state) {
5325 case SCTP_STATE_SHUTDOWN_SENT:
5326 reply = sctp_make_shutdown(asoc, NULL);
5329 case SCTP_STATE_SHUTDOWN_ACK_SENT:
5330 reply = sctp_make_shutdown_ack(asoc, NULL);
5341 /* Do some failure management (Section 8.2). */
5342 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
5343 SCTP_TRANSPORT(asoc->shutdown_last_sent_to));
5345 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
5346 * the T2-shutdown timer.
5348 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
5350 /* Restart the T2-shutdown timer. */
5351 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
5352 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
5353 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
5354 return SCTP_DISPOSITION_CONSUME;
5357 return SCTP_DISPOSITION_NOMEM;
5361 * ADDIP Section 4.1 ASCONF CHunk Procedures
5362 * If the T4 RTO timer expires the endpoint should do B1 to B5
5364 sctp_disposition_t sctp_sf_t4_timer_expire(
5365 const struct sctp_endpoint *ep,
5366 const struct sctp_association *asoc,
5367 const sctp_subtype_t type,
5369 sctp_cmd_seq_t *commands)
5371 struct sctp_chunk *chunk = asoc->addip_last_asconf;
5372 struct sctp_transport *transport = chunk->transport;
5374 SCTP_INC_STATS(SCTP_MIB_T4_RTO_EXPIREDS);
5376 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
5377 * detection on the appropriate destination address as defined in
5378 * RFC2960 [5] section 8.1 and 8.2.
5380 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
5382 /* Reconfig T4 timer and transport. */
5383 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
5385 /* ADDIP 4.1 B2) Increment the association error counters and perform
5386 * endpoint failure detection on the association as defined in
5387 * RFC2960 [5] section 8.1 and 8.2.
5388 * association error counter is incremented in SCTP_CMD_STRIKE.
5390 if (asoc->overall_error_count >= asoc->max_retrans) {
5391 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5392 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
5393 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5394 SCTP_ERROR(ETIMEDOUT));
5395 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5396 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5397 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
5398 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
5399 return SCTP_DISPOSITION_ABORT;
5402 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
5403 * the ASCONF chunk was sent by doubling the RTO timer value.
5404 * This is done in SCTP_CMD_STRIKE.
5407 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
5408 * choose an alternate destination address (please refer to RFC2960
5409 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
5410 * chunk, it MUST be the same (including its serial number) as the last
5413 sctp_chunk_hold(asoc->addip_last_asconf);
5414 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
5415 SCTP_CHUNK(asoc->addip_last_asconf));
5417 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
5418 * destination is selected, then the RTO used will be that of the new
5419 * destination address.
5421 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
5422 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
5424 return SCTP_DISPOSITION_CONSUME;
5427 /* sctpimpguide-05 Section 2.12.2
5428 * The sender of the SHUTDOWN MAY also start an overall guard timer
5429 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5430 * At the expiration of this timer the sender SHOULD abort the association
5431 * by sending an ABORT chunk.
5433 sctp_disposition_t sctp_sf_t5_timer_expire(const struct sctp_endpoint *ep,
5434 const struct sctp_association *asoc,
5435 const sctp_subtype_t type,
5437 sctp_cmd_seq_t *commands)
5439 struct sctp_chunk *reply = NULL;
5441 SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
5442 SCTP_INC_STATS(SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS);
5444 reply = sctp_make_abort(asoc, NULL, 0);
5448 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
5449 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5450 SCTP_ERROR(ETIMEDOUT));
5451 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5452 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5454 return SCTP_DISPOSITION_DELETE_TCB;
5456 return SCTP_DISPOSITION_NOMEM;
5459 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
5460 * the association is automatically closed by starting the shutdown process.
5461 * The work that needs to be done is same as when SHUTDOWN is initiated by
5462 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
5464 sctp_disposition_t sctp_sf_autoclose_timer_expire(
5465 const struct sctp_endpoint *ep,
5466 const struct sctp_association *asoc,
5467 const sctp_subtype_t type,
5469 sctp_cmd_seq_t *commands)
5473 SCTP_INC_STATS(SCTP_MIB_AUTOCLOSE_EXPIREDS);
5475 /* From 9.2 Shutdown of an Association
5476 * Upon receipt of the SHUTDOWN primitive from its upper
5477 * layer, the endpoint enters SHUTDOWN-PENDING state and
5478 * remains there until all outstanding data has been
5479 * acknowledged by its peer. The endpoint accepts no new data
5480 * from its upper layer, but retransmits data to the far end
5481 * if necessary to fill gaps.
5483 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
5484 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
5486 /* sctpimpguide-05 Section 2.12.2
5487 * The sender of the SHUTDOWN MAY also start an overall guard timer
5488 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5490 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
5491 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
5492 disposition = SCTP_DISPOSITION_CONSUME;
5493 if (sctp_outq_is_empty(&asoc->outqueue)) {
5494 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
5500 /*****************************************************************************
5501 * These are sa state functions which could apply to all types of events.
5502 ****************************************************************************/
5505 * This table entry is not implemented.
5508 * (endpoint, asoc, chunk)
5510 * The return value is the disposition of the chunk.
5512 sctp_disposition_t sctp_sf_not_impl(const struct sctp_endpoint *ep,
5513 const struct sctp_association *asoc,
5514 const sctp_subtype_t type,
5516 sctp_cmd_seq_t *commands)
5518 return SCTP_DISPOSITION_NOT_IMPL;
5522 * This table entry represents a bug.
5525 * (endpoint, asoc, chunk)
5527 * The return value is the disposition of the chunk.
5529 sctp_disposition_t sctp_sf_bug(const struct sctp_endpoint *ep,
5530 const struct sctp_association *asoc,
5531 const sctp_subtype_t type,
5533 sctp_cmd_seq_t *commands)
5535 return SCTP_DISPOSITION_BUG;
5539 * This table entry represents the firing of a timer in the wrong state.
5540 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
5541 * when the association is in the wrong state. This event should
5542 * be ignored, so as to prevent any rearming of the timer.
5545 * (endpoint, asoc, chunk)
5547 * The return value is the disposition of the chunk.
5549 sctp_disposition_t sctp_sf_timer_ignore(const struct sctp_endpoint *ep,
5550 const struct sctp_association *asoc,
5551 const sctp_subtype_t type,
5553 sctp_cmd_seq_t *commands)
5555 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type.chunk);
5556 return SCTP_DISPOSITION_CONSUME;
5559 /********************************************************************
5560 * 2nd Level Abstractions
5561 ********************************************************************/
5563 /* Pull the SACK chunk based on the SACK header. */
5564 static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk)
5566 struct sctp_sackhdr *sack;
5571 /* Protect ourselves from reading too far into
5572 * the skb from a bogus sender.
5574 sack = (struct sctp_sackhdr *) chunk->skb->data;
5576 num_blocks = ntohs(sack->num_gap_ack_blocks);
5577 num_dup_tsns = ntohs(sack->num_dup_tsns);
5578 len = sizeof(struct sctp_sackhdr);
5579 len += (num_blocks + num_dup_tsns) * sizeof(__u32);
5580 if (len > chunk->skb->len)
5583 skb_pull(chunk->skb, len);
5588 /* Create an ABORT packet to be sent as a response, with the specified
5591 static struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep,
5592 const struct sctp_association *asoc,
5593 struct sctp_chunk *chunk,
5594 const void *payload,
5597 struct sctp_packet *packet;
5598 struct sctp_chunk *abort;
5600 packet = sctp_ootb_pkt_new(asoc, chunk);
5604 * The T bit will be set if the asoc is NULL.
5606 abort = sctp_make_abort(asoc, chunk, paylen);
5608 sctp_ootb_pkt_free(packet);
5612 /* Reflect vtag if T-Bit is set */
5613 if (sctp_test_T_bit(abort))
5614 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
5616 /* Add specified error causes, i.e., payload, to the
5619 sctp_addto_chunk(abort, paylen, payload);
5621 /* Set the skb to the belonging sock for accounting. */
5622 abort->skb->sk = ep->base.sk;
5624 sctp_packet_append_chunk(packet, abort);
5631 /* Allocate a packet for responding in the OOTB conditions. */
5632 static struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc,
5633 const struct sctp_chunk *chunk)
5635 struct sctp_packet *packet;
5636 struct sctp_transport *transport;
5641 /* Get the source and destination port from the inbound packet. */
5642 sport = ntohs(chunk->sctp_hdr->dest);
5643 dport = ntohs(chunk->sctp_hdr->source);
5645 /* The V-tag is going to be the same as the inbound packet if no
5646 * association exists, otherwise, use the peer's vtag.
5649 /* Special case the INIT-ACK as there is no peer's vtag
5652 switch(chunk->chunk_hdr->type) {
5653 case SCTP_CID_INIT_ACK:
5655 sctp_initack_chunk_t *initack;
5657 initack = (sctp_initack_chunk_t *)chunk->chunk_hdr;
5658 vtag = ntohl(initack->init_hdr.init_tag);
5662 vtag = asoc->peer.i.init_tag;
5666 /* Special case the INIT and stale COOKIE_ECHO as there is no
5669 switch(chunk->chunk_hdr->type) {
5672 sctp_init_chunk_t *init;
5674 init = (sctp_init_chunk_t *)chunk->chunk_hdr;
5675 vtag = ntohl(init->init_hdr.init_tag);
5679 vtag = ntohl(chunk->sctp_hdr->vtag);
5684 /* Make a transport for the bucket, Eliza... */
5685 transport = sctp_transport_new(sctp_source(chunk), GFP_ATOMIC);
5689 /* Cache a route for the transport with the chunk's destination as
5690 * the source address.
5692 sctp_transport_route(transport, (union sctp_addr *)&chunk->dest,
5693 sctp_sk(sctp_get_ctl_sock()));
5695 packet = sctp_packet_init(&transport->packet, transport, sport, dport);
5696 packet = sctp_packet_config(packet, vtag, 0);
5704 /* Free the packet allocated earlier for responding in the OOTB condition. */
5705 void sctp_ootb_pkt_free(struct sctp_packet *packet)
5707 sctp_transport_free(packet->transport);
5710 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
5711 static void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep,
5712 const struct sctp_association *asoc,
5713 const struct sctp_chunk *chunk,
5714 sctp_cmd_seq_t *commands,
5715 struct sctp_chunk *err_chunk)
5717 struct sctp_packet *packet;
5720 packet = sctp_ootb_pkt_new(asoc, chunk);
5722 struct sctp_signed_cookie *cookie;
5724 /* Override the OOTB vtag from the cookie. */
5725 cookie = chunk->subh.cookie_hdr;
5726 packet->vtag = cookie->c.peer_vtag;
5728 /* Set the skb to the belonging sock for accounting. */
5729 err_chunk->skb->sk = ep->base.sk;
5730 sctp_packet_append_chunk(packet, err_chunk);
5731 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
5732 SCTP_PACKET(packet));
5733 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
5735 sctp_chunk_free (err_chunk);
5740 /* Process a data chunk */
5741 static int sctp_eat_data(const struct sctp_association *asoc,
5742 struct sctp_chunk *chunk,
5743 sctp_cmd_seq_t *commands)
5745 sctp_datahdr_t *data_hdr;
5746 struct sctp_chunk *err;
5748 sctp_verb_t deliver;
5751 struct sctp_tsnmap *map = (struct sctp_tsnmap *)&asoc->peer.tsn_map;
5752 struct sock *sk = asoc->base.sk;
5754 data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *)chunk->skb->data;
5755 skb_pull(chunk->skb, sizeof(sctp_datahdr_t));
5757 tsn = ntohl(data_hdr->tsn);
5758 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn);
5760 /* ASSERT: Now skb->data is really the user data. */
5762 /* Process ECN based congestion.
5764 * Since the chunk structure is reused for all chunks within
5765 * a packet, we use ecn_ce_done to track if we've already
5766 * done CE processing for this packet.
5768 * We need to do ECN processing even if we plan to discard the
5772 if (!chunk->ecn_ce_done) {
5774 chunk->ecn_ce_done = 1;
5776 af = sctp_get_af_specific(
5777 ipver2af(ip_hdr(chunk->skb)->version));
5779 if (af && af->is_ce(chunk->skb) && asoc->peer.ecn_capable) {
5780 /* Do real work as sideffect. */
5781 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
5786 tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
5788 /* The TSN is too high--silently discard the chunk and
5789 * count on it getting retransmitted later.
5791 return SCTP_IERROR_HIGH_TSN;
5792 } else if (tmp > 0) {
5793 /* This is a duplicate. Record it. */
5794 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
5795 return SCTP_IERROR_DUP_TSN;
5798 /* This is a new TSN. */
5800 /* Discard if there is no room in the receive window.
5801 * Actually, allow a little bit of overflow (up to a MTU).
5803 datalen = ntohs(chunk->chunk_hdr->length);
5804 datalen -= sizeof(sctp_data_chunk_t);
5806 deliver = SCTP_CMD_CHUNK_ULP;
5808 /* Think about partial delivery. */
5809 if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) {
5811 /* Even if we don't accept this chunk there is
5814 sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL());
5817 /* Spill over rwnd a little bit. Note: While allowed, this spill over
5818 * seems a bit troublesome in that frag_point varies based on
5819 * PMTU. In cases, such as loopback, this might be a rather
5822 if ((!chunk->data_accepted) && (!asoc->rwnd || asoc->rwnd_over ||
5823 (datalen > asoc->rwnd + asoc->frag_point))) {
5825 /* If this is the next TSN, consider reneging to make
5826 * room. Note: Playing nice with a confused sender. A
5827 * malicious sender can still eat up all our buffer
5828 * space and in the future we may want to detect and
5829 * do more drastic reneging.
5831 if (sctp_tsnmap_has_gap(map) &&
5832 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
5833 SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn);
5834 deliver = SCTP_CMD_RENEGE;
5836 SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
5837 "rwnd: %d\n", tsn, datalen,
5839 return SCTP_IERROR_IGNORE_TSN;
5844 * Also try to renege to limit our memory usage in the event that
5845 * we are under memory pressure
5846 * If we can't renege, don't worry about it, the sk_rmem_schedule
5847 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
5848 * memory usage too much
5850 if (*sk->sk_prot_creator->memory_pressure) {
5851 if (sctp_tsnmap_has_gap(map) &&
5852 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
5853 SCTP_DEBUG_PRINTK("Under Pressure! Reneging for tsn:%u\n", tsn);
5854 deliver = SCTP_CMD_RENEGE;
5859 * Section 3.3.10.9 No User Data (9)
5863 * No User Data: This error cause is returned to the originator of a
5864 * DATA chunk if a received DATA chunk has no user data.
5866 if (unlikely(0 == datalen)) {
5867 err = sctp_make_abort_no_data(asoc, chunk, tsn);
5869 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
5872 /* We are going to ABORT, so we might as well stop
5873 * processing the rest of the chunks in the packet.
5875 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
5876 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5877 SCTP_ERROR(ECONNABORTED));
5878 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5879 SCTP_PERR(SCTP_ERROR_NO_DATA));
5880 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
5881 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
5882 return SCTP_IERROR_NO_DATA;
5885 /* If definately accepting the DATA chunk, record its TSN, otherwise
5886 * wait for renege processing.
5888 if (SCTP_CMD_CHUNK_ULP == deliver)
5889 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
5891 chunk->data_accepted = 1;
5893 /* Note: Some chunks may get overcounted (if we drop) or overcounted
5894 * if we renege and the chunk arrives again.
5896 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
5897 SCTP_INC_STATS(SCTP_MIB_INUNORDERCHUNKS);
5899 SCTP_INC_STATS(SCTP_MIB_INORDERCHUNKS);
5901 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
5903 * If an endpoint receive a DATA chunk with an invalid stream
5904 * identifier, it shall acknowledge the reception of the DATA chunk
5905 * following the normal procedure, immediately send an ERROR chunk
5906 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
5907 * and discard the DATA chunk.
5909 if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) {
5910 err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
5912 sizeof(data_hdr->stream));
5914 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
5916 return SCTP_IERROR_BAD_STREAM;
5919 /* Send the data up to the user. Note: Schedule the
5920 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
5921 * chunk needs the updated rwnd.
5923 sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk));
5925 return SCTP_IERROR_NO_ERROR;