1 /* SCTP kernel reference Implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001-2002 Intel Corp.
6 * Copyright (c) 2002 Nokia Corp.
8 * This file is part of the SCTP kernel reference Implementation
10 * This is part of the SCTP Linux Kernel Reference Implementation.
12 * These are the state functions for the state machine.
14 * The SCTP reference implementation is free software;
15 * you can redistribute it and/or modify it under the terms of
16 * the GNU General Public License as published by
17 * the Free Software Foundation; either version 2, or (at your option)
20 * The SCTP reference implementation is distributed in the hope that it
21 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
22 * ************************
23 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 * See the GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with GNU CC; see the file COPYING. If not, write to
28 * the Free Software Foundation, 59 Temple Place - Suite 330,
29 * Boston, MA 02111-1307, USA.
31 * Please send any bug reports or fixes you make to the
33 * lksctp developers <lksctp-developers@lists.sourceforge.net>
35 * Or submit a bug report through the following website:
36 * http://www.sf.net/projects/lksctp
38 * Written or modified by:
39 * La Monte H.P. Yarroll <piggy@acm.org>
40 * Karl Knutson <karl@athena.chicago.il.us>
41 * Mathew Kotowsky <kotowsky@sctp.org>
42 * Sridhar Samudrala <samudrala@us.ibm.com>
43 * Jon Grimm <jgrimm@us.ibm.com>
44 * Hui Huang <hui.huang@nokia.com>
45 * Dajiang Zhang <dajiang.zhang@nokia.com>
46 * Daisy Chang <daisyc@us.ibm.com>
47 * Ardelle Fan <ardelle.fan@intel.com>
48 * Ryan Layer <rmlayer@us.ibm.com>
49 * Kevin Gao <kevin.gao@intel.com>
51 * Any bugs reported given to us we will try to fix... any fixes shared will
52 * be incorporated into the next SCTP release.
55 #include <linux/types.h>
56 #include <linux/kernel.h>
58 #include <linux/ipv6.h>
59 #include <linux/net.h>
60 #include <linux/inet.h>
62 #include <net/inet_ecn.h>
63 #include <linux/skbuff.h>
64 #include <net/sctp/sctp.h>
65 #include <net/sctp/sm.h>
66 #include <net/sctp/structs.h>
68 static struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep,
69 const struct sctp_association *asoc,
70 struct sctp_chunk *chunk,
73 static int sctp_eat_data(const struct sctp_association *asoc,
74 struct sctp_chunk *chunk,
75 sctp_cmd_seq_t *commands);
76 static struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc,
77 const struct sctp_chunk *chunk);
78 static void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep,
79 const struct sctp_association *asoc,
80 const struct sctp_chunk *chunk,
81 sctp_cmd_seq_t *commands,
82 struct sctp_chunk *err_chunk);
83 static sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep,
84 const struct sctp_association *asoc,
85 const sctp_subtype_t type,
87 sctp_cmd_seq_t *commands);
88 static sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep,
89 const struct sctp_association *asoc,
90 const sctp_subtype_t type,
92 sctp_cmd_seq_t *commands);
93 static sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep,
94 const struct sctp_association *asoc,
95 const sctp_subtype_t type,
97 sctp_cmd_seq_t *commands);
98 static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk);
100 static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands,
101 __be16 error, int sk_err,
102 const struct sctp_association *asoc,
103 struct sctp_transport *transport);
105 static sctp_disposition_t sctp_sf_abort_violation(
106 const struct sctp_endpoint *ep,
107 const struct sctp_association *asoc,
109 sctp_cmd_seq_t *commands,
111 const size_t paylen);
113 static sctp_disposition_t sctp_sf_violation_chunklen(
114 const struct sctp_endpoint *ep,
115 const struct sctp_association *asoc,
116 const sctp_subtype_t type,
118 sctp_cmd_seq_t *commands);
120 static sctp_disposition_t sctp_sf_violation_paramlen(
121 const struct sctp_endpoint *ep,
122 const struct sctp_association *asoc,
123 const sctp_subtype_t type,
125 sctp_cmd_seq_t *commands);
127 static sctp_disposition_t sctp_sf_violation_ctsn(
128 const struct sctp_endpoint *ep,
129 const struct sctp_association *asoc,
130 const sctp_subtype_t type,
132 sctp_cmd_seq_t *commands);
134 static sctp_disposition_t sctp_sf_violation_chunk(
135 const struct sctp_endpoint *ep,
136 const struct sctp_association *asoc,
137 const sctp_subtype_t type,
139 sctp_cmd_seq_t *commands);
141 static sctp_ierror_t sctp_sf_authenticate(const struct sctp_endpoint *ep,
142 const struct sctp_association *asoc,
143 const sctp_subtype_t type,
144 struct sctp_chunk *chunk);
146 static sctp_disposition_t __sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep,
147 const struct sctp_association *asoc,
148 const sctp_subtype_t type,
150 sctp_cmd_seq_t *commands);
152 /* Small helper function that checks if the chunk length
153 * is of the appropriate length. The 'required_length' argument
154 * is set to be the size of a specific chunk we are testing.
155 * Return Values: 1 = Valid length
160 sctp_chunk_length_valid(struct sctp_chunk *chunk,
161 __u16 required_length)
163 __u16 chunk_length = ntohs(chunk->chunk_hdr->length);
165 if (unlikely(chunk_length < required_length))
171 /**********************************************************
172 * These are the state functions for handling chunk events.
173 **********************************************************/
176 * Process the final SHUTDOWN COMPLETE.
178 * Section: 4 (C) (diagram), 9.2
179 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
180 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
181 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
182 * should stop the T2-shutdown timer and remove all knowledge of the
183 * association (and thus the association enters the CLOSED state).
185 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
186 * C) Rules for packet carrying SHUTDOWN COMPLETE:
188 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
189 * if the Verification Tag field of the packet matches its own tag and
190 * the T bit is not set
192 * it is set to its peer's tag and the T bit is set in the Chunk
194 * Otherwise, the receiver MUST silently discard the packet
195 * and take no further action. An endpoint MUST ignore the
196 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
199 * (endpoint, asoc, chunk)
202 * (asoc, reply_msg, msg_up, timers, counters)
204 * The return value is the disposition of the chunk.
206 sctp_disposition_t sctp_sf_do_4_C(const struct sctp_endpoint *ep,
207 const struct sctp_association *asoc,
208 const sctp_subtype_t type,
210 sctp_cmd_seq_t *commands)
212 struct sctp_chunk *chunk = arg;
213 struct sctp_ulpevent *ev;
215 if (!sctp_vtag_verify_either(chunk, asoc))
216 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
218 /* RFC 2960 6.10 Bundling
220 * An endpoint MUST NOT bundle INIT, INIT ACK or
221 * SHUTDOWN COMPLETE with any other chunks.
223 if (!chunk->singleton)
224 return sctp_sf_violation_chunk(ep, asoc, type, arg, commands);
226 /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */
227 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
228 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
231 /* RFC 2960 10.2 SCTP-to-ULP
233 * H) SHUTDOWN COMPLETE notification
235 * When SCTP completes the shutdown procedures (section 9.2) this
236 * notification is passed to the upper layer.
238 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
239 0, 0, 0, NULL, GFP_ATOMIC);
241 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
244 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
245 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
246 * not the chunk should be discarded. If the endpoint is in
247 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
248 * T2-shutdown timer and remove all knowledge of the
249 * association (and thus the association enters the CLOSED
252 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
253 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
255 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
256 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
258 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
259 SCTP_STATE(SCTP_STATE_CLOSED));
261 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
262 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
264 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
266 return SCTP_DISPOSITION_DELETE_TCB;
270 * Respond to a normal INIT chunk.
271 * We are the side that is being asked for an association.
273 * Section: 5.1 Normal Establishment of an Association, B
274 * B) "Z" shall respond immediately with an INIT ACK chunk. The
275 * destination IP address of the INIT ACK MUST be set to the source
276 * IP address of the INIT to which this INIT ACK is responding. In
277 * the response, besides filling in other parameters, "Z" must set the
278 * Verification Tag field to Tag_A, and also provide its own
279 * Verification Tag (Tag_Z) in the Initiate Tag field.
281 * Verification Tag: Must be 0.
284 * (endpoint, asoc, chunk)
287 * (asoc, reply_msg, msg_up, timers, counters)
289 * The return value is the disposition of the chunk.
291 sctp_disposition_t sctp_sf_do_5_1B_init(const struct sctp_endpoint *ep,
292 const struct sctp_association *asoc,
293 const sctp_subtype_t type,
295 sctp_cmd_seq_t *commands)
297 struct sctp_chunk *chunk = arg;
298 struct sctp_chunk *repl;
299 struct sctp_association *new_asoc;
300 struct sctp_chunk *err_chunk;
301 struct sctp_packet *packet;
302 sctp_unrecognized_param_t *unk_param;
306 * An endpoint MUST NOT bundle INIT, INIT ACK or
307 * SHUTDOWN COMPLETE with any other chunks.
310 * Furthermore, we require that the receiver of an INIT chunk MUST
311 * enforce these rules by silently discarding an arriving packet
312 * with an INIT chunk that is bundled with other chunks.
314 if (!chunk->singleton)
315 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
317 /* If the packet is an OOTB packet which is temporarily on the
318 * control endpoint, respond with an ABORT.
320 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
321 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
323 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
326 if (chunk->sctp_hdr->vtag != 0)
327 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
329 /* Make sure that the INIT chunk has a valid length.
330 * Normally, this would cause an ABORT with a Protocol Violation
331 * error, but since we don't have an association, we'll
332 * just discard the packet.
334 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
335 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
337 /* Verify the INIT chunk before processing it. */
339 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
340 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
342 /* This chunk contains fatal error. It is to be discarded.
343 * Send an ABORT, with causes if there is any.
346 packet = sctp_abort_pkt_new(ep, asoc, arg,
347 (__u8 *)(err_chunk->chunk_hdr) +
348 sizeof(sctp_chunkhdr_t),
349 ntohs(err_chunk->chunk_hdr->length) -
350 sizeof(sctp_chunkhdr_t));
352 sctp_chunk_free(err_chunk);
355 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
356 SCTP_PACKET(packet));
357 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
358 return SCTP_DISPOSITION_CONSUME;
360 return SCTP_DISPOSITION_NOMEM;
363 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
368 /* Grab the INIT header. */
369 chunk->subh.init_hdr = (sctp_inithdr_t *)chunk->skb->data;
371 /* Tag the variable length parameters. */
372 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
374 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
378 /* The call, sctp_process_init(), can fail on memory allocation. */
379 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
381 (sctp_init_chunk_t *)chunk->chunk_hdr,
385 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
387 /* If there are errors need to be reported for unknown parameters,
388 * make sure to reserve enough room in the INIT ACK for them.
392 len = ntohs(err_chunk->chunk_hdr->length) -
393 sizeof(sctp_chunkhdr_t);
395 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
398 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
402 /* If there are errors need to be reported for unknown parameters,
403 * include them in the outgoing INIT ACK as "Unrecognized parameter"
407 /* Get the "Unrecognized parameter" parameter(s) out of the
408 * ERROR chunk generated by sctp_verify_init(). Since the
409 * error cause code for "unknown parameter" and the
410 * "Unrecognized parameter" type is the same, we can
411 * construct the parameters in INIT ACK by copying the
414 unk_param = (sctp_unrecognized_param_t *)
415 ((__u8 *)(err_chunk->chunk_hdr) +
416 sizeof(sctp_chunkhdr_t));
417 /* Replace the cause code with the "Unrecognized parameter"
420 sctp_addto_chunk(repl, len, unk_param);
421 sctp_chunk_free(err_chunk);
424 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
426 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
429 * Note: After sending out INIT ACK with the State Cookie parameter,
430 * "Z" MUST NOT allocate any resources, nor keep any states for the
431 * new association. Otherwise, "Z" will be vulnerable to resource
434 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
436 return SCTP_DISPOSITION_DELETE_TCB;
439 sctp_association_free(new_asoc);
442 sctp_chunk_free(err_chunk);
443 return SCTP_DISPOSITION_NOMEM;
447 * Respond to a normal INIT ACK chunk.
448 * We are the side that is initiating the association.
450 * Section: 5.1 Normal Establishment of an Association, C
451 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
452 * timer and leave COOKIE-WAIT state. "A" shall then send the State
453 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
454 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
456 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
457 * DATA chunks, but it MUST be the first chunk in the packet and
458 * until the COOKIE ACK is returned the sender MUST NOT send any
459 * other packets to the peer.
461 * Verification Tag: 3.3.3
462 * If the value of the Initiate Tag in a received INIT ACK chunk is
463 * found to be 0, the receiver MUST treat it as an error and close the
464 * association by transmitting an ABORT.
467 * (endpoint, asoc, chunk)
470 * (asoc, reply_msg, msg_up, timers, counters)
472 * The return value is the disposition of the chunk.
474 sctp_disposition_t sctp_sf_do_5_1C_ack(const struct sctp_endpoint *ep,
475 const struct sctp_association *asoc,
476 const sctp_subtype_t type,
478 sctp_cmd_seq_t *commands)
480 struct sctp_chunk *chunk = arg;
481 sctp_init_chunk_t *initchunk;
482 struct sctp_chunk *err_chunk;
483 struct sctp_packet *packet;
486 if (!sctp_vtag_verify(chunk, asoc))
487 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
490 * An endpoint MUST NOT bundle INIT, INIT ACK or
491 * SHUTDOWN COMPLETE with any other chunks.
493 if (!chunk->singleton)
494 return sctp_sf_violation_chunk(ep, asoc, type, arg, commands);
496 /* Make sure that the INIT-ACK chunk has a valid length */
497 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_initack_chunk_t)))
498 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
500 /* Grab the INIT header. */
501 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
503 /* Verify the INIT chunk before processing it. */
505 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
506 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
509 /* This chunk contains fatal error. It is to be discarded.
510 * Send an ABORT, with causes if there is any.
513 packet = sctp_abort_pkt_new(ep, asoc, arg,
514 (__u8 *)(err_chunk->chunk_hdr) +
515 sizeof(sctp_chunkhdr_t),
516 ntohs(err_chunk->chunk_hdr->length) -
517 sizeof(sctp_chunkhdr_t));
519 sctp_chunk_free(err_chunk);
522 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
523 SCTP_PACKET(packet));
524 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
525 error = SCTP_ERROR_INV_PARAM;
527 error = SCTP_ERROR_NO_RESOURCE;
530 sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
531 error = SCTP_ERROR_INV_PARAM;
534 /* SCTP-AUTH, Section 6.3:
535 * It should be noted that if the receiver wants to tear
536 * down an association in an authenticated way only, the
537 * handling of malformed packets should not result in
538 * tearing down the association.
540 * This means that if we only want to abort associations
541 * in an authenticated way (i.e AUTH+ABORT), then we
542 * can't destory this association just becuase the packet
545 if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
546 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
548 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
549 return sctp_stop_t1_and_abort(commands, error, ECONNREFUSED,
550 asoc, chunk->transport);
553 /* Tag the variable length parameters. Note that we never
554 * convert the parameters in an INIT chunk.
556 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
558 initchunk = (sctp_init_chunk_t *) chunk->chunk_hdr;
560 sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT,
561 SCTP_PEER_INIT(initchunk));
563 /* Reset init error count upon receipt of INIT-ACK. */
564 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
566 /* 5.1 C) "A" shall stop the T1-init timer and leave
567 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
568 * timer, and enter the COOKIE-ECHOED state.
570 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
571 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
572 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
573 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
574 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
575 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED));
577 /* SCTP-AUTH: genereate the assocition shared keys so that
578 * we can potentially signe the COOKIE-ECHO.
580 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_SHKEY, SCTP_NULL());
582 /* 5.1 C) "A" shall then send the State Cookie received in the
583 * INIT ACK chunk in a COOKIE ECHO chunk, ...
585 /* If there is any errors to report, send the ERROR chunk generated
586 * for unknown parameters as well.
588 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO,
589 SCTP_CHUNK(err_chunk));
591 return SCTP_DISPOSITION_CONSUME;
595 * Respond to a normal COOKIE ECHO chunk.
596 * We are the side that is being asked for an association.
598 * Section: 5.1 Normal Establishment of an Association, D
599 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
600 * with a COOKIE ACK chunk after building a TCB and moving to
601 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
602 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
603 * chunk MUST be the first chunk in the packet.
605 * IMPLEMENTATION NOTE: An implementation may choose to send the
606 * Communication Up notification to the SCTP user upon reception
607 * of a valid COOKIE ECHO chunk.
609 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
610 * D) Rules for packet carrying a COOKIE ECHO
612 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
613 * Initial Tag received in the INIT ACK.
615 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
618 * (endpoint, asoc, chunk)
621 * (asoc, reply_msg, msg_up, timers, counters)
623 * The return value is the disposition of the chunk.
625 sctp_disposition_t sctp_sf_do_5_1D_ce(const struct sctp_endpoint *ep,
626 const struct sctp_association *asoc,
627 const sctp_subtype_t type, void *arg,
628 sctp_cmd_seq_t *commands)
630 struct sctp_chunk *chunk = arg;
631 struct sctp_association *new_asoc;
632 sctp_init_chunk_t *peer_init;
633 struct sctp_chunk *repl;
634 struct sctp_ulpevent *ev, *ai_ev = NULL;
636 struct sctp_chunk *err_chk_p;
639 /* If the packet is an OOTB packet which is temporarily on the
640 * control endpoint, respond with an ABORT.
642 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
643 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
645 /* Make sure that the COOKIE_ECHO chunk has a valid length.
646 * In this case, we check that we have enough for at least a
647 * chunk header. More detailed verification is done
648 * in sctp_unpack_cookie().
650 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
651 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
653 /* If the endpoint is not listening or if the number of associations
654 * on the TCP-style socket exceed the max backlog, respond with an
658 if (!sctp_sstate(sk, LISTENING) ||
659 (sctp_style(sk, TCP) && sk_acceptq_is_full(sk)))
660 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
662 /* "Decode" the chunk. We have no optional parameters so we
665 chunk->subh.cookie_hdr =
666 (struct sctp_signed_cookie *)chunk->skb->data;
667 if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
668 sizeof(sctp_chunkhdr_t)))
671 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
672 * "Z" will reply with a COOKIE ACK chunk after building a TCB
673 * and moving to the ESTABLISHED state.
675 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
679 * If the re-build failed, what is the proper error path
682 * [We should abort the association. --piggy]
685 /* FIXME: Several errors are possible. A bad cookie should
686 * be silently discarded, but think about logging it too.
689 case -SCTP_IERROR_NOMEM:
692 case -SCTP_IERROR_STALE_COOKIE:
693 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
695 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
697 case -SCTP_IERROR_BAD_SIG:
699 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
704 /* Delay state machine commands until later.
706 * Re-build the bind address for the association is done in
707 * the sctp_unpack_cookie() already.
709 /* This is a brand-new association, so these are not yet side
710 * effects--it is safe to run them here.
712 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
714 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
715 &chunk->subh.cookie_hdr->c.peer_addr,
716 peer_init, GFP_ATOMIC))
719 /* SCTP-AUTH: Now that we've populate required fields in
720 * sctp_process_init, set up the assocaition shared keys as
721 * necessary so that we can potentially authenticate the ACK
723 error = sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC);
727 /* SCTP-AUTH: auth_chunk pointer is only set when the cookie-echo
728 * is supposed to be authenticated and we have to do delayed
729 * authentication. We've just recreated the association using
730 * the information in the cookie and now it's much easier to
731 * do the authentication.
733 if (chunk->auth_chunk) {
734 struct sctp_chunk auth;
737 /* set-up our fake chunk so that we can process it */
738 auth.skb = chunk->auth_chunk;
739 auth.asoc = chunk->asoc;
740 auth.sctp_hdr = chunk->sctp_hdr;
741 auth.chunk_hdr = (sctp_chunkhdr_t *)skb_push(chunk->auth_chunk,
742 sizeof(sctp_chunkhdr_t));
743 skb_pull(chunk->auth_chunk, sizeof(sctp_chunkhdr_t));
744 auth.transport = chunk->transport;
746 ret = sctp_sf_authenticate(ep, new_asoc, type, &auth);
748 /* We can now safely free the auth_chunk clone */
749 kfree_skb(chunk->auth_chunk);
751 if (ret != SCTP_IERROR_NO_ERROR) {
752 sctp_association_free(new_asoc);
753 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
757 repl = sctp_make_cookie_ack(new_asoc, chunk);
761 /* RFC 2960 5.1 Normal Establishment of an Association
763 * D) IMPLEMENTATION NOTE: An implementation may choose to
764 * send the Communication Up notification to the SCTP user
765 * upon reception of a valid COOKIE ECHO chunk.
767 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0,
768 new_asoc->c.sinit_num_ostreams,
769 new_asoc->c.sinit_max_instreams,
774 /* Sockets API Draft Section 5.3.1.6
775 * When a peer sends a Adaptation Layer Indication parameter , SCTP
776 * delivers this notification to inform the application that of the
777 * peers requested adaptation layer.
779 if (new_asoc->peer.adaptation_ind) {
780 ai_ev = sctp_ulpevent_make_adaptation_indication(new_asoc,
786 /* Add all the state machine commands now since we've created
787 * everything. This way we don't introduce memory corruptions
788 * during side-effect processing and correclty count established
791 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
792 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
793 SCTP_STATE(SCTP_STATE_ESTABLISHED));
794 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
795 SCTP_INC_STATS(SCTP_MIB_PASSIVEESTABS);
796 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
798 if (new_asoc->autoclose)
799 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
800 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
802 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
804 /* This will send the COOKIE ACK */
805 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
807 /* Queue the ASSOC_CHANGE event */
808 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
810 /* Send up the Adaptation Layer Indication event */
812 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
813 SCTP_ULPEVENT(ai_ev));
815 return SCTP_DISPOSITION_CONSUME;
818 sctp_ulpevent_free(ev);
820 sctp_chunk_free(repl);
822 sctp_association_free(new_asoc);
824 return SCTP_DISPOSITION_NOMEM;
828 * Respond to a normal COOKIE ACK chunk.
829 * We are the side that is being asked for an association.
831 * RFC 2960 5.1 Normal Establishment of an Association
833 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
834 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
835 * timer. It may also notify its ULP about the successful
836 * establishment of the association with a Communication Up
837 * notification (see Section 10).
841 * (endpoint, asoc, chunk)
844 * (asoc, reply_msg, msg_up, timers, counters)
846 * The return value is the disposition of the chunk.
848 sctp_disposition_t sctp_sf_do_5_1E_ca(const struct sctp_endpoint *ep,
849 const struct sctp_association *asoc,
850 const sctp_subtype_t type, void *arg,
851 sctp_cmd_seq_t *commands)
853 struct sctp_chunk *chunk = arg;
854 struct sctp_ulpevent *ev;
856 if (!sctp_vtag_verify(chunk, asoc))
857 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
859 /* Verify that the chunk length for the COOKIE-ACK is OK.
860 * If we don't do this, any bundled chunks may be junked.
862 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
863 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
866 /* Reset init error count upon receipt of COOKIE-ACK,
867 * to avoid problems with the managemement of this
868 * counter in stale cookie situations when a transition back
869 * from the COOKIE-ECHOED state to the COOKIE-WAIT
870 * state is performed.
872 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
874 /* RFC 2960 5.1 Normal Establishment of an Association
876 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
877 * from the COOKIE-ECHOED state to the ESTABLISHED state,
878 * stopping the T1-cookie timer.
880 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
881 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
882 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
883 SCTP_STATE(SCTP_STATE_ESTABLISHED));
884 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
885 SCTP_INC_STATS(SCTP_MIB_ACTIVEESTABS);
886 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
888 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
889 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
890 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
892 /* It may also notify its ULP about the successful
893 * establishment of the association with a Communication Up
894 * notification (see Section 10).
896 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP,
897 0, asoc->c.sinit_num_ostreams,
898 asoc->c.sinit_max_instreams,
904 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
906 /* Sockets API Draft Section 5.3.1.6
907 * When a peer sends a Adaptation Layer Indication parameter , SCTP
908 * delivers this notification to inform the application that of the
909 * peers requested adaptation layer.
911 if (asoc->peer.adaptation_ind) {
912 ev = sctp_ulpevent_make_adaptation_indication(asoc, GFP_ATOMIC);
916 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
920 return SCTP_DISPOSITION_CONSUME;
922 return SCTP_DISPOSITION_NOMEM;
925 /* Generate and sendout a heartbeat packet. */
926 static sctp_disposition_t sctp_sf_heartbeat(const struct sctp_endpoint *ep,
927 const struct sctp_association *asoc,
928 const sctp_subtype_t type,
930 sctp_cmd_seq_t *commands)
932 struct sctp_transport *transport = (struct sctp_transport *) arg;
933 struct sctp_chunk *reply;
934 sctp_sender_hb_info_t hbinfo;
937 hbinfo.param_hdr.type = SCTP_PARAM_HEARTBEAT_INFO;
938 hbinfo.param_hdr.length = htons(sizeof(sctp_sender_hb_info_t));
939 hbinfo.daddr = transport->ipaddr;
940 hbinfo.sent_at = jiffies;
941 hbinfo.hb_nonce = transport->hb_nonce;
943 /* Send a heartbeat to our peer. */
944 paylen = sizeof(sctp_sender_hb_info_t);
945 reply = sctp_make_heartbeat(asoc, transport, &hbinfo, paylen);
947 return SCTP_DISPOSITION_NOMEM;
949 /* Set rto_pending indicating that an RTT measurement
950 * is started with this heartbeat chunk.
952 sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING,
953 SCTP_TRANSPORT(transport));
955 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
956 return SCTP_DISPOSITION_CONSUME;
959 /* Generate a HEARTBEAT packet on the given transport. */
960 sctp_disposition_t sctp_sf_sendbeat_8_3(const struct sctp_endpoint *ep,
961 const struct sctp_association *asoc,
962 const sctp_subtype_t type,
964 sctp_cmd_seq_t *commands)
966 struct sctp_transport *transport = (struct sctp_transport *) arg;
968 if (asoc->overall_error_count > asoc->max_retrans) {
969 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
970 SCTP_ERROR(ETIMEDOUT));
971 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
972 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
973 SCTP_PERR(SCTP_ERROR_NO_ERROR));
974 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
975 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
976 return SCTP_DISPOSITION_DELETE_TCB;
980 * The Sender-specific Heartbeat Info field should normally include
981 * information about the sender's current time when this HEARTBEAT
982 * chunk is sent and the destination transport address to which this
983 * HEARTBEAT is sent (see Section 8.3).
986 if (transport->param_flags & SPP_HB_ENABLE) {
987 if (SCTP_DISPOSITION_NOMEM ==
988 sctp_sf_heartbeat(ep, asoc, type, arg,
990 return SCTP_DISPOSITION_NOMEM;
991 /* Set transport error counter and association error counter
992 * when sending heartbeat.
994 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET,
995 SCTP_TRANSPORT(transport));
997 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE,
998 SCTP_TRANSPORT(transport));
1000 return SCTP_DISPOSITION_CONSUME;
1004 * Process an heartbeat request.
1006 * Section: 8.3 Path Heartbeat
1007 * The receiver of the HEARTBEAT should immediately respond with a
1008 * HEARTBEAT ACK that contains the Heartbeat Information field copied
1009 * from the received HEARTBEAT chunk.
1011 * Verification Tag: 8.5 Verification Tag [Normal verification]
1012 * When receiving an SCTP packet, the endpoint MUST ensure that the
1013 * value in the Verification Tag field of the received SCTP packet
1014 * matches its own Tag. If the received Verification Tag value does not
1015 * match the receiver's own tag value, the receiver shall silently
1016 * discard the packet and shall not process it any further except for
1017 * those cases listed in Section 8.5.1 below.
1020 * (endpoint, asoc, chunk)
1023 * (asoc, reply_msg, msg_up, timers, counters)
1025 * The return value is the disposition of the chunk.
1027 sctp_disposition_t sctp_sf_beat_8_3(const struct sctp_endpoint *ep,
1028 const struct sctp_association *asoc,
1029 const sctp_subtype_t type,
1031 sctp_cmd_seq_t *commands)
1033 struct sctp_chunk *chunk = arg;
1034 struct sctp_chunk *reply;
1037 if (!sctp_vtag_verify(chunk, asoc))
1038 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1040 /* Make sure that the HEARTBEAT chunk has a valid length. */
1041 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t)))
1042 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1045 /* 8.3 The receiver of the HEARTBEAT should immediately
1046 * respond with a HEARTBEAT ACK that contains the Heartbeat
1047 * Information field copied from the received HEARTBEAT chunk.
1049 chunk->subh.hb_hdr = (sctp_heartbeathdr_t *) chunk->skb->data;
1050 paylen = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t);
1051 if (!pskb_pull(chunk->skb, paylen))
1054 reply = sctp_make_heartbeat_ack(asoc, chunk,
1055 chunk->subh.hb_hdr, paylen);
1059 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
1060 return SCTP_DISPOSITION_CONSUME;
1063 return SCTP_DISPOSITION_NOMEM;
1067 * Process the returning HEARTBEAT ACK.
1069 * Section: 8.3 Path Heartbeat
1070 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
1071 * should clear the error counter of the destination transport
1072 * address to which the HEARTBEAT was sent, and mark the destination
1073 * transport address as active if it is not so marked. The endpoint may
1074 * optionally report to the upper layer when an inactive destination
1075 * address is marked as active due to the reception of the latest
1076 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
1077 * clear the association overall error count as well (as defined
1080 * The receiver of the HEARTBEAT ACK should also perform an RTT
1081 * measurement for that destination transport address using the time
1082 * value carried in the HEARTBEAT ACK chunk.
1084 * Verification Tag: 8.5 Verification Tag [Normal verification]
1087 * (endpoint, asoc, chunk)
1090 * (asoc, reply_msg, msg_up, timers, counters)
1092 * The return value is the disposition of the chunk.
1094 sctp_disposition_t sctp_sf_backbeat_8_3(const struct sctp_endpoint *ep,
1095 const struct sctp_association *asoc,
1096 const sctp_subtype_t type,
1098 sctp_cmd_seq_t *commands)
1100 struct sctp_chunk *chunk = arg;
1101 union sctp_addr from_addr;
1102 struct sctp_transport *link;
1103 sctp_sender_hb_info_t *hbinfo;
1104 unsigned long max_interval;
1106 if (!sctp_vtag_verify(chunk, asoc))
1107 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1109 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1110 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t)))
1111 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1114 hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data;
1115 /* Make sure that the length of the parameter is what we expect */
1116 if (ntohs(hbinfo->param_hdr.length) !=
1117 sizeof(sctp_sender_hb_info_t)) {
1118 return SCTP_DISPOSITION_DISCARD;
1121 from_addr = hbinfo->daddr;
1122 link = sctp_assoc_lookup_paddr(asoc, &from_addr);
1124 /* This should never happen, but lets log it if so. */
1125 if (unlikely(!link)) {
1126 if (from_addr.sa.sa_family == AF_INET6) {
1127 if (net_ratelimit())
1129 "%s association %p could not find address "
1133 NIP6(from_addr.v6.sin6_addr));
1135 if (net_ratelimit())
1137 "%s association %p could not find address "
1141 NIPQUAD(from_addr.v4.sin_addr.s_addr));
1143 return SCTP_DISPOSITION_DISCARD;
1146 /* Validate the 64-bit random nonce. */
1147 if (hbinfo->hb_nonce != link->hb_nonce)
1148 return SCTP_DISPOSITION_DISCARD;
1150 max_interval = link->hbinterval + link->rto;
1152 /* Check if the timestamp looks valid. */
1153 if (time_after(hbinfo->sent_at, jiffies) ||
1154 time_after(jiffies, hbinfo->sent_at + max_interval)) {
1155 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp "
1156 "received for transport: %p\n",
1157 __FUNCTION__, link);
1158 return SCTP_DISPOSITION_DISCARD;
1161 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1162 * the HEARTBEAT should clear the error counter of the
1163 * destination transport address to which the HEARTBEAT was
1164 * sent and mark the destination transport address as active if
1165 * it is not so marked.
1167 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link));
1169 return SCTP_DISPOSITION_CONSUME;
1172 /* Helper function to send out an abort for the restart
1175 static int sctp_sf_send_restart_abort(union sctp_addr *ssa,
1176 struct sctp_chunk *init,
1177 sctp_cmd_seq_t *commands)
1180 struct sctp_packet *pkt;
1181 union sctp_addr_param *addrparm;
1182 struct sctp_errhdr *errhdr;
1183 struct sctp_endpoint *ep;
1184 char buffer[sizeof(struct sctp_errhdr)+sizeof(union sctp_addr_param)];
1185 struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family);
1187 /* Build the error on the stack. We are way to malloc crazy
1188 * throughout the code today.
1190 errhdr = (struct sctp_errhdr *)buffer;
1191 addrparm = (union sctp_addr_param *)errhdr->variable;
1193 /* Copy into a parm format. */
1194 len = af->to_addr_param(ssa, addrparm);
1195 len += sizeof(sctp_errhdr_t);
1197 errhdr->cause = SCTP_ERROR_RESTART;
1198 errhdr->length = htons(len);
1200 /* Assign to the control socket. */
1201 ep = sctp_sk((sctp_get_ctl_sock()))->ep;
1203 /* Association is NULL since this may be a restart attack and we
1204 * want to send back the attacker's vtag.
1206 pkt = sctp_abort_pkt_new(ep, NULL, init, errhdr, len);
1210 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt));
1212 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1214 /* Discard the rest of the inbound packet. */
1215 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
1218 /* Even if there is no memory, treat as a failure so
1219 * the packet will get dropped.
1224 /* A restart is occurring, check to make sure no new addresses
1225 * are being added as we may be under a takeover attack.
1227 static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc,
1228 const struct sctp_association *asoc,
1229 struct sctp_chunk *init,
1230 sctp_cmd_seq_t *commands)
1232 struct sctp_transport *new_addr, *addr;
1233 struct list_head *pos, *pos2;
1236 /* Implementor's Guide - Sectin 5.2.2
1238 * Before responding the endpoint MUST check to see if the
1239 * unexpected INIT adds new addresses to the association. If new
1240 * addresses are added to the association, the endpoint MUST respond
1244 /* Search through all current addresses and make sure
1245 * we aren't adding any new ones.
1250 list_for_each(pos, &new_asoc->peer.transport_addr_list) {
1251 new_addr = list_entry(pos, struct sctp_transport, transports);
1253 list_for_each(pos2, &asoc->peer.transport_addr_list) {
1254 addr = list_entry(pos2, struct sctp_transport,
1256 if (sctp_cmp_addr_exact(&new_addr->ipaddr,
1266 /* If a new address was added, ABORT the sender. */
1267 if (!found && new_addr) {
1268 sctp_sf_send_restart_abort(&new_addr->ipaddr, init, commands);
1271 /* Return success if all addresses were found. */
1275 /* Populate the verification/tie tags based on overlapping INIT
1278 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1280 static void sctp_tietags_populate(struct sctp_association *new_asoc,
1281 const struct sctp_association *asoc)
1283 switch (asoc->state) {
1285 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1287 case SCTP_STATE_COOKIE_WAIT:
1288 new_asoc->c.my_vtag = asoc->c.my_vtag;
1289 new_asoc->c.my_ttag = asoc->c.my_vtag;
1290 new_asoc->c.peer_ttag = 0;
1293 case SCTP_STATE_COOKIE_ECHOED:
1294 new_asoc->c.my_vtag = asoc->c.my_vtag;
1295 new_asoc->c.my_ttag = asoc->c.my_vtag;
1296 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1299 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1300 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1303 new_asoc->c.my_ttag = asoc->c.my_vtag;
1304 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1308 /* Other parameters for the endpoint SHOULD be copied from the
1309 * existing parameters of the association (e.g. number of
1310 * outbound streams) into the INIT ACK and cookie.
1312 new_asoc->rwnd = asoc->rwnd;
1313 new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams;
1314 new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams;
1315 new_asoc->c.initial_tsn = asoc->c.initial_tsn;
1319 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1322 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1324 * Returns value representing action to be taken. These action values
1325 * correspond to Action/Description values in RFC 2960, Table 2.
1327 static char sctp_tietags_compare(struct sctp_association *new_asoc,
1328 const struct sctp_association *asoc)
1330 /* In this case, the peer may have restarted. */
1331 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1332 (asoc->c.peer_vtag != new_asoc->c.peer_vtag) &&
1333 (asoc->c.my_vtag == new_asoc->c.my_ttag) &&
1334 (asoc->c.peer_vtag == new_asoc->c.peer_ttag))
1337 /* Collision case B. */
1338 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1339 ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) ||
1340 (0 == asoc->c.peer_vtag))) {
1344 /* Collision case D. */
1345 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1346 (asoc->c.peer_vtag == new_asoc->c.peer_vtag))
1349 /* Collision case C. */
1350 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1351 (asoc->c.peer_vtag == new_asoc->c.peer_vtag) &&
1352 (0 == new_asoc->c.my_ttag) &&
1353 (0 == new_asoc->c.peer_ttag))
1356 /* No match to any of the special cases; discard this packet. */
1360 /* Common helper routine for both duplicate and simulataneous INIT
1363 static sctp_disposition_t sctp_sf_do_unexpected_init(
1364 const struct sctp_endpoint *ep,
1365 const struct sctp_association *asoc,
1366 const sctp_subtype_t type,
1367 void *arg, sctp_cmd_seq_t *commands)
1369 sctp_disposition_t retval;
1370 struct sctp_chunk *chunk = arg;
1371 struct sctp_chunk *repl;
1372 struct sctp_association *new_asoc;
1373 struct sctp_chunk *err_chunk;
1374 struct sctp_packet *packet;
1375 sctp_unrecognized_param_t *unk_param;
1379 * An endpoint MUST NOT bundle INIT, INIT ACK or
1380 * SHUTDOWN COMPLETE with any other chunks.
1383 * Furthermore, we require that the receiver of an INIT chunk MUST
1384 * enforce these rules by silently discarding an arriving packet
1385 * with an INIT chunk that is bundled with other chunks.
1387 if (!chunk->singleton)
1388 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1390 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1393 if (chunk->sctp_hdr->vtag != 0)
1394 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
1396 /* Make sure that the INIT chunk has a valid length.
1397 * In this case, we generate a protocol violation since we have
1398 * an association established.
1400 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
1401 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1403 /* Grab the INIT header. */
1404 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
1406 /* Tag the variable length parameters. */
1407 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
1409 /* Verify the INIT chunk before processing it. */
1411 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
1412 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
1414 /* This chunk contains fatal error. It is to be discarded.
1415 * Send an ABORT, with causes if there is any.
1418 packet = sctp_abort_pkt_new(ep, asoc, arg,
1419 (__u8 *)(err_chunk->chunk_hdr) +
1420 sizeof(sctp_chunkhdr_t),
1421 ntohs(err_chunk->chunk_hdr->length) -
1422 sizeof(sctp_chunkhdr_t));
1425 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
1426 SCTP_PACKET(packet));
1427 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1428 retval = SCTP_DISPOSITION_CONSUME;
1430 retval = SCTP_DISPOSITION_NOMEM;
1434 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
1440 * Other parameters for the endpoint SHOULD be copied from the
1441 * existing parameters of the association (e.g. number of
1442 * outbound streams) into the INIT ACK and cookie.
1443 * FIXME: We are copying parameters from the endpoint not the
1446 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
1450 /* In the outbound INIT ACK the endpoint MUST copy its current
1451 * Verification Tag and Peers Verification tag into a reserved
1452 * place (local tie-tag and per tie-tag) within the state cookie.
1454 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1456 (sctp_init_chunk_t *)chunk->chunk_hdr,
1460 /* Make sure no new addresses are being added during the
1461 * restart. Do not do this check for COOKIE-WAIT state,
1462 * since there are no peer addresses to check against.
1463 * Upon return an ABORT will have been sent if needed.
1465 if (!sctp_state(asoc, COOKIE_WAIT)) {
1466 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
1468 retval = SCTP_DISPOSITION_CONSUME;
1473 sctp_tietags_populate(new_asoc, asoc);
1475 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1477 /* If there are errors need to be reported for unknown parameters,
1478 * make sure to reserve enough room in the INIT ACK for them.
1482 len = ntohs(err_chunk->chunk_hdr->length) -
1483 sizeof(sctp_chunkhdr_t);
1486 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
1489 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
1493 /* If there are errors need to be reported for unknown parameters,
1494 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1498 /* Get the "Unrecognized parameter" parameter(s) out of the
1499 * ERROR chunk generated by sctp_verify_init(). Since the
1500 * error cause code for "unknown parameter" and the
1501 * "Unrecognized parameter" type is the same, we can
1502 * construct the parameters in INIT ACK by copying the
1503 * ERROR causes over.
1505 unk_param = (sctp_unrecognized_param_t *)
1506 ((__u8 *)(err_chunk->chunk_hdr) +
1507 sizeof(sctp_chunkhdr_t));
1508 /* Replace the cause code with the "Unrecognized parameter"
1511 sctp_addto_chunk(repl, len, unk_param);
1514 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1515 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1518 * Note: After sending out INIT ACK with the State Cookie parameter,
1519 * "Z" MUST NOT allocate any resources for this new association.
1520 * Otherwise, "Z" will be vulnerable to resource attacks.
1522 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1523 retval = SCTP_DISPOSITION_CONSUME;
1528 retval = SCTP_DISPOSITION_NOMEM;
1531 sctp_association_free(new_asoc);
1534 sctp_chunk_free(err_chunk);
1539 * Handle simultanous INIT.
1540 * This means we started an INIT and then we got an INIT request from
1543 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1544 * This usually indicates an initialization collision, i.e., each
1545 * endpoint is attempting, at about the same time, to establish an
1546 * association with the other endpoint.
1548 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1549 * endpoint MUST respond with an INIT ACK using the same parameters it
1550 * sent in its original INIT chunk (including its Verification Tag,
1551 * unchanged). These original parameters are combined with those from the
1552 * newly received INIT chunk. The endpoint shall also generate a State
1553 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1554 * INIT to calculate the State Cookie.
1556 * After that, the endpoint MUST NOT change its state, the T1-init
1557 * timer shall be left running and the corresponding TCB MUST NOT be
1558 * destroyed. The normal procedures for handling State Cookies when
1559 * a TCB exists will resolve the duplicate INITs to a single association.
1561 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1562 * its Tie-Tags with the Tag information of itself and its peer (see
1563 * section 5.2.2 for a description of the Tie-Tags).
1565 * Verification Tag: Not explicit, but an INIT can not have a valid
1566 * verification tag, so we skip the check.
1569 * (endpoint, asoc, chunk)
1572 * (asoc, reply_msg, msg_up, timers, counters)
1574 * The return value is the disposition of the chunk.
1576 sctp_disposition_t sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint *ep,
1577 const struct sctp_association *asoc,
1578 const sctp_subtype_t type,
1580 sctp_cmd_seq_t *commands)
1582 /* Call helper to do the real work for both simulataneous and
1583 * duplicate INIT chunk handling.
1585 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1589 * Handle duplicated INIT messages. These are usually delayed
1592 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1593 * COOKIE-ECHOED and COOKIE-WAIT
1595 * Unless otherwise stated, upon reception of an unexpected INIT for
1596 * this association, the endpoint shall generate an INIT ACK with a
1597 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1598 * current Verification Tag and peer's Verification Tag into a reserved
1599 * place within the state cookie. We shall refer to these locations as
1600 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1601 * containing this INIT ACK MUST carry a Verification Tag value equal to
1602 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1603 * MUST contain a new Initiation Tag (randomly generated see Section
1604 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1605 * existing parameters of the association (e.g. number of outbound
1606 * streams) into the INIT ACK and cookie.
1608 * After sending out the INIT ACK, the endpoint shall take no further
1609 * actions, i.e., the existing association, including its current state,
1610 * and the corresponding TCB MUST NOT be changed.
1612 * Note: Only when a TCB exists and the association is not in a COOKIE-
1613 * WAIT state are the Tie-Tags populated. For a normal association INIT
1614 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1615 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1616 * State Cookie are populated as specified in section 5.2.1.
1618 * Verification Tag: Not specified, but an INIT has no way of knowing
1619 * what the verification tag could be, so we ignore it.
1622 * (endpoint, asoc, chunk)
1625 * (asoc, reply_msg, msg_up, timers, counters)
1627 * The return value is the disposition of the chunk.
1629 sctp_disposition_t sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint *ep,
1630 const struct sctp_association *asoc,
1631 const sctp_subtype_t type,
1633 sctp_cmd_seq_t *commands)
1635 /* Call helper to do the real work for both simulataneous and
1636 * duplicate INIT chunk handling.
1638 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1643 * Unexpected INIT-ACK handler.
1646 * If an INIT ACK received by an endpoint in any state other than the
1647 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1648 * An unexpected INIT ACK usually indicates the processing of an old or
1649 * duplicated INIT chunk.
1651 sctp_disposition_t sctp_sf_do_5_2_3_initack(const struct sctp_endpoint *ep,
1652 const struct sctp_association *asoc,
1653 const sctp_subtype_t type,
1654 void *arg, sctp_cmd_seq_t *commands)
1656 /* Per the above section, we'll discard the chunk if we have an
1657 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1659 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
1660 return sctp_sf_ootb(ep, asoc, type, arg, commands);
1662 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
1665 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1668 * A) In this case, the peer may have restarted.
1670 static sctp_disposition_t sctp_sf_do_dupcook_a(const struct sctp_endpoint *ep,
1671 const struct sctp_association *asoc,
1672 struct sctp_chunk *chunk,
1673 sctp_cmd_seq_t *commands,
1674 struct sctp_association *new_asoc)
1676 sctp_init_chunk_t *peer_init;
1677 struct sctp_ulpevent *ev;
1678 struct sctp_chunk *repl;
1679 struct sctp_chunk *err;
1680 sctp_disposition_t disposition;
1682 /* new_asoc is a brand-new association, so these are not yet
1683 * side effects--it is safe to run them here.
1685 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1687 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1688 sctp_source(chunk), peer_init,
1692 /* Make sure no new addresses are being added during the
1693 * restart. Though this is a pretty complicated attack
1694 * since you'd have to get inside the cookie.
1696 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) {
1697 return SCTP_DISPOSITION_CONSUME;
1700 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1701 * the peer has restarted (Action A), it MUST NOT setup a new
1702 * association but instead resend the SHUTDOWN ACK and send an ERROR
1703 * chunk with a "Cookie Received while Shutting Down" error cause to
1706 if (sctp_state(asoc, SHUTDOWN_ACK_SENT)) {
1707 disposition = sctp_sf_do_9_2_reshutack(ep, asoc,
1708 SCTP_ST_CHUNK(chunk->chunk_hdr->type),
1710 if (SCTP_DISPOSITION_NOMEM == disposition)
1713 err = sctp_make_op_error(asoc, chunk,
1714 SCTP_ERROR_COOKIE_IN_SHUTDOWN,
1717 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1720 return SCTP_DISPOSITION_CONSUME;
1723 /* For now, fail any unsent/unacked data. Consider the optional
1724 * choice of resending of this data.
1726 sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL());
1728 repl = sctp_make_cookie_ack(new_asoc, chunk);
1732 /* Report association restart to upper layer. */
1733 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0,
1734 new_asoc->c.sinit_num_ostreams,
1735 new_asoc->c.sinit_max_instreams,
1740 /* Update the content of current association. */
1741 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1742 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1743 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1744 return SCTP_DISPOSITION_CONSUME;
1747 sctp_chunk_free(repl);
1749 return SCTP_DISPOSITION_NOMEM;
1752 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1755 * B) In this case, both sides may be attempting to start an association
1756 * at about the same time but the peer endpoint started its INIT
1757 * after responding to the local endpoint's INIT
1759 /* This case represents an initialization collision. */
1760 static sctp_disposition_t sctp_sf_do_dupcook_b(const struct sctp_endpoint *ep,
1761 const struct sctp_association *asoc,
1762 struct sctp_chunk *chunk,
1763 sctp_cmd_seq_t *commands,
1764 struct sctp_association *new_asoc)
1766 sctp_init_chunk_t *peer_init;
1767 struct sctp_chunk *repl;
1769 /* new_asoc is a brand-new association, so these are not yet
1770 * side effects--it is safe to run them here.
1772 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1773 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1774 sctp_source(chunk), peer_init,
1778 /* Update the content of current association. */
1779 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1780 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1781 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1782 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
1783 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
1785 repl = sctp_make_cookie_ack(new_asoc, chunk);
1789 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1790 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1792 /* RFC 2960 5.1 Normal Establishment of an Association
1794 * D) IMPLEMENTATION NOTE: An implementation may choose to
1795 * send the Communication Up notification to the SCTP user
1796 * upon reception of a valid COOKIE ECHO chunk.
1798 * Sadly, this needs to be implemented as a side-effect, because
1799 * we are not guaranteed to have set the association id of the real
1800 * association and so these notifications need to be delayed until
1801 * the association id is allocated.
1804 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_CHANGE, SCTP_U8(SCTP_COMM_UP));
1806 /* Sockets API Draft Section 5.3.1.6
1807 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1808 * delivers this notification to inform the application that of the
1809 * peers requested adaptation layer.
1811 * This also needs to be done as a side effect for the same reason as
1814 if (asoc->peer.adaptation_ind)
1815 sctp_add_cmd_sf(commands, SCTP_CMD_ADAPTATION_IND, SCTP_NULL());
1817 return SCTP_DISPOSITION_CONSUME;
1820 return SCTP_DISPOSITION_NOMEM;
1823 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1826 * C) In this case, the local endpoint's cookie has arrived late.
1827 * Before it arrived, the local endpoint sent an INIT and received an
1828 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1829 * but a new tag of its own.
1831 /* This case represents an initialization collision. */
1832 static sctp_disposition_t sctp_sf_do_dupcook_c(const struct sctp_endpoint *ep,
1833 const struct sctp_association *asoc,
1834 struct sctp_chunk *chunk,
1835 sctp_cmd_seq_t *commands,
1836 struct sctp_association *new_asoc)
1838 /* The cookie should be silently discarded.
1839 * The endpoint SHOULD NOT change states and should leave
1840 * any timers running.
1842 return SCTP_DISPOSITION_DISCARD;
1845 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1849 * D) When both local and remote tags match the endpoint should always
1850 * enter the ESTABLISHED state, if it has not already done so.
1852 /* This case represents an initialization collision. */
1853 static sctp_disposition_t sctp_sf_do_dupcook_d(const struct sctp_endpoint *ep,
1854 const struct sctp_association *asoc,
1855 struct sctp_chunk *chunk,
1856 sctp_cmd_seq_t *commands,
1857 struct sctp_association *new_asoc)
1859 struct sctp_ulpevent *ev = NULL, *ai_ev = NULL;
1860 struct sctp_chunk *repl;
1862 /* Clarification from Implementor's Guide:
1863 * D) When both local and remote tags match the endpoint should
1864 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1865 * It should stop any cookie timer that may be running and send
1869 /* Don't accidentally move back into established state. */
1870 if (asoc->state < SCTP_STATE_ESTABLISHED) {
1871 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1872 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
1873 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1874 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1875 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
1876 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START,
1879 /* RFC 2960 5.1 Normal Establishment of an Association
1881 * D) IMPLEMENTATION NOTE: An implementation may choose
1882 * to send the Communication Up notification to the
1883 * SCTP user upon reception of a valid COOKIE
1886 ev = sctp_ulpevent_make_assoc_change(asoc, 0,
1888 asoc->c.sinit_num_ostreams,
1889 asoc->c.sinit_max_instreams,
1894 /* Sockets API Draft Section 5.3.1.6
1895 * When a peer sends a Adaptation Layer Indication parameter,
1896 * SCTP delivers this notification to inform the application
1897 * that of the peers requested adaptation layer.
1899 if (asoc->peer.adaptation_ind) {
1900 ai_ev = sctp_ulpevent_make_adaptation_indication(asoc,
1907 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1909 repl = sctp_make_cookie_ack(new_asoc, chunk);
1914 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1917 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1918 SCTP_ULPEVENT(ai_ev));
1920 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1921 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1923 return SCTP_DISPOSITION_CONSUME;
1927 sctp_ulpevent_free(ai_ev);
1929 sctp_ulpevent_free(ev);
1930 return SCTP_DISPOSITION_NOMEM;
1934 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1935 * chunk was retransmitted and then delayed in the network.
1937 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1939 * Verification Tag: None. Do cookie validation.
1942 * (endpoint, asoc, chunk)
1945 * (asoc, reply_msg, msg_up, timers, counters)
1947 * The return value is the disposition of the chunk.
1949 sctp_disposition_t sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint *ep,
1950 const struct sctp_association *asoc,
1951 const sctp_subtype_t type,
1953 sctp_cmd_seq_t *commands)
1955 sctp_disposition_t retval;
1956 struct sctp_chunk *chunk = arg;
1957 struct sctp_association *new_asoc;
1960 struct sctp_chunk *err_chk_p;
1962 /* Make sure that the chunk has a valid length from the protocol
1963 * perspective. In this case check to make sure we have at least
1964 * enough for the chunk header. Cookie length verification is
1967 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
1968 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1971 /* "Decode" the chunk. We have no optional parameters so we
1972 * are in good shape.
1974 chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data;
1975 if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
1976 sizeof(sctp_chunkhdr_t)))
1979 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
1980 * of a duplicate COOKIE ECHO match the Verification Tags of the
1981 * current association, consider the State Cookie valid even if
1982 * the lifespan is exceeded.
1984 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
1988 * If the re-build failed, what is the proper error path
1991 * [We should abort the association. --piggy]
1994 /* FIXME: Several errors are possible. A bad cookie should
1995 * be silently discarded, but think about logging it too.
1998 case -SCTP_IERROR_NOMEM:
2001 case -SCTP_IERROR_STALE_COOKIE:
2002 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
2004 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2005 case -SCTP_IERROR_BAD_SIG:
2007 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2011 /* Compare the tie_tag in cookie with the verification tag of
2012 * current association.
2014 action = sctp_tietags_compare(new_asoc, asoc);
2017 case 'A': /* Association restart. */
2018 retval = sctp_sf_do_dupcook_a(ep, asoc, chunk, commands,
2022 case 'B': /* Collision case B. */
2023 retval = sctp_sf_do_dupcook_b(ep, asoc, chunk, commands,
2027 case 'C': /* Collision case C. */
2028 retval = sctp_sf_do_dupcook_c(ep, asoc, chunk, commands,
2032 case 'D': /* Collision case D. */
2033 retval = sctp_sf_do_dupcook_d(ep, asoc, chunk, commands,
2037 default: /* Discard packet for all others. */
2038 retval = sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2042 /* Delete the tempory new association. */
2043 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
2044 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
2049 return SCTP_DISPOSITION_NOMEM;
2053 * Process an ABORT. (SHUTDOWN-PENDING state)
2055 * See sctp_sf_do_9_1_abort().
2057 sctp_disposition_t sctp_sf_shutdown_pending_abort(
2058 const struct sctp_endpoint *ep,
2059 const struct sctp_association *asoc,
2060 const sctp_subtype_t type,
2062 sctp_cmd_seq_t *commands)
2064 struct sctp_chunk *chunk = arg;
2066 if (!sctp_vtag_verify_either(chunk, asoc))
2067 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2069 /* Make sure that the ABORT chunk has a valid length.
2070 * Since this is an ABORT chunk, we have to discard it
2071 * because of the following text:
2072 * RFC 2960, Section 3.3.7
2073 * If an endpoint receives an ABORT with a format error or for an
2074 * association that doesn't exist, it MUST silently discard it.
2075 * Becasue the length is "invalid", we can't really discard just
2076 * as we do not know its true length. So, to be safe, discard the
2079 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2080 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2082 /* ADD-IP: Special case for ABORT chunks
2083 * F4) One special consideration is that ABORT Chunks arriving
2084 * destined to the IP address being deleted MUST be
2085 * ignored (see Section 5.3.1 for further details).
2087 if (SCTP_ADDR_DEL ==
2088 sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
2089 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
2091 /* Stop the T5-shutdown guard timer. */
2092 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2093 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
2095 return __sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
2099 * Process an ABORT. (SHUTDOWN-SENT state)
2101 * See sctp_sf_do_9_1_abort().
2103 sctp_disposition_t sctp_sf_shutdown_sent_abort(const struct sctp_endpoint *ep,
2104 const struct sctp_association *asoc,
2105 const sctp_subtype_t type,
2107 sctp_cmd_seq_t *commands)
2109 struct sctp_chunk *chunk = arg;
2111 if (!sctp_vtag_verify_either(chunk, asoc))
2112 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2114 /* Make sure that the ABORT chunk has a valid length.
2115 * Since this is an ABORT chunk, we have to discard it
2116 * because of the following text:
2117 * RFC 2960, Section 3.3.7
2118 * If an endpoint receives an ABORT with a format error or for an
2119 * association that doesn't exist, it MUST silently discard it.
2120 * Becasue the length is "invalid", we can't really discard just
2121 * as we do not know its true length. So, to be safe, discard the
2124 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2125 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2127 /* ADD-IP: Special case for ABORT chunks
2128 * F4) One special consideration is that ABORT Chunks arriving
2129 * destined to the IP address being deleted MUST be
2130 * ignored (see Section 5.3.1 for further details).
2132 if (SCTP_ADDR_DEL ==
2133 sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
2134 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
2136 /* Stop the T2-shutdown timer. */
2137 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2138 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2140 /* Stop the T5-shutdown guard timer. */
2141 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2142 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
2144 return __sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
2148 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2150 * See sctp_sf_do_9_1_abort().
2152 sctp_disposition_t sctp_sf_shutdown_ack_sent_abort(
2153 const struct sctp_endpoint *ep,
2154 const struct sctp_association *asoc,
2155 const sctp_subtype_t type,
2157 sctp_cmd_seq_t *commands)
2159 /* The same T2 timer, so we should be able to use
2160 * common function with the SHUTDOWN-SENT state.
2162 return sctp_sf_shutdown_sent_abort(ep, asoc, type, arg, commands);
2166 * Handle an Error received in COOKIE_ECHOED state.
2168 * Only handle the error type of stale COOKIE Error, the other errors will
2172 * (endpoint, asoc, chunk)
2175 * (asoc, reply_msg, msg_up, timers, counters)
2177 * The return value is the disposition of the chunk.
2179 sctp_disposition_t sctp_sf_cookie_echoed_err(const struct sctp_endpoint *ep,
2180 const struct sctp_association *asoc,
2181 const sctp_subtype_t type,
2183 sctp_cmd_seq_t *commands)
2185 struct sctp_chunk *chunk = arg;
2188 if (!sctp_vtag_verify(chunk, asoc))
2189 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2191 /* Make sure that the ERROR chunk has a valid length.
2192 * The parameter walking depends on this as well.
2194 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t)))
2195 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2198 /* Process the error here */
2199 /* FUTURE FIXME: When PR-SCTP related and other optional
2200 * parms are emitted, this will have to change to handle multiple
2203 sctp_walk_errors(err, chunk->chunk_hdr) {
2204 if (SCTP_ERROR_STALE_COOKIE == err->cause)
2205 return sctp_sf_do_5_2_6_stale(ep, asoc, type,
2209 /* It is possible to have malformed error causes, and that
2210 * will cause us to end the walk early. However, since
2211 * we are discarding the packet, there should be no adverse
2214 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2218 * Handle a Stale COOKIE Error
2220 * Section: 5.2.6 Handle Stale COOKIE Error
2221 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2222 * one of the following three alternatives.
2224 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2225 * Preservative parameter requesting an extension to the lifetime of
2226 * the State Cookie. When calculating the time extension, an
2227 * implementation SHOULD use the RTT information measured based on the
2228 * previous COOKIE ECHO / ERROR exchange, and should add no more
2229 * than 1 second beyond the measured RTT, due to long State Cookie
2230 * lifetimes making the endpoint more subject to a replay attack.
2232 * Verification Tag: Not explicit, but safe to ignore.
2235 * (endpoint, asoc, chunk)
2238 * (asoc, reply_msg, msg_up, timers, counters)
2240 * The return value is the disposition of the chunk.
2242 static sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep,
2243 const struct sctp_association *asoc,
2244 const sctp_subtype_t type,
2246 sctp_cmd_seq_t *commands)
2248 struct sctp_chunk *chunk = arg;
2250 sctp_cookie_preserve_param_t bht;
2252 struct sctp_chunk *reply;
2253 struct sctp_bind_addr *bp;
2254 int attempts = asoc->init_err_counter + 1;
2256 if (attempts > asoc->max_init_attempts) {
2257 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
2258 SCTP_ERROR(ETIMEDOUT));
2259 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2260 SCTP_PERR(SCTP_ERROR_STALE_COOKIE));
2261 return SCTP_DISPOSITION_DELETE_TCB;
2264 err = (sctp_errhdr_t *)(chunk->skb->data);
2266 /* When calculating the time extension, an implementation
2267 * SHOULD use the RTT information measured based on the
2268 * previous COOKIE ECHO / ERROR exchange, and should add no
2269 * more than 1 second beyond the measured RTT, due to long
2270 * State Cookie lifetimes making the endpoint more subject to
2272 * Measure of Staleness's unit is usec. (1/1000000 sec)
2273 * Suggested Cookie Life-span Increment's unit is msec.
2275 * In general, if you use the suggested cookie life, the value
2276 * found in the field of measure of staleness should be doubled
2277 * to give ample time to retransmit the new cookie and thus
2278 * yield a higher probability of success on the reattempt.
2280 stale = ntohl(*(__be32 *)((u8 *)err + sizeof(sctp_errhdr_t)));
2281 stale = (stale * 2) / 1000;
2283 bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE;
2284 bht.param_hdr.length = htons(sizeof(bht));
2285 bht.lifespan_increment = htonl(stale);
2287 /* Build that new INIT chunk. */
2288 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
2289 reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht));
2293 sctp_addto_chunk(reply, sizeof(bht), &bht);
2295 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2296 sctp_add_cmd_sf(commands, SCTP_CMD_CLEAR_INIT_TAG, SCTP_NULL());
2298 /* Stop pending T3-rtx and heartbeat timers */
2299 sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL());
2300 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
2302 /* Delete non-primary peer ip addresses since we are transitioning
2303 * back to the COOKIE-WAIT state
2305 sctp_add_cmd_sf(commands, SCTP_CMD_DEL_NON_PRIMARY, SCTP_NULL());
2307 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2310 sctp_add_cmd_sf(commands, SCTP_CMD_T1_RETRAN,
2311 SCTP_TRANSPORT(asoc->peer.primary_path));
2313 /* Cast away the const modifier, as we want to just
2314 * rerun it through as a sideffect.
2316 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_INC, SCTP_NULL());
2318 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2319 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
2320 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2321 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
2322 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
2323 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2325 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2327 return SCTP_DISPOSITION_CONSUME;
2330 return SCTP_DISPOSITION_NOMEM;
2337 * After checking the Verification Tag, the receiving endpoint shall
2338 * remove the association from its record, and shall report the
2339 * termination to its upper layer.
2341 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2342 * B) Rules for packet carrying ABORT:
2344 * - The endpoint shall always fill in the Verification Tag field of the
2345 * outbound packet with the destination endpoint's tag value if it
2348 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2349 * MUST follow the procedure described in Section 8.4.
2351 * - The receiver MUST accept the packet if the Verification Tag
2352 * matches either its own tag, OR the tag of its peer. Otherwise, the
2353 * receiver MUST silently discard the packet and take no further
2357 * (endpoint, asoc, chunk)
2360 * (asoc, reply_msg, msg_up, timers, counters)
2362 * The return value is the disposition of the chunk.
2364 sctp_disposition_t sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep,
2365 const struct sctp_association *asoc,
2366 const sctp_subtype_t type,
2368 sctp_cmd_seq_t *commands)
2370 struct sctp_chunk *chunk = arg;
2372 if (!sctp_vtag_verify_either(chunk, asoc))
2373 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2375 /* Make sure that the ABORT chunk has a valid length.
2376 * Since this is an ABORT chunk, we have to discard it
2377 * because of the following text:
2378 * RFC 2960, Section 3.3.7
2379 * If an endpoint receives an ABORT with a format error or for an
2380 * association that doesn't exist, it MUST silently discard it.
2381 * Becasue the length is "invalid", we can't really discard just
2382 * as we do not know its true length. So, to be safe, discard the
2385 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2386 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2388 /* ADD-IP: Special case for ABORT chunks
2389 * F4) One special consideration is that ABORT Chunks arriving
2390 * destined to the IP address being deleted MUST be
2391 * ignored (see Section 5.3.1 for further details).
2393 if (SCTP_ADDR_DEL ==
2394 sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
2395 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
2397 return __sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
2400 static sctp_disposition_t __sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep,
2401 const struct sctp_association *asoc,
2402 const sctp_subtype_t type,
2404 sctp_cmd_seq_t *commands)
2406 struct sctp_chunk *chunk = arg;
2408 __be16 error = SCTP_ERROR_NO_ERROR;
2410 /* See if we have an error cause code in the chunk. */
2411 len = ntohs(chunk->chunk_hdr->length);
2412 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2413 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2415 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNRESET));
2416 /* ASSOC_FAILED will DELETE_TCB. */
2417 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_PERR(error));
2418 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
2419 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
2421 return SCTP_DISPOSITION_ABORT;
2425 * Process an ABORT. (COOKIE-WAIT state)
2427 * See sctp_sf_do_9_1_abort() above.
2429 sctp_disposition_t sctp_sf_cookie_wait_abort(const struct sctp_endpoint *ep,
2430 const struct sctp_association *asoc,
2431 const sctp_subtype_t type,
2433 sctp_cmd_seq_t *commands)
2435 struct sctp_chunk *chunk = arg;
2437 __be16 error = SCTP_ERROR_NO_ERROR;
2439 if (!sctp_vtag_verify_either(chunk, asoc))
2440 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2442 /* Make sure that the ABORT chunk has a valid length.
2443 * Since this is an ABORT chunk, we have to discard it
2444 * because of the following text:
2445 * RFC 2960, Section 3.3.7
2446 * If an endpoint receives an ABORT with a format error or for an
2447 * association that doesn't exist, it MUST silently discard it.
2448 * Becasue the length is "invalid", we can't really discard just
2449 * as we do not know its true length. So, to be safe, discard the
2452 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2453 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2455 /* See if we have an error cause code in the chunk. */
2456 len = ntohs(chunk->chunk_hdr->length);
2457 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2458 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2460 return sctp_stop_t1_and_abort(commands, error, ECONNREFUSED, asoc,
2465 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2467 sctp_disposition_t sctp_sf_cookie_wait_icmp_abort(const struct sctp_endpoint *ep,
2468 const struct sctp_association *asoc,
2469 const sctp_subtype_t type,
2471 sctp_cmd_seq_t *commands)
2473 return sctp_stop_t1_and_abort(commands, SCTP_ERROR_NO_ERROR,
2475 (struct sctp_transport *)arg);
2479 * Process an ABORT. (COOKIE-ECHOED state)
2481 sctp_disposition_t sctp_sf_cookie_echoed_abort(const struct sctp_endpoint *ep,
2482 const struct sctp_association *asoc,
2483 const sctp_subtype_t type,
2485 sctp_cmd_seq_t *commands)
2487 /* There is a single T1 timer, so we should be able to use
2488 * common function with the COOKIE-WAIT state.
2490 return sctp_sf_cookie_wait_abort(ep, asoc, type, arg, commands);
2494 * Stop T1 timer and abort association with "INIT failed".
2496 * This is common code called by several sctp_sf_*_abort() functions above.
2498 static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands,
2499 __be16 error, int sk_err,
2500 const struct sctp_association *asoc,
2501 struct sctp_transport *transport)
2503 SCTP_DEBUG_PRINTK("ABORT received (INIT).\n");
2504 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2505 SCTP_STATE(SCTP_STATE_CLOSED));
2506 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
2507 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2508 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2509 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(sk_err));
2510 /* CMD_INIT_FAILED will DELETE_TCB. */
2511 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2513 return SCTP_DISPOSITION_ABORT;
2517 * sctp_sf_do_9_2_shut
2520 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2521 * - enter the SHUTDOWN-RECEIVED state,
2523 * - stop accepting new data from its SCTP user
2525 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2526 * that all its outstanding DATA chunks have been received by the
2529 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2530 * send a SHUTDOWN in response to a ULP request. And should discard
2531 * subsequent SHUTDOWN chunks.
2533 * If there are still outstanding DATA chunks left, the SHUTDOWN
2534 * receiver shall continue to follow normal data transmission
2535 * procedures defined in Section 6 until all outstanding DATA chunks
2536 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2537 * new data from its SCTP user.
2539 * Verification Tag: 8.5 Verification Tag [Normal verification]
2542 * (endpoint, asoc, chunk)
2545 * (asoc, reply_msg, msg_up, timers, counters)
2547 * The return value is the disposition of the chunk.
2549 sctp_disposition_t sctp_sf_do_9_2_shutdown(const struct sctp_endpoint *ep,
2550 const struct sctp_association *asoc,
2551 const sctp_subtype_t type,
2553 sctp_cmd_seq_t *commands)
2555 struct sctp_chunk *chunk = arg;
2556 sctp_shutdownhdr_t *sdh;
2557 sctp_disposition_t disposition;
2558 struct sctp_ulpevent *ev;
2560 if (!sctp_vtag_verify(chunk, asoc))
2561 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2563 /* Make sure that the SHUTDOWN chunk has a valid length. */
2564 if (!sctp_chunk_length_valid(chunk,
2565 sizeof(struct sctp_shutdown_chunk_t)))
2566 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2569 /* Convert the elaborate header. */
2570 sdh = (sctp_shutdownhdr_t *)chunk->skb->data;
2571 skb_pull(chunk->skb, sizeof(sctp_shutdownhdr_t));
2572 chunk->subh.shutdown_hdr = sdh;
2574 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2575 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2576 * inform the application that it should cease sending data.
2578 ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC);
2580 disposition = SCTP_DISPOSITION_NOMEM;
2583 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
2585 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2586 * - enter the SHUTDOWN-RECEIVED state,
2587 * - stop accepting new data from its SCTP user
2589 * [This is implicit in the new state.]
2591 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2592 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED));
2593 disposition = SCTP_DISPOSITION_CONSUME;
2595 if (sctp_outq_is_empty(&asoc->outqueue)) {
2596 disposition = sctp_sf_do_9_2_shutdown_ack(ep, asoc, type,
2600 if (SCTP_DISPOSITION_NOMEM == disposition)
2603 /* - verify, by checking the Cumulative TSN Ack field of the
2604 * chunk, that all its outstanding DATA chunks have been
2605 * received by the SHUTDOWN sender.
2607 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
2608 SCTP_BE32(chunk->subh.shutdown_hdr->cum_tsn_ack));
2615 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2616 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2617 * transport addresses (either in the IP addresses or in the INIT chunk)
2618 * that belong to this association, it should discard the INIT chunk and
2619 * retransmit the SHUTDOWN ACK chunk.
2621 sctp_disposition_t sctp_sf_do_9_2_reshutack(const struct sctp_endpoint *ep,
2622 const struct sctp_association *asoc,
2623 const sctp_subtype_t type,
2625 sctp_cmd_seq_t *commands)
2627 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
2628 struct sctp_chunk *reply;
2630 /* Make sure that the chunk has a valid length */
2631 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
2632 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2635 /* Since we are not going to really process this INIT, there
2636 * is no point in verifying chunk boundries. Just generate
2639 reply = sctp_make_shutdown_ack(asoc, chunk);
2643 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2644 * the T2-SHUTDOWN timer.
2646 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
2648 /* and restart the T2-shutdown timer. */
2649 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2650 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2652 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2654 return SCTP_DISPOSITION_CONSUME;
2656 return SCTP_DISPOSITION_NOMEM;
2660 * sctp_sf_do_ecn_cwr
2662 * Section: Appendix A: Explicit Congestion Notification
2666 * RFC 2481 details a specific bit for a sender to send in the header of
2667 * its next outbound TCP segment to indicate to its peer that it has
2668 * reduced its congestion window. This is termed the CWR bit. For
2669 * SCTP the same indication is made by including the CWR chunk.
2670 * This chunk contains one data element, i.e. the TSN number that
2671 * was sent in the ECNE chunk. This element represents the lowest
2672 * TSN number in the datagram that was originally marked with the
2675 * Verification Tag: 8.5 Verification Tag [Normal verification]
2677 * (endpoint, asoc, chunk)
2680 * (asoc, reply_msg, msg_up, timers, counters)
2682 * The return value is the disposition of the chunk.
2684 sctp_disposition_t sctp_sf_do_ecn_cwr(const struct sctp_endpoint *ep,
2685 const struct sctp_association *asoc,
2686 const sctp_subtype_t type,
2688 sctp_cmd_seq_t *commands)
2691 struct sctp_chunk *chunk = arg;
2694 if (!sctp_vtag_verify(chunk, asoc))
2695 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2697 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t)))
2698 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2701 cwr = (sctp_cwrhdr_t *) chunk->skb->data;
2702 skb_pull(chunk->skb, sizeof(sctp_cwrhdr_t));
2704 lowest_tsn = ntohl(cwr->lowest_tsn);
2706 /* Does this CWR ack the last sent congestion notification? */
2707 if (TSN_lte(asoc->last_ecne_tsn, lowest_tsn)) {
2708 /* Stop sending ECNE. */
2709 sctp_add_cmd_sf(commands,
2711 SCTP_U32(lowest_tsn));
2713 return SCTP_DISPOSITION_CONSUME;
2719 * Section: Appendix A: Explicit Congestion Notification
2723 * RFC 2481 details a specific bit for a receiver to send back in its
2724 * TCP acknowledgements to notify the sender of the Congestion
2725 * Experienced (CE) bit having arrived from the network. For SCTP this
2726 * same indication is made by including the ECNE chunk. This chunk
2727 * contains one data element, i.e. the lowest TSN associated with the IP
2728 * datagram marked with the CE bit.....
2730 * Verification Tag: 8.5 Verification Tag [Normal verification]
2732 * (endpoint, asoc, chunk)
2735 * (asoc, reply_msg, msg_up, timers, counters)
2737 * The return value is the disposition of the chunk.
2739 sctp_disposition_t sctp_sf_do_ecne(const struct sctp_endpoint *ep,
2740 const struct sctp_association *asoc,
2741 const sctp_subtype_t type,
2743 sctp_cmd_seq_t *commands)
2745 sctp_ecnehdr_t *ecne;
2746 struct sctp_chunk *chunk = arg;
2748 if (!sctp_vtag_verify(chunk, asoc))
2749 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2751 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t)))
2752 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2755 ecne = (sctp_ecnehdr_t *) chunk->skb->data;
2756 skb_pull(chunk->skb, sizeof(sctp_ecnehdr_t));
2758 /* If this is a newer ECNE than the last CWR packet we sent out */
2759 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE,
2760 SCTP_U32(ntohl(ecne->lowest_tsn)));
2762 return SCTP_DISPOSITION_CONSUME;
2766 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2768 * The SCTP endpoint MUST always acknowledge the reception of each valid
2771 * The guidelines on delayed acknowledgement algorithm specified in
2772 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2773 * acknowledgement SHOULD be generated for at least every second packet
2774 * (not every second DATA chunk) received, and SHOULD be generated within
2775 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2776 * situations it may be beneficial for an SCTP transmitter to be more
2777 * conservative than the algorithms detailed in this document allow.
2778 * However, an SCTP transmitter MUST NOT be more aggressive than the
2779 * following algorithms allow.
2781 * A SCTP receiver MUST NOT generate more than one SACK for every
2782 * incoming packet, other than to update the offered window as the
2783 * receiving application consumes new data.
2785 * Verification Tag: 8.5 Verification Tag [Normal verification]
2788 * (endpoint, asoc, chunk)
2791 * (asoc, reply_msg, msg_up, timers, counters)
2793 * The return value is the disposition of the chunk.
2795 sctp_disposition_t sctp_sf_eat_data_6_2(const struct sctp_endpoint *ep,
2796 const struct sctp_association *asoc,
2797 const sctp_subtype_t type,
2799 sctp_cmd_seq_t *commands)
2801 struct sctp_chunk *chunk = arg;
2804 if (!sctp_vtag_verify(chunk, asoc)) {
2805 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2807 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2810 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t)))
2811 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2814 error = sctp_eat_data(asoc, chunk, commands );
2816 case SCTP_IERROR_NO_ERROR:
2818 case SCTP_IERROR_HIGH_TSN:
2819 case SCTP_IERROR_BAD_STREAM:
2820 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
2821 goto discard_noforce;
2822 case SCTP_IERROR_DUP_TSN:
2823 case SCTP_IERROR_IGNORE_TSN:
2824 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
2826 case SCTP_IERROR_NO_DATA:
2832 if (asoc->autoclose) {
2833 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2834 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
2837 /* If this is the last chunk in a packet, we need to count it
2838 * toward sack generation. Note that we need to SACK every
2839 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2840 * THEM. We elect to NOT generate SACK's if the chunk fails
2841 * the verification tag test.
2843 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2845 * The SCTP endpoint MUST always acknowledge the reception of
2846 * each valid DATA chunk.
2848 * The guidelines on delayed acknowledgement algorithm
2849 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2850 * Specifically, an acknowledgement SHOULD be generated for at
2851 * least every second packet (not every second DATA chunk)
2852 * received, and SHOULD be generated within 200 ms of the
2853 * arrival of any unacknowledged DATA chunk. In some
2854 * situations it may be beneficial for an SCTP transmitter to
2855 * be more conservative than the algorithms detailed in this
2856 * document allow. However, an SCTP transmitter MUST NOT be
2857 * more aggressive than the following algorithms allow.
2859 if (chunk->end_of_packet)
2860 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2862 return SCTP_DISPOSITION_CONSUME;
2865 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2867 * When a packet arrives with duplicate DATA chunk(s) and with
2868 * no new DATA chunk(s), the endpoint MUST immediately send a
2869 * SACK with no delay. If a packet arrives with duplicate
2870 * DATA chunk(s) bundled with new DATA chunks, the endpoint
2871 * MAY immediately send a SACK. Normally receipt of duplicate
2872 * DATA chunks will occur when the original SACK chunk was lost
2873 * and the peer's RTO has expired. The duplicate TSN number(s)
2874 * SHOULD be reported in the SACK as duplicate.
2876 /* In our case, we split the MAY SACK advice up whether or not
2877 * the last chunk is a duplicate.'
2879 if (chunk->end_of_packet)
2880 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2881 return SCTP_DISPOSITION_DISCARD;
2884 if (chunk->end_of_packet)
2885 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2887 return SCTP_DISPOSITION_DISCARD;
2889 return SCTP_DISPOSITION_CONSUME;
2894 * sctp_sf_eat_data_fast_4_4
2897 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
2898 * DATA chunks without delay.
2900 * Verification Tag: 8.5 Verification Tag [Normal verification]
2902 * (endpoint, asoc, chunk)
2905 * (asoc, reply_msg, msg_up, timers, counters)
2907 * The return value is the disposition of the chunk.
2909 sctp_disposition_t sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint *ep,
2910 const struct sctp_association *asoc,
2911 const sctp_subtype_t type,
2913 sctp_cmd_seq_t *commands)
2915 struct sctp_chunk *chunk = arg;
2918 if (!sctp_vtag_verify(chunk, asoc)) {
2919 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2921 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2924 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t)))
2925 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2928 error = sctp_eat_data(asoc, chunk, commands );
2930 case SCTP_IERROR_NO_ERROR:
2931 case SCTP_IERROR_HIGH_TSN:
2932 case SCTP_IERROR_DUP_TSN:
2933 case SCTP_IERROR_IGNORE_TSN:
2934 case SCTP_IERROR_BAD_STREAM:
2936 case SCTP_IERROR_NO_DATA:
2942 /* Go a head and force a SACK, since we are shutting down. */
2944 /* Implementor's Guide.
2946 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
2947 * respond to each received packet containing one or more DATA chunk(s)
2948 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
2950 if (chunk->end_of_packet) {
2951 /* We must delay the chunk creation since the cumulative
2952 * TSN has not been updated yet.
2954 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
2955 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2956 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2957 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2961 return SCTP_DISPOSITION_CONSUME;
2965 * Section: 6.2 Processing a Received SACK
2966 * D) Any time a SACK arrives, the endpoint performs the following:
2968 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
2969 * then drop the SACK. Since Cumulative TSN Ack is monotonically
2970 * increasing, a SACK whose Cumulative TSN Ack is less than the
2971 * Cumulative TSN Ack Point indicates an out-of-order SACK.
2973 * ii) Set rwnd equal to the newly received a_rwnd minus the number
2974 * of bytes still outstanding after processing the Cumulative TSN Ack
2975 * and the Gap Ack Blocks.
2977 * iii) If the SACK is missing a TSN that was previously
2978 * acknowledged via a Gap Ack Block (e.g., the data receiver
2979 * reneged on the data), then mark the corresponding DATA chunk
2980 * as available for retransmit: Mark it as missing for fast
2981 * retransmit as described in Section 7.2.4 and if no retransmit
2982 * timer is running for the destination address to which the DATA
2983 * chunk was originally transmitted, then T3-rtx is started for
2984 * that destination address.
2986 * Verification Tag: 8.5 Verification Tag [Normal verification]
2989 * (endpoint, asoc, chunk)
2992 * (asoc, reply_msg, msg_up, timers, counters)
2994 * The return value is the disposition of the chunk.
2996 sctp_disposition_t sctp_sf_eat_sack_6_2(const struct sctp_endpoint *ep,
2997 const struct sctp_association *asoc,
2998 const sctp_subtype_t type,
3000 sctp_cmd_seq_t *commands)
3002 struct sctp_chunk *chunk = arg;
3003 sctp_sackhdr_t *sackh;
3006 if (!sctp_vtag_verify(chunk, asoc))
3007 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3009 /* Make sure that the SACK chunk has a valid length. */
3010 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_sack_chunk_t)))
3011 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3014 /* Pull the SACK chunk from the data buffer */
3015 sackh = sctp_sm_pull_sack(chunk);
3016 /* Was this a bogus SACK? */
3018 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3019 chunk->subh.sack_hdr = sackh;
3020 ctsn = ntohl(sackh->cum_tsn_ack);
3022 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
3023 * Ack Point, then drop the SACK. Since Cumulative TSN
3024 * Ack is monotonically increasing, a SACK whose
3025 * Cumulative TSN Ack is less than the Cumulative TSN Ack
3026 * Point indicates an out-of-order SACK.
3028 if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
3029 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn);
3030 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc->ctsn_ack_point);
3031 return SCTP_DISPOSITION_DISCARD;
3034 /* If Cumulative TSN Ack beyond the max tsn currently
3035 * send, terminating the association and respond to the
3036 * sender with an ABORT.
3038 if (!TSN_lt(ctsn, asoc->next_tsn))
3039 return sctp_sf_violation_ctsn(ep, asoc, type, arg, commands);
3041 /* Return this SACK for further processing. */
3042 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_SACKH(sackh));
3044 /* Note: We do the rest of the work on the PROCESS_SACK
3047 return SCTP_DISPOSITION_CONSUME;
3051 * Generate an ABORT in response to a packet.
3053 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
3055 * 8) The receiver should respond to the sender of the OOTB packet with
3056 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3057 * MUST fill in the Verification Tag field of the outbound packet
3058 * with the value found in the Verification Tag field of the OOTB
3059 * packet and set the T-bit in the Chunk Flags to indicate that the
3060 * Verification Tag is reflected. After sending this ABORT, the
3061 * receiver of the OOTB packet shall discard the OOTB packet and take
3062 * no further action.
3066 * The return value is the disposition of the chunk.
3068 static sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep,
3069 const struct sctp_association *asoc,
3070 const sctp_subtype_t type,
3072 sctp_cmd_seq_t *commands)
3074 struct sctp_packet *packet = NULL;
3075 struct sctp_chunk *chunk = arg;
3076 struct sctp_chunk *abort;
3078 packet = sctp_ootb_pkt_new(asoc, chunk);
3081 /* Make an ABORT. The T bit will be set if the asoc
3084 abort = sctp_make_abort(asoc, chunk, 0);
3086 sctp_ootb_pkt_free(packet);
3087 return SCTP_DISPOSITION_NOMEM;
3090 /* Reflect vtag if T-Bit is set */
3091 if (sctp_test_T_bit(abort))
3092 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
3094 /* Set the skb to the belonging sock for accounting. */
3095 abort->skb->sk = ep->base.sk;
3097 sctp_packet_append_chunk(packet, abort);
3099 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
3100 SCTP_PACKET(packet));
3102 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
3104 sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3105 return SCTP_DISPOSITION_CONSUME;
3108 return SCTP_DISPOSITION_NOMEM;
3112 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
3113 * event as ULP notification for each cause included in the chunk.
3115 * API 5.3.1.3 - SCTP_REMOTE_ERROR
3117 * The return value is the disposition of the chunk.
3119 sctp_disposition_t sctp_sf_operr_notify(const struct sctp_endpoint *ep,
3120 const struct sctp_association *asoc,
3121 const sctp_subtype_t type,
3123 sctp_cmd_seq_t *commands)
3125 struct sctp_chunk *chunk = arg;
3126 struct sctp_ulpevent *ev;
3128 if (!sctp_vtag_verify(chunk, asoc))
3129 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3131 /* Make sure that the ERROR chunk has a valid length. */
3132 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t)))
3133 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3136 while (chunk->chunk_end > chunk->skb->data) {
3137 ev = sctp_ulpevent_make_remote_error(asoc, chunk, 0,
3142 if (!sctp_add_cmd(commands, SCTP_CMD_EVENT_ULP,
3143 SCTP_ULPEVENT(ev))) {
3144 sctp_ulpevent_free(ev);
3148 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR,
3151 return SCTP_DISPOSITION_CONSUME;
3154 return SCTP_DISPOSITION_NOMEM;
3158 * Process an inbound SHUTDOWN ACK.
3161 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3162 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3163 * peer, and remove all record of the association.
3165 * The return value is the disposition.
3167 sctp_disposition_t sctp_sf_do_9_2_final(const struct sctp_endpoint *ep,
3168 const struct sctp_association *asoc,
3169 const sctp_subtype_t type,
3171 sctp_cmd_seq_t *commands)
3173 struct sctp_chunk *chunk = arg;
3174 struct sctp_chunk *reply;
3175 struct sctp_ulpevent *ev;
3177 if (!sctp_vtag_verify(chunk, asoc))
3178 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3180 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3181 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3182 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3184 /* 10.2 H) SHUTDOWN COMPLETE notification
3186 * When SCTP completes the shutdown procedures (section 9.2) this
3187 * notification is passed to the upper layer.
3189 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
3190 0, 0, 0, NULL, GFP_ATOMIC);
3194 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3195 reply = sctp_make_shutdown_complete(asoc, chunk);
3199 /* Do all the commands now (after allocation), so that we
3200 * have consistent state if memory allocation failes
3202 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
3204 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3205 * stop the T2-shutdown timer,
3207 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3208 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3210 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3211 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3213 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3214 SCTP_STATE(SCTP_STATE_CLOSED));
3215 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
3216 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3217 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
3219 /* ...and remove all record of the association. */
3220 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
3221 return SCTP_DISPOSITION_DELETE_TCB;
3224 sctp_ulpevent_free(ev);
3226 return SCTP_DISPOSITION_NOMEM;
3230 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3232 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3233 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3234 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3235 * packet must fill in the Verification Tag field of the outbound
3236 * packet with the Verification Tag received in the SHUTDOWN ACK and
3237 * set the T-bit in the Chunk Flags to indicate that the Verification
3240 * 8) The receiver should respond to the sender of the OOTB packet with
3241 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3242 * MUST fill in the Verification Tag field of the outbound packet
3243 * with the value found in the Verification Tag field of the OOTB
3244 * packet and set the T-bit in the Chunk Flags to indicate that the
3245 * Verification Tag is reflected. After sending this ABORT, the
3246 * receiver of the OOTB packet shall discard the OOTB packet and take
3247 * no further action.
3249 sctp_disposition_t sctp_sf_ootb(const struct sctp_endpoint *ep,
3250 const struct sctp_association *asoc,
3251 const sctp_subtype_t type,
3253 sctp_cmd_seq_t *commands)
3255 struct sctp_chunk *chunk = arg;
3256 struct sk_buff *skb = chunk->skb;
3257 sctp_chunkhdr_t *ch;
3259 int ootb_shut_ack = 0;
3261 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES);
3263 ch = (sctp_chunkhdr_t *) chunk->chunk_hdr;
3265 /* Report violation if the chunk is less then minimal */
3266 if (ntohs(ch->length) < sizeof(sctp_chunkhdr_t))
3267 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3270 /* Now that we know we at least have a chunk header,
3271 * do things that are type appropriate.
3273 if (SCTP_CID_SHUTDOWN_ACK == ch->type)
3276 /* RFC 2960, Section 3.3.7
3277 * Moreover, under any circumstances, an endpoint that
3278 * receives an ABORT MUST NOT respond to that ABORT by
3279 * sending an ABORT of its own.
3281 if (SCTP_CID_ABORT == ch->type)
3282 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3284 /* Report violation if chunk len overflows */
3285 ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length));
3286 if (ch_end > skb_tail_pointer(skb))
3287 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3290 ch = (sctp_chunkhdr_t *) ch_end;
3291 } while (ch_end < skb_tail_pointer(skb));
3294 return sctp_sf_shut_8_4_5(ep, asoc, type, arg, commands);
3296 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
3300 * Handle an "Out of the blue" SHUTDOWN ACK.
3302 * Section: 8.4 5, sctpimpguide 2.41.
3304 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3305 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3306 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3307 * packet must fill in the Verification Tag field of the outbound
3308 * packet with the Verification Tag received in the SHUTDOWN ACK and
3309 * set the T-bit in the Chunk Flags to indicate that the Verification
3313 * (endpoint, asoc, type, arg, commands)
3316 * (sctp_disposition_t)
3318 * The return value is the disposition of the chunk.
3320 static sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep,
3321 const struct sctp_association *asoc,
3322 const sctp_subtype_t type,
3324 sctp_cmd_seq_t *commands)
3326 struct sctp_packet *packet = NULL;
3327 struct sctp_chunk *chunk = arg;
3328 struct sctp_chunk *shut;
3330 packet = sctp_ootb_pkt_new(asoc, chunk);
3333 /* Make an SHUTDOWN_COMPLETE.
3334 * The T bit will be set if the asoc is NULL.
3336 shut = sctp_make_shutdown_complete(asoc, chunk);
3338 sctp_ootb_pkt_free(packet);
3339 return SCTP_DISPOSITION_NOMEM;
3342 /* Reflect vtag if T-Bit is set */
3343 if (sctp_test_T_bit(shut))
3344 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
3346 /* Set the skb to the belonging sock for accounting. */
3347 shut->skb->sk = ep->base.sk;
3349 sctp_packet_append_chunk(packet, shut);
3351 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
3352 SCTP_PACKET(packet));
3354 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
3356 /* If the chunk length is invalid, we don't want to process
3357 * the reset of the packet.
3359 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3360 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3362 /* We need to discard the rest of the packet to prevent
3363 * potential bomming attacks from additional bundled chunks.
3364 * This is documented in SCTP Threats ID.
3366 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3369 return SCTP_DISPOSITION_NOMEM;
3373 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3375 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3376 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3377 * procedures in section 8.4 SHOULD be followed, in other words it
3378 * should be treated as an Out Of The Blue packet.
3379 * [This means that we do NOT check the Verification Tag on these
3383 sctp_disposition_t sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint *ep,
3384 const struct sctp_association *asoc,
3385 const sctp_subtype_t type,
3387 sctp_cmd_seq_t *commands)
3389 struct sctp_chunk *chunk = arg;
3391 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3392 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3393 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3396 /* Although we do have an association in this case, it corresponds
3397 * to a restarted association. So the packet is treated as an OOTB
3398 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3399 * called with a NULL association.
3401 return sctp_sf_shut_8_4_5(ep, NULL, type, arg, commands);
3404 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3405 sctp_disposition_t sctp_sf_do_asconf(const struct sctp_endpoint *ep,
3406 const struct sctp_association *asoc,
3407 const sctp_subtype_t type, void *arg,
3408 sctp_cmd_seq_t *commands)
3410 struct sctp_chunk *chunk = arg;
3411 struct sctp_chunk *asconf_ack = NULL;
3412 struct sctp_paramhdr *err_param = NULL;
3413 sctp_addiphdr_t *hdr;
3414 union sctp_addr_param *addr_param;
3418 if (!sctp_vtag_verify(chunk, asoc)) {
3419 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3421 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3424 /* ADD-IP: Section 4.1.1
3425 * This chunk MUST be sent in an authenticated way by using
3426 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3427 * is received unauthenticated it MUST be silently discarded as
3428 * described in [I-D.ietf-tsvwg-sctp-auth].
3430 if (!sctp_addip_noauth && !chunk->auth)
3431 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
3433 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3434 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_addip_chunk_t)))
3435 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3438 hdr = (sctp_addiphdr_t *)chunk->skb->data;
3439 serial = ntohl(hdr->serial);
3441 addr_param = (union sctp_addr_param *)hdr->params;
3442 length = ntohs(addr_param->p.length);
3443 if (length < sizeof(sctp_paramhdr_t))
3444 return sctp_sf_violation_paramlen(ep, asoc, type,
3445 (void *)addr_param, commands);
3447 /* Verify the ASCONF chunk before processing it. */
3448 if (!sctp_verify_asconf(asoc,
3449 (sctp_paramhdr_t *)((void *)addr_param + length),
3450 (void *)chunk->chunk_end,
3452 return sctp_sf_violation_paramlen(ep, asoc, type,
3453 (void *)&err_param, commands);
3455 /* ADDIP 5.2 E1) Compare the value of the serial number to the value
3456 * the endpoint stored in a new association variable
3457 * 'Peer-Serial-Number'.
3459 if (serial == asoc->peer.addip_serial + 1) {
3460 /* If this is the first instance of ASCONF in the packet,
3461 * we can clean our old ASCONF-ACKs.
3463 if (!chunk->has_asconf)
3464 sctp_assoc_clean_asconf_ack_cache(asoc);
3466 /* ADDIP 5.2 E4) When the Sequence Number matches the next one
3467 * expected, process the ASCONF as described below and after
3468 * processing the ASCONF Chunk, append an ASCONF-ACK Chunk to
3469 * the response packet and cache a copy of it (in the event it
3470 * later needs to be retransmitted).
3472 * Essentially, do V1-V5.
3474 asconf_ack = sctp_process_asconf((struct sctp_association *)
3477 return SCTP_DISPOSITION_NOMEM;
3478 } else if (serial < asoc->peer.addip_serial + 1) {
3480 * If the value found in the Sequence Number is less than the
3481 * ('Peer- Sequence-Number' + 1), simply skip to the next
3482 * ASCONF, and include in the outbound response packet
3483 * any previously cached ASCONF-ACK response that was
3484 * sent and saved that matches the Sequence Number of the
3485 * ASCONF. Note: It is possible that no cached ASCONF-ACK
3486 * Chunk exists. This will occur when an older ASCONF
3487 * arrives out of order. In such a case, the receiver
3488 * should skip the ASCONF Chunk and not include ASCONF-ACK
3489 * Chunk for that chunk.
3491 asconf_ack = sctp_assoc_lookup_asconf_ack(asoc, hdr->serial);
3493 return SCTP_DISPOSITION_DISCARD;
3495 /* ADDIP 5.2 E5) Otherwise, the ASCONF Chunk is discarded since
3496 * it must be either a stale packet or from an attacker.
3498 return SCTP_DISPOSITION_DISCARD;
3501 /* ADDIP 5.2 E6) The destination address of the SCTP packet
3502 * containing the ASCONF-ACK Chunks MUST be the source address of
3503 * the SCTP packet that held the ASCONF Chunks.
3505 * To do this properly, we'll set the destination address of the chunk
3506 * and at the transmit time, will try look up the transport to use.
3507 * Since ASCONFs may be bundled, the correct transport may not be
3508 * created untill we process the entire packet, thus this workaround.
3510 asconf_ack->dest = chunk->source;
3511 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack));
3513 return SCTP_DISPOSITION_CONSUME;
3517 * ADDIP Section 4.3 General rules for address manipulation
3518 * When building TLV parameters for the ASCONF Chunk that will add or
3519 * delete IP addresses the D0 to D13 rules should be applied:
3521 sctp_disposition_t sctp_sf_do_asconf_ack(const struct sctp_endpoint *ep,
3522 const struct sctp_association *asoc,
3523 const sctp_subtype_t type, void *arg,
3524 sctp_cmd_seq_t *commands)
3526 struct sctp_chunk *asconf_ack = arg;
3527 struct sctp_chunk *last_asconf = asoc->addip_last_asconf;
3528 struct sctp_chunk *abort;
3529 struct sctp_paramhdr *err_param = NULL;
3530 sctp_addiphdr_t *addip_hdr;
3531 __u32 sent_serial, rcvd_serial;
3533 if (!sctp_vtag_verify(asconf_ack, asoc)) {
3534 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3536 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3539 /* ADD-IP, Section 4.1.2:
3540 * This chunk MUST be sent in an authenticated way by using
3541 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3542 * is received unauthenticated it MUST be silently discarded as
3543 * described in [I-D.ietf-tsvwg-sctp-auth].
3545 if (!sctp_addip_noauth && !asconf_ack->auth)
3546 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
3548 /* Make sure that the ADDIP chunk has a valid length. */
3549 if (!sctp_chunk_length_valid(asconf_ack, sizeof(sctp_addip_chunk_t)))
3550 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3553 addip_hdr = (sctp_addiphdr_t *)asconf_ack->skb->data;
3554 rcvd_serial = ntohl(addip_hdr->serial);
3556 /* Verify the ASCONF-ACK chunk before processing it. */
3557 if (!sctp_verify_asconf(asoc,
3558 (sctp_paramhdr_t *)addip_hdr->params,
3559 (void *)asconf_ack->chunk_end,
3561 return sctp_sf_violation_paramlen(ep, asoc, type,
3562 (void *)&err_param, commands);
3565 addip_hdr = (sctp_addiphdr_t *)last_asconf->subh.addip_hdr;
3566 sent_serial = ntohl(addip_hdr->serial);
3568 sent_serial = asoc->addip_serial - 1;
3571 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3572 * equal to the next serial number to be used but no ASCONF chunk is
3573 * outstanding the endpoint MUST ABORT the association. Note that a
3574 * sequence number is greater than if it is no more than 2^^31-1
3575 * larger than the current sequence number (using serial arithmetic).
3577 if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) &&
3578 !(asoc->addip_last_asconf)) {
3579 abort = sctp_make_abort(asoc, asconf_ack,
3580 sizeof(sctp_errhdr_t));
3582 sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, 0);
3583 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3586 /* We are going to ABORT, so we might as well stop
3587 * processing the rest of the chunks in the packet.
3589 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3590 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3591 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3592 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3593 SCTP_ERROR(ECONNABORTED));
3594 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3595 SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
3596 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3597 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3598 return SCTP_DISPOSITION_ABORT;
3601 if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) {
3602 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3603 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3605 if (!sctp_process_asconf_ack((struct sctp_association *)asoc,
3607 return SCTP_DISPOSITION_CONSUME;
3609 abort = sctp_make_abort(asoc, asconf_ack,
3610 sizeof(sctp_errhdr_t));
3612 sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, 0);
3613 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3616 /* We are going to ABORT, so we might as well stop
3617 * processing the rest of the chunks in the packet.
3619 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3620 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3621 SCTP_ERROR(ECONNABORTED));
3622 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3623 SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
3624 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3625 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3626 return SCTP_DISPOSITION_ABORT;
3629 return SCTP_DISPOSITION_DISCARD;
3633 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3635 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3636 * its cumulative TSN point to the value carried in the FORWARD TSN
3637 * chunk, and then MUST further advance its cumulative TSN point locally
3639 * After the above processing, the data receiver MUST stop reporting any
3640 * missing TSNs earlier than or equal to the new cumulative TSN point.
3642 * Verification Tag: 8.5 Verification Tag [Normal verification]
3644 * The return value is the disposition of the chunk.
3646 sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep,
3647 const struct sctp_association *asoc,
3648 const sctp_subtype_t type,
3650 sctp_cmd_seq_t *commands)
3652 struct sctp_chunk *chunk = arg;
3653 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3657 if (!sctp_vtag_verify(chunk, asoc)) {
3658 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3660 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3663 /* Make sure that the FORWARD_TSN chunk has valid length. */
3664 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk)))
3665 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3668 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3669 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3670 len = ntohs(chunk->chunk_hdr->length);
3671 len -= sizeof(struct sctp_chunkhdr);
3672 skb_pull(chunk->skb, len);
3674 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3675 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn);
3677 /* The TSN is too high--silently discard the chunk and count on it
3678 * getting retransmitted later.
3680 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3681 goto discard_noforce;
3683 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3684 if (len > sizeof(struct sctp_fwdtsn_hdr))
3685 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3688 /* Count this as receiving DATA. */
3689 if (asoc->autoclose) {
3690 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3691 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
3694 /* FIXME: For now send a SACK, but DATA processing may
3697 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
3699 return SCTP_DISPOSITION_CONSUME;
3702 return SCTP_DISPOSITION_DISCARD;
3705 sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(
3706 const struct sctp_endpoint *ep,
3707 const struct sctp_association *asoc,
3708 const sctp_subtype_t type,
3710 sctp_cmd_seq_t *commands)
3712 struct sctp_chunk *chunk = arg;
3713 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3717 if (!sctp_vtag_verify(chunk, asoc)) {
3718 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3720 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3723 /* Make sure that the FORWARD_TSN chunk has a valid length. */
3724 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk)))
3725 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3728 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3729 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3730 len = ntohs(chunk->chunk_hdr->length);
3731 len -= sizeof(struct sctp_chunkhdr);
3732 skb_pull(chunk->skb, len);
3734 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3735 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn);
3737 /* The TSN is too high--silently discard the chunk and count on it
3738 * getting retransmitted later.
3740 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3743 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3744 if (len > sizeof(struct sctp_fwdtsn_hdr))
3745 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3748 /* Go a head and force a SACK, since we are shutting down. */
3750 /* Implementor's Guide.
3752 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3753 * respond to each received packet containing one or more DATA chunk(s)
3754 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3756 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
3757 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
3758 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3759 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3761 return SCTP_DISPOSITION_CONSUME;
3765 * SCTP-AUTH Section 6.3 Receving authenticated chukns
3767 * The receiver MUST use the HMAC algorithm indicated in the HMAC
3768 * Identifier field. If this algorithm was not specified by the
3769 * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk
3770 * during association setup, the AUTH chunk and all chunks after it MUST
3771 * be discarded and an ERROR chunk SHOULD be sent with the error cause
3772 * defined in Section 4.1.
3774 * If an endpoint with no shared key receives a Shared Key Identifier
3775 * other than 0, it MUST silently discard all authenticated chunks. If
3776 * the endpoint has at least one endpoint pair shared key for the peer,
3777 * it MUST use the key specified by the Shared Key Identifier if a
3778 * key has been configured for that Shared Key Identifier. If no
3779 * endpoint pair shared key has been configured for that Shared Key
3780 * Identifier, all authenticated chunks MUST be silently discarded.
3782 * Verification Tag: 8.5 Verification Tag [Normal verification]
3784 * The return value is the disposition of the chunk.
3786 static sctp_ierror_t sctp_sf_authenticate(const struct sctp_endpoint *ep,
3787 const struct sctp_association *asoc,
3788 const sctp_subtype_t type,
3789 struct sctp_chunk *chunk)
3791 struct sctp_authhdr *auth_hdr;
3792 struct sctp_hmac *hmac;
3793 unsigned int sig_len;
3798 /* Pull in the auth header, so we can do some more verification */
3799 auth_hdr = (struct sctp_authhdr *)chunk->skb->data;
3800 chunk->subh.auth_hdr = auth_hdr;
3801 skb_pull(chunk->skb, sizeof(struct sctp_authhdr));
3803 /* Make sure that we suport the HMAC algorithm from the auth
3806 if (!sctp_auth_asoc_verify_hmac_id(asoc, auth_hdr->hmac_id))
3807 return SCTP_IERROR_AUTH_BAD_HMAC;
3809 /* Make sure that the provided shared key identifier has been
3812 key_id = ntohs(auth_hdr->shkey_id);
3813 if (key_id != asoc->active_key_id && !sctp_auth_get_shkey(asoc, key_id))
3814 return SCTP_IERROR_AUTH_BAD_KEYID;
3817 /* Make sure that the length of the signature matches what
3820 sig_len = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_auth_chunk_t);
3821 hmac = sctp_auth_get_hmac(ntohs(auth_hdr->hmac_id));
3822 if (sig_len != hmac->hmac_len)
3823 return SCTP_IERROR_PROTO_VIOLATION;
3825 /* Now that we've done validation checks, we can compute and
3826 * verify the hmac. The steps involved are:
3827 * 1. Save the digest from the chunk.
3828 * 2. Zero out the digest in the chunk.
3829 * 3. Compute the new digest
3830 * 4. Compare saved and new digests.
3832 digest = auth_hdr->hmac;
3833 skb_pull(chunk->skb, sig_len);
3835 save_digest = kmemdup(digest, sig_len, GFP_ATOMIC);
3839 memset(digest, 0, sig_len);
3841 sctp_auth_calculate_hmac(asoc, chunk->skb,
3842 (struct sctp_auth_chunk *)chunk->chunk_hdr,
3845 /* Discard the packet if the digests do not match */
3846 if (memcmp(save_digest, digest, sig_len)) {
3848 return SCTP_IERROR_BAD_SIG;
3854 return SCTP_IERROR_NO_ERROR;
3856 return SCTP_IERROR_NOMEM;
3859 sctp_disposition_t sctp_sf_eat_auth(const struct sctp_endpoint *ep,
3860 const struct sctp_association *asoc,
3861 const sctp_subtype_t type,
3863 sctp_cmd_seq_t *commands)
3865 struct sctp_authhdr *auth_hdr;
3866 struct sctp_chunk *chunk = arg;
3867 struct sctp_chunk *err_chunk;
3868 sctp_ierror_t error;
3870 if (!sctp_vtag_verify(chunk, asoc)) {
3871 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3873 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3876 /* Make sure that the AUTH chunk has valid length. */
3877 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_auth_chunk)))
3878 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3881 auth_hdr = (struct sctp_authhdr *)chunk->skb->data;
3882 error = sctp_sf_authenticate(ep, asoc, type, chunk);
3884 case SCTP_IERROR_AUTH_BAD_HMAC:
3885 /* Generate the ERROR chunk and discard the rest
3888 err_chunk = sctp_make_op_error(asoc, chunk,
3889 SCTP_ERROR_UNSUP_HMAC,
3893 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3894 SCTP_CHUNK(err_chunk));
3897 case SCTP_IERROR_AUTH_BAD_KEYID:
3898 case SCTP_IERROR_BAD_SIG:
3899 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3901 case SCTP_IERROR_PROTO_VIOLATION:
3902 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3905 case SCTP_IERROR_NOMEM:
3906 return SCTP_DISPOSITION_NOMEM;
3911 if (asoc->active_key_id != ntohs(auth_hdr->shkey_id)) {
3912 struct sctp_ulpevent *ev;
3914 ev = sctp_ulpevent_make_authkey(asoc, ntohs(auth_hdr->shkey_id),
3915 SCTP_AUTH_NEWKEY, GFP_ATOMIC);
3920 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
3924 return SCTP_DISPOSITION_CONSUME;
3928 * Process an unknown chunk.
3930 * Section: 3.2. Also, 2.1 in the implementor's guide.
3932 * Chunk Types are encoded such that the highest-order two bits specify
3933 * the action that must be taken if the processing endpoint does not
3934 * recognize the Chunk Type.
3936 * 00 - Stop processing this SCTP packet and discard it, do not process
3937 * any further chunks within it.
3939 * 01 - Stop processing this SCTP packet and discard it, do not process
3940 * any further chunks within it, and report the unrecognized
3941 * chunk in an 'Unrecognized Chunk Type'.
3943 * 10 - Skip this chunk and continue processing.
3945 * 11 - Skip this chunk and continue processing, but report in an ERROR
3946 * Chunk using the 'Unrecognized Chunk Type' cause of error.
3948 * The return value is the disposition of the chunk.
3950 sctp_disposition_t sctp_sf_unk_chunk(const struct sctp_endpoint *ep,
3951 const struct sctp_association *asoc,
3952 const sctp_subtype_t type,
3954 sctp_cmd_seq_t *commands)
3956 struct sctp_chunk *unk_chunk = arg;
3957 struct sctp_chunk *err_chunk;
3958 sctp_chunkhdr_t *hdr;
3960 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type.chunk);
3962 if (!sctp_vtag_verify(unk_chunk, asoc))
3963 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3965 /* Make sure that the chunk has a valid length.
3966 * Since we don't know the chunk type, we use a general
3967 * chunkhdr structure to make a comparison.
3969 if (!sctp_chunk_length_valid(unk_chunk, sizeof(sctp_chunkhdr_t)))
3970 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3973 switch (type.chunk & SCTP_CID_ACTION_MASK) {
3974 case SCTP_CID_ACTION_DISCARD:
3975 /* Discard the packet. */
3976 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3978 case SCTP_CID_ACTION_DISCARD_ERR:
3979 /* Discard the packet. */
3980 sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3982 /* Generate an ERROR chunk as response. */
3983 hdr = unk_chunk->chunk_hdr;
3984 err_chunk = sctp_make_op_error(asoc, unk_chunk,
3985 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
3986 WORD_ROUND(ntohs(hdr->length)));
3988 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3989 SCTP_CHUNK(err_chunk));
3991 return SCTP_DISPOSITION_CONSUME;
3993 case SCTP_CID_ACTION_SKIP:
3994 /* Skip the chunk. */
3995 return SCTP_DISPOSITION_DISCARD;
3997 case SCTP_CID_ACTION_SKIP_ERR:
3998 /* Generate an ERROR chunk as response. */
3999 hdr = unk_chunk->chunk_hdr;
4000 err_chunk = sctp_make_op_error(asoc, unk_chunk,
4001 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
4002 WORD_ROUND(ntohs(hdr->length)));
4004 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4005 SCTP_CHUNK(err_chunk));
4007 /* Skip the chunk. */
4008 return SCTP_DISPOSITION_CONSUME;
4014 return SCTP_DISPOSITION_DISCARD;
4018 * Discard the chunk.
4020 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
4021 * [Too numerous to mention...]
4022 * Verification Tag: No verification needed.
4024 * (endpoint, asoc, chunk)
4027 * (asoc, reply_msg, msg_up, timers, counters)
4029 * The return value is the disposition of the chunk.
4031 sctp_disposition_t sctp_sf_discard_chunk(const struct sctp_endpoint *ep,
4032 const struct sctp_association *asoc,
4033 const sctp_subtype_t type,
4035 sctp_cmd_seq_t *commands)
4037 struct sctp_chunk *chunk = arg;
4039 /* Make sure that the chunk has a valid length.
4040 * Since we don't know the chunk type, we use a general
4041 * chunkhdr structure to make a comparison.
4043 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
4044 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
4047 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type.chunk);
4048 return SCTP_DISPOSITION_DISCARD;
4052 * Discard the whole packet.
4056 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
4057 * silently discard the OOTB packet and take no further action.
4059 * Verification Tag: No verification necessary
4062 * (endpoint, asoc, chunk)
4065 * (asoc, reply_msg, msg_up, timers, counters)
4067 * The return value is the disposition of the chunk.
4069 sctp_disposition_t sctp_sf_pdiscard(const struct sctp_endpoint *ep,
4070 const struct sctp_association *asoc,
4071 const sctp_subtype_t type,
4073 sctp_cmd_seq_t *commands)
4075 SCTP_INC_STATS(SCTP_MIB_IN_PKT_DISCARDS);
4076 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
4078 return SCTP_DISPOSITION_CONSUME;
4083 * The other end is violating protocol.
4085 * Section: Not specified
4086 * Verification Tag: Not specified
4088 * (endpoint, asoc, chunk)
4091 * (asoc, reply_msg, msg_up, timers, counters)
4093 * We simply tag the chunk as a violation. The state machine will log
4094 * the violation and continue.
4096 sctp_disposition_t sctp_sf_violation(const struct sctp_endpoint *ep,
4097 const struct sctp_association *asoc,
4098 const sctp_subtype_t type,
4100 sctp_cmd_seq_t *commands)
4102 struct sctp_chunk *chunk = arg;
4104 /* Make sure that the chunk has a valid length. */
4105 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
4106 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
4109 return SCTP_DISPOSITION_VIOLATION;
4113 * Common function to handle a protocol violation.
4115 static sctp_disposition_t sctp_sf_abort_violation(
4116 const struct sctp_endpoint *ep,
4117 const struct sctp_association *asoc,
4119 sctp_cmd_seq_t *commands,
4120 const __u8 *payload,
4121 const size_t paylen)
4123 struct sctp_packet *packet = NULL;
4124 struct sctp_chunk *chunk = arg;
4125 struct sctp_chunk *abort = NULL;
4127 /* SCTP-AUTH, Section 6.3:
4128 * It should be noted that if the receiver wants to tear
4129 * down an association in an authenticated way only, the
4130 * handling of malformed packets should not result in
4131 * tearing down the association.
4133 * This means that if we only want to abort associations
4134 * in an authenticated way (i.e AUTH+ABORT), then we
4135 * can't destory this association just becuase the packet
4138 if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
4141 /* Make the abort chunk. */
4142 abort = sctp_make_abort_violation(asoc, chunk, payload, paylen);
4147 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4148 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
4150 if (asoc->state <= SCTP_STATE_COOKIE_ECHOED) {
4151 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4152 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4153 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4154 SCTP_ERROR(ECONNREFUSED));
4155 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4156 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
4158 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4159 SCTP_ERROR(ECONNABORTED));
4160 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4161 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
4162 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4165 packet = sctp_ootb_pkt_new(asoc, chunk);
4170 if (sctp_test_T_bit(abort))
4171 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
4173 abort->skb->sk = ep->base.sk;
4175 sctp_packet_append_chunk(packet, abort);
4177 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
4178 SCTP_PACKET(packet));
4180 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
4184 sctp_sf_pdiscard(ep, asoc, SCTP_ST_CHUNK(0), arg, commands);
4186 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4188 return SCTP_DISPOSITION_ABORT;
4191 sctp_chunk_free(abort);
4193 return SCTP_DISPOSITION_NOMEM;
4197 * Handle a protocol violation when the chunk length is invalid.
4198 * "Invalid" length is identified as smaller then the minimal length a
4199 * given chunk can be. For example, a SACK chunk has invalid length
4200 * if it's length is set to be smaller then the size of sctp_sack_chunk_t.
4202 * We inform the other end by sending an ABORT with a Protocol Violation
4205 * Section: Not specified
4206 * Verification Tag: Nothing to do
4208 * (endpoint, asoc, chunk)
4211 * (reply_msg, msg_up, counters)
4213 * Generate an ABORT chunk and terminate the association.
4215 static sctp_disposition_t sctp_sf_violation_chunklen(
4216 const struct sctp_endpoint *ep,
4217 const struct sctp_association *asoc,
4218 const sctp_subtype_t type,
4220 sctp_cmd_seq_t *commands)
4222 char err_str[]="The following chunk had invalid length:";
4224 return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str,
4229 * Handle a protocol violation when the parameter length is invalid.
4230 * "Invalid" length is identified as smaller then the minimal length a
4231 * given parameter can be.
4233 static sctp_disposition_t sctp_sf_violation_paramlen(
4234 const struct sctp_endpoint *ep,
4235 const struct sctp_association *asoc,
4236 const sctp_subtype_t type,
4238 sctp_cmd_seq_t *commands) {
4239 char err_str[] = "The following parameter had invalid length:";
4241 return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str,
4245 /* Handle a protocol violation when the peer trying to advance the
4246 * cumulative tsn ack to a point beyond the max tsn currently sent.
4248 * We inform the other end by sending an ABORT with a Protocol Violation
4251 static sctp_disposition_t sctp_sf_violation_ctsn(
4252 const struct sctp_endpoint *ep,
4253 const struct sctp_association *asoc,
4254 const sctp_subtype_t type,
4256 sctp_cmd_seq_t *commands)
4258 char err_str[]="The cumulative tsn ack beyond the max tsn currently sent:";
4260 return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str,
4264 /* Handle protocol violation of an invalid chunk bundling. For example,
4265 * when we have an association and we recieve bundled INIT-ACK, or
4266 * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle"
4267 * statement from the specs. Additinally, there might be an attacker
4268 * on the path and we may not want to continue this communication.
4270 static sctp_disposition_t sctp_sf_violation_chunk(
4271 const struct sctp_endpoint *ep,
4272 const struct sctp_association *asoc,
4273 const sctp_subtype_t type,
4275 sctp_cmd_seq_t *commands)
4277 char err_str[]="The following chunk violates protocol:";
4280 return sctp_sf_violation(ep, asoc, type, arg, commands);
4282 return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str,
4285 /***************************************************************************
4286 * These are the state functions for handling primitive (Section 10) events.
4287 ***************************************************************************/
4289 * sctp_sf_do_prm_asoc
4291 * Section: 10.1 ULP-to-SCTP
4294 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
4295 * outbound stream count)
4296 * -> association id [,destination transport addr list] [,outbound stream
4299 * This primitive allows the upper layer to initiate an association to a
4300 * specific peer endpoint.
4302 * The peer endpoint shall be specified by one of the transport addresses
4303 * which defines the endpoint (see Section 1.4). If the local SCTP
4304 * instance has not been initialized, the ASSOCIATE is considered an
4306 * [This is not relevant for the kernel implementation since we do all
4307 * initialization at boot time. It we hadn't initialized we wouldn't
4308 * get anywhere near this code.]
4310 * An association id, which is a local handle to the SCTP association,
4311 * will be returned on successful establishment of the association. If
4312 * SCTP is not able to open an SCTP association with the peer endpoint,
4313 * an error is returned.
4314 * [In the kernel implementation, the struct sctp_association needs to
4315 * be created BEFORE causing this primitive to run.]
4317 * Other association parameters may be returned, including the
4318 * complete destination transport addresses of the peer as well as the
4319 * outbound stream count of the local endpoint. One of the transport
4320 * address from the returned destination addresses will be selected by
4321 * the local endpoint as default primary path for sending SCTP packets
4322 * to this peer. The returned "destination transport addr list" can
4323 * be used by the ULP to change the default primary path or to force
4324 * sending a packet to a specific transport address. [All of this
4325 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
4328 * Mandatory attributes:
4330 * o local SCTP instance name - obtained from the INITIALIZE operation.
4331 * [This is the argument asoc.]
4332 * o destination transport addr - specified as one of the transport
4333 * addresses of the peer endpoint with which the association is to be
4335 * [This is asoc->peer.active_path.]
4336 * o outbound stream count - the number of outbound streams the ULP
4337 * would like to open towards this peer endpoint.
4338 * [BUG: This is not currently implemented.]
4339 * Optional attributes:
4343 * The return value is a disposition.
4345 sctp_disposition_t sctp_sf_do_prm_asoc(const struct sctp_endpoint *ep,
4346 const struct sctp_association *asoc,
4347 const sctp_subtype_t type,
4349 sctp_cmd_seq_t *commands)
4351 struct sctp_chunk *repl;
4353 /* The comment below says that we enter COOKIE-WAIT AFTER
4354 * sending the INIT, but that doesn't actually work in our
4357 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4358 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
4360 /* RFC 2960 5.1 Normal Establishment of an Association
4362 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
4363 * must provide its Verification Tag (Tag_A) in the Initiate
4364 * Tag field. Tag_A SHOULD be a random number in the range of
4365 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
4368 repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0);
4372 /* Cast away the const modifier, as we want to just
4373 * rerun it through as a sideffect.
4375 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC,
4376 SCTP_ASOC((struct sctp_association *) asoc));
4378 /* Choose transport for INIT. */
4379 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
4382 /* After sending the INIT, "A" starts the T1-init timer and
4383 * enters the COOKIE-WAIT state.
4385 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4386 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4387 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
4388 return SCTP_DISPOSITION_CONSUME;
4391 return SCTP_DISPOSITION_NOMEM;
4395 * Process the SEND primitive.
4397 * Section: 10.1 ULP-to-SCTP
4400 * Format: SEND(association id, buffer address, byte count [,context]
4401 * [,stream id] [,life time] [,destination transport address]
4402 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
4405 * This is the main method to send user data via SCTP.
4407 * Mandatory attributes:
4409 * o association id - local handle to the SCTP association
4411 * o buffer address - the location where the user message to be
4412 * transmitted is stored;
4414 * o byte count - The size of the user data in number of bytes;
4416 * Optional attributes:
4418 * o context - an optional 32 bit integer that will be carried in the
4419 * sending failure notification to the ULP if the transportation of
4420 * this User Message fails.
4422 * o stream id - to indicate which stream to send the data on. If not
4423 * specified, stream 0 will be used.
4425 * o life time - specifies the life time of the user data. The user data
4426 * will not be sent by SCTP after the life time expires. This
4427 * parameter can be used to avoid efforts to transmit stale
4428 * user messages. SCTP notifies the ULP if the data cannot be
4429 * initiated to transport (i.e. sent to the destination via SCTP's
4430 * send primitive) within the life time variable. However, the
4431 * user data will be transmitted if SCTP has attempted to transmit a
4432 * chunk before the life time expired.
4434 * o destination transport address - specified as one of the destination
4435 * transport addresses of the peer endpoint to which this packet
4436 * should be sent. Whenever possible, SCTP should use this destination
4437 * transport address for sending the packets, instead of the current
4440 * o unorder flag - this flag, if present, indicates that the user
4441 * would like the data delivered in an unordered fashion to the peer
4442 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
4445 * o no-bundle flag - instructs SCTP not to bundle this user data with
4446 * other outbound DATA chunks. SCTP MAY still bundle even when
4447 * this flag is present, when faced with network congestion.
4449 * o payload protocol-id - A 32 bit unsigned integer that is to be
4450 * passed to the peer indicating the type of payload protocol data
4451 * being transmitted. This value is passed as opaque data by SCTP.
4453 * The return value is the disposition.
4455 sctp_disposition_t sctp_sf_do_prm_send(const struct sctp_endpoint *ep,
4456 const struct sctp_association *asoc,
4457 const sctp_subtype_t type,
4459 sctp_cmd_seq_t *commands)
4461 struct sctp_chunk *chunk = arg;
4463 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
4464 return SCTP_DISPOSITION_CONSUME;
4468 * Process the SHUTDOWN primitive.
4473 * Format: SHUTDOWN(association id)
4476 * Gracefully closes an association. Any locally queued user data
4477 * will be delivered to the peer. The association will be terminated only
4478 * after the peer acknowledges all the SCTP packets sent. A success code
4479 * will be returned on successful termination of the association. If
4480 * attempting to terminate the association results in a failure, an error
4481 * code shall be returned.
4483 * Mandatory attributes:
4485 * o association id - local handle to the SCTP association
4487 * Optional attributes:
4491 * The return value is the disposition.
4493 sctp_disposition_t sctp_sf_do_9_2_prm_shutdown(
4494 const struct sctp_endpoint *ep,
4495 const struct sctp_association *asoc,
4496 const sctp_subtype_t type,
4498 sctp_cmd_seq_t *commands)
4502 /* From 9.2 Shutdown of an Association
4503 * Upon receipt of the SHUTDOWN primitive from its upper
4504 * layer, the endpoint enters SHUTDOWN-PENDING state and
4505 * remains there until all outstanding data has been
4506 * acknowledged by its peer. The endpoint accepts no new data
4507 * from its upper layer, but retransmits data to the far end
4508 * if necessary to fill gaps.
4510 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4511 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
4513 /* sctpimpguide-05 Section 2.12.2
4514 * The sender of the SHUTDOWN MAY also start an overall guard timer
4515 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4517 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4518 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4520 disposition = SCTP_DISPOSITION_CONSUME;
4521 if (sctp_outq_is_empty(&asoc->outqueue)) {
4522 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
4529 * Process the ABORT primitive.
4534 * Format: Abort(association id [, cause code])
4537 * Ungracefully closes an association. Any locally queued user data
4538 * will be discarded and an ABORT chunk is sent to the peer. A success code
4539 * will be returned on successful abortion of the association. If
4540 * attempting to abort the association results in a failure, an error
4541 * code shall be returned.
4543 * Mandatory attributes:
4545 * o association id - local handle to the SCTP association
4547 * Optional attributes:
4549 * o cause code - reason of the abort to be passed to the peer
4553 * The return value is the disposition.
4555 sctp_disposition_t sctp_sf_do_9_1_prm_abort(
4556 const struct sctp_endpoint *ep,
4557 const struct sctp_association *asoc,
4558 const sctp_subtype_t type,
4560 sctp_cmd_seq_t *commands)
4562 /* From 9.1 Abort of an Association
4563 * Upon receipt of the ABORT primitive from its upper
4564 * layer, the endpoint enters CLOSED state and
4565 * discard all outstanding data has been
4566 * acknowledged by its peer. The endpoint accepts no new data
4567 * from its upper layer, but retransmits data to the far end
4568 * if necessary to fill gaps.
4570 struct sctp_chunk *abort = arg;
4571 sctp_disposition_t retval;
4573 retval = SCTP_DISPOSITION_CONSUME;
4575 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4577 /* Even if we can't send the ABORT due to low memory delete the
4578 * TCB. This is a departure from our typical NOMEM handling.
4581 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4582 SCTP_ERROR(ECONNABORTED));
4583 /* Delete the established association. */
4584 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4585 SCTP_PERR(SCTP_ERROR_USER_ABORT));
4587 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4588 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4593 /* We tried an illegal operation on an association which is closed. */
4594 sctp_disposition_t sctp_sf_error_closed(const struct sctp_endpoint *ep,
4595 const struct sctp_association *asoc,
4596 const sctp_subtype_t type,
4598 sctp_cmd_seq_t *commands)
4600 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL));
4601 return SCTP_DISPOSITION_CONSUME;
4604 /* We tried an illegal operation on an association which is shutting
4607 sctp_disposition_t sctp_sf_error_shutdown(const struct sctp_endpoint *ep,
4608 const struct sctp_association *asoc,
4609 const sctp_subtype_t type,
4611 sctp_cmd_seq_t *commands)
4613 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR,
4614 SCTP_ERROR(-ESHUTDOWN));
4615 return SCTP_DISPOSITION_CONSUME;
4619 * sctp_cookie_wait_prm_shutdown
4621 * Section: 4 Note: 2
4626 * The RFC does not explicitly address this issue, but is the route through the
4627 * state table when someone issues a shutdown while in COOKIE_WAIT state.
4632 sctp_disposition_t sctp_sf_cookie_wait_prm_shutdown(
4633 const struct sctp_endpoint *ep,
4634 const struct sctp_association *asoc,
4635 const sctp_subtype_t type,
4637 sctp_cmd_seq_t *commands)
4639 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4640 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4642 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4643 SCTP_STATE(SCTP_STATE_CLOSED));
4645 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
4647 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
4649 return SCTP_DISPOSITION_DELETE_TCB;
4653 * sctp_cookie_echoed_prm_shutdown
4655 * Section: 4 Note: 2
4660 * The RFC does not explcitly address this issue, but is the route through the
4661 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
4666 sctp_disposition_t sctp_sf_cookie_echoed_prm_shutdown(
4667 const struct sctp_endpoint *ep,
4668 const struct sctp_association *asoc,
4669 const sctp_subtype_t type,
4670 void *arg, sctp_cmd_seq_t *commands)
4672 /* There is a single T1 timer, so we should be able to use
4673 * common function with the COOKIE-WAIT state.
4675 return sctp_sf_cookie_wait_prm_shutdown(ep, asoc, type, arg, commands);
4679 * sctp_sf_cookie_wait_prm_abort
4681 * Section: 4 Note: 2
4686 * The RFC does not explicitly address this issue, but is the route through the
4687 * state table when someone issues an abort while in COOKIE_WAIT state.
4692 sctp_disposition_t sctp_sf_cookie_wait_prm_abort(
4693 const struct sctp_endpoint *ep,
4694 const struct sctp_association *asoc,
4695 const sctp_subtype_t type,
4697 sctp_cmd_seq_t *commands)
4699 struct sctp_chunk *abort = arg;
4700 sctp_disposition_t retval;
4702 /* Stop T1-init timer */
4703 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4704 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4705 retval = SCTP_DISPOSITION_CONSUME;
4707 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4709 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4710 SCTP_STATE(SCTP_STATE_CLOSED));
4712 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4714 /* Even if we can't send the ABORT due to low memory delete the
4715 * TCB. This is a departure from our typical NOMEM handling.
4718 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4719 SCTP_ERROR(ECONNREFUSED));
4720 /* Delete the established association. */
4721 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4722 SCTP_PERR(SCTP_ERROR_USER_ABORT));
4728 * sctp_sf_cookie_echoed_prm_abort
4730 * Section: 4 Note: 3
4735 * The RFC does not explcitly address this issue, but is the route through the
4736 * state table when someone issues an abort while in COOKIE_ECHOED state.
4741 sctp_disposition_t sctp_sf_cookie_echoed_prm_abort(
4742 const struct sctp_endpoint *ep,
4743 const struct sctp_association *asoc,
4744 const sctp_subtype_t type,
4746 sctp_cmd_seq_t *commands)
4748 /* There is a single T1 timer, so we should be able to use
4749 * common function with the COOKIE-WAIT state.
4751 return sctp_sf_cookie_wait_prm_abort(ep, asoc, type, arg, commands);
4755 * sctp_sf_shutdown_pending_prm_abort
4760 * The RFC does not explicitly address this issue, but is the route through the
4761 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
4766 sctp_disposition_t sctp_sf_shutdown_pending_prm_abort(
4767 const struct sctp_endpoint *ep,
4768 const struct sctp_association *asoc,
4769 const sctp_subtype_t type,
4771 sctp_cmd_seq_t *commands)
4773 /* Stop the T5-shutdown guard timer. */
4774 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4775 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4777 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
4781 * sctp_sf_shutdown_sent_prm_abort
4786 * The RFC does not explicitly address this issue, but is the route through the
4787 * state table when someone issues an abort while in SHUTDOWN-SENT state.
4792 sctp_disposition_t sctp_sf_shutdown_sent_prm_abort(
4793 const struct sctp_endpoint *ep,
4794 const struct sctp_association *asoc,
4795 const sctp_subtype_t type,
4797 sctp_cmd_seq_t *commands)
4799 /* Stop the T2-shutdown timer. */
4800 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4801 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4803 /* Stop the T5-shutdown guard timer. */
4804 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4805 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4807 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
4811 * sctp_sf_cookie_echoed_prm_abort
4816 * The RFC does not explcitly address this issue, but is the route through the
4817 * state table when someone issues an abort while in COOKIE_ECHOED state.
4822 sctp_disposition_t sctp_sf_shutdown_ack_sent_prm_abort(
4823 const struct sctp_endpoint *ep,
4824 const struct sctp_association *asoc,
4825 const sctp_subtype_t type,
4827 sctp_cmd_seq_t *commands)
4829 /* The same T2 timer, so we should be able to use
4830 * common function with the SHUTDOWN-SENT state.
4832 return sctp_sf_shutdown_sent_prm_abort(ep, asoc, type, arg, commands);
4836 * Process the REQUESTHEARTBEAT primitive
4839 * J) Request Heartbeat
4841 * Format: REQUESTHEARTBEAT(association id, destination transport address)
4845 * Instructs the local endpoint to perform a HeartBeat on the specified
4846 * destination transport address of the given association. The returned
4847 * result should indicate whether the transmission of the HEARTBEAT
4848 * chunk to the destination address is successful.
4850 * Mandatory attributes:
4852 * o association id - local handle to the SCTP association
4854 * o destination transport address - the transport address of the
4855 * association on which a heartbeat should be issued.
4857 sctp_disposition_t sctp_sf_do_prm_requestheartbeat(
4858 const struct sctp_endpoint *ep,
4859 const struct sctp_association *asoc,
4860 const sctp_subtype_t type,
4862 sctp_cmd_seq_t *commands)
4864 if (SCTP_DISPOSITION_NOMEM == sctp_sf_heartbeat(ep, asoc, type,
4865 (struct sctp_transport *)arg, commands))
4866 return SCTP_DISPOSITION_NOMEM;
4869 * RFC 2960 (bis), section 8.3
4871 * D) Request an on-demand HEARTBEAT on a specific destination
4872 * transport address of a given association.
4874 * The endpoint should increment the respective error counter of
4875 * the destination transport address each time a HEARTBEAT is sent
4876 * to that address and not acknowledged within one RTO.
4879 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET,
4880 SCTP_TRANSPORT(arg));
4881 return SCTP_DISPOSITION_CONSUME;
4885 * ADDIP Section 4.1 ASCONF Chunk Procedures
4886 * When an endpoint has an ASCONF signaled change to be sent to the
4887 * remote endpoint it should do A1 to A9
4889 sctp_disposition_t sctp_sf_do_prm_asconf(const struct sctp_endpoint *ep,
4890 const struct sctp_association *asoc,
4891 const sctp_subtype_t type,
4893 sctp_cmd_seq_t *commands)
4895 struct sctp_chunk *chunk = arg;
4897 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
4898 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4899 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4900 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
4901 return SCTP_DISPOSITION_CONSUME;
4905 * Ignore the primitive event
4907 * The return value is the disposition of the primitive.
4909 sctp_disposition_t sctp_sf_ignore_primitive(
4910 const struct sctp_endpoint *ep,
4911 const struct sctp_association *asoc,
4912 const sctp_subtype_t type,
4914 sctp_cmd_seq_t *commands)
4916 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type.primitive);
4917 return SCTP_DISPOSITION_DISCARD;
4920 /***************************************************************************
4921 * These are the state functions for the OTHER events.
4922 ***************************************************************************/
4925 * Start the shutdown negotiation.
4928 * Once all its outstanding data has been acknowledged, the endpoint
4929 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
4930 * TSN Ack field the last sequential TSN it has received from the peer.
4931 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
4932 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
4933 * with the updated last sequential TSN received from its peer.
4935 * The return value is the disposition.
4937 sctp_disposition_t sctp_sf_do_9_2_start_shutdown(
4938 const struct sctp_endpoint *ep,
4939 const struct sctp_association *asoc,
4940 const sctp_subtype_t type,
4942 sctp_cmd_seq_t *commands)
4944 struct sctp_chunk *reply;
4946 /* Once all its outstanding data has been acknowledged, the
4947 * endpoint shall send a SHUTDOWN chunk to its peer including
4948 * in the Cumulative TSN Ack field the last sequential TSN it
4949 * has received from the peer.
4951 reply = sctp_make_shutdown(asoc, NULL);
4955 /* Set the transport for the SHUTDOWN chunk and the timeout for the
4956 * T2-shutdown timer.
4958 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4960 /* It shall then start the T2-shutdown timer */
4961 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4962 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4964 if (asoc->autoclose)
4965 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4966 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
4968 /* and enter the SHUTDOWN-SENT state. */
4969 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4970 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT));
4972 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4974 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4977 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
4979 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4981 return SCTP_DISPOSITION_CONSUME;
4984 return SCTP_DISPOSITION_NOMEM;
4988 * Generate a SHUTDOWN ACK now that everything is SACK'd.
4992 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4993 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
4994 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
4995 * endpoint must re-send the SHUTDOWN ACK.
4997 * The return value is the disposition.
4999 sctp_disposition_t sctp_sf_do_9_2_shutdown_ack(
5000 const struct sctp_endpoint *ep,
5001 const struct sctp_association *asoc,
5002 const sctp_subtype_t type,
5004 sctp_cmd_seq_t *commands)
5006 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
5007 struct sctp_chunk *reply;
5009 /* There are 2 ways of getting here:
5010 * 1) called in response to a SHUTDOWN chunk
5011 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
5013 * For the case (2), the arg parameter is set to NULL. We need
5014 * to check that we have a chunk before accessing it's fields.
5017 if (!sctp_vtag_verify(chunk, asoc))
5018 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
5020 /* Make sure that the SHUTDOWN chunk has a valid length. */
5021 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk_t)))
5022 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
5026 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5027 * shall send a SHUTDOWN ACK ...
5029 reply = sctp_make_shutdown_ack(asoc, chunk);
5033 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
5034 * the T2-shutdown timer.
5036 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
5038 /* and start/restart a T2-shutdown timer of its own, */
5039 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
5040 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
5042 if (asoc->autoclose)
5043 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5044 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
5046 /* Enter the SHUTDOWN-ACK-SENT state. */
5047 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
5048 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT));
5050 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5052 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5055 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
5057 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
5059 return SCTP_DISPOSITION_CONSUME;
5062 return SCTP_DISPOSITION_NOMEM;
5066 * Ignore the event defined as other
5068 * The return value is the disposition of the event.
5070 sctp_disposition_t sctp_sf_ignore_other(const struct sctp_endpoint *ep,
5071 const struct sctp_association *asoc,
5072 const sctp_subtype_t type,
5074 sctp_cmd_seq_t *commands)
5076 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type.other);
5077 return SCTP_DISPOSITION_DISCARD;
5080 /************************************************************
5081 * These are the state functions for handling timeout events.
5082 ************************************************************/
5087 * Section: 6.3.3 Handle T3-rtx Expiration
5089 * Whenever the retransmission timer T3-rtx expires for a destination
5090 * address, do the following:
5093 * The return value is the disposition of the chunk.
5095 sctp_disposition_t sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint *ep,
5096 const struct sctp_association *asoc,
5097 const sctp_subtype_t type,
5099 sctp_cmd_seq_t *commands)
5101 struct sctp_transport *transport = arg;
5103 SCTP_INC_STATS(SCTP_MIB_T3_RTX_EXPIREDS);
5105 if (asoc->overall_error_count >= asoc->max_retrans) {
5106 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5107 SCTP_ERROR(ETIMEDOUT));
5108 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5109 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5110 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5111 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
5112 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
5113 return SCTP_DISPOSITION_DELETE_TCB;
5116 /* E1) For the destination address for which the timer
5117 * expires, adjust its ssthresh with rules defined in Section
5118 * 7.2.3 and set the cwnd <- MTU.
5121 /* E2) For the destination address for which the timer
5122 * expires, set RTO <- RTO * 2 ("back off the timer"). The
5123 * maximum value discussed in rule C7 above (RTO.max) may be
5124 * used to provide an upper bound to this doubling operation.
5127 /* E3) Determine how many of the earliest (i.e., lowest TSN)
5128 * outstanding DATA chunks for the address for which the
5129 * T3-rtx has expired will fit into a single packet, subject
5130 * to the MTU constraint for the path corresponding to the
5131 * destination transport address to which the retransmission
5132 * is being sent (this may be different from the address for
5133 * which the timer expires [see Section 6.4]). Call this
5134 * value K. Bundle and retransmit those K DATA chunks in a
5135 * single packet to the destination endpoint.
5137 * Note: Any DATA chunks that were sent to the address for
5138 * which the T3-rtx timer expired but did not fit in one MTU
5139 * (rule E3 above), should be marked for retransmission and
5140 * sent as soon as cwnd allows (normally when a SACK arrives).
5143 /* Do some failure management (Section 8.2). */
5144 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
5146 /* NB: Rules E4 and F1 are implicit in R1. */
5147 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport));
5149 return SCTP_DISPOSITION_CONSUME;
5153 * Generate delayed SACK on timeout
5155 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
5157 * The guidelines on delayed acknowledgement algorithm specified in
5158 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
5159 * acknowledgement SHOULD be generated for at least every second packet
5160 * (not every second DATA chunk) received, and SHOULD be generated
5161 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
5162 * some situations it may be beneficial for an SCTP transmitter to be
5163 * more conservative than the algorithms detailed in this document
5164 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
5165 * the following algorithms allow.
5167 sctp_disposition_t sctp_sf_do_6_2_sack(const struct sctp_endpoint *ep,
5168 const struct sctp_association *asoc,
5169 const sctp_subtype_t type,
5171 sctp_cmd_seq_t *commands)
5173 SCTP_INC_STATS(SCTP_MIB_DELAY_SACK_EXPIREDS);
5174 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
5175 return SCTP_DISPOSITION_CONSUME;
5179 * sctp_sf_t1_init_timer_expire
5181 * Section: 4 Note: 2
5186 * RFC 2960 Section 4 Notes
5187 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
5188 * and re-start the T1-init timer without changing state. This MUST
5189 * be repeated up to 'Max.Init.Retransmits' times. After that, the
5190 * endpoint MUST abort the initialization process and report the
5191 * error to SCTP user.
5197 sctp_disposition_t sctp_sf_t1_init_timer_expire(const struct sctp_endpoint *ep,
5198 const struct sctp_association *asoc,
5199 const sctp_subtype_t type,
5201 sctp_cmd_seq_t *commands)
5203 struct sctp_chunk *repl = NULL;
5204 struct sctp_bind_addr *bp;
5205 int attempts = asoc->init_err_counter + 1;
5207 SCTP_DEBUG_PRINTK("Timer T1 expired (INIT).\n");
5208 SCTP_INC_STATS(SCTP_MIB_T1_INIT_EXPIREDS);
5210 if (attempts <= asoc->max_init_attempts) {
5211 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
5212 repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0);
5214 return SCTP_DISPOSITION_NOMEM;
5216 /* Choose transport for INIT. */
5217 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
5220 /* Issue a sideeffect to do the needed accounting. */
5221 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART,
5222 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
5224 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
5226 SCTP_DEBUG_PRINTK("Giving up on INIT, attempts: %d"
5227 " max_init_attempts: %d\n",
5228 attempts, asoc->max_init_attempts);
5229 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5230 SCTP_ERROR(ETIMEDOUT));
5231 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
5232 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5233 return SCTP_DISPOSITION_DELETE_TCB;
5236 return SCTP_DISPOSITION_CONSUME;
5240 * sctp_sf_t1_cookie_timer_expire
5242 * Section: 4 Note: 2
5247 * RFC 2960 Section 4 Notes
5248 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
5249 * COOKIE ECHO and re-start the T1-cookie timer without changing
5250 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
5251 * After that, the endpoint MUST abort the initialization process and
5252 * report the error to SCTP user.
5258 sctp_disposition_t sctp_sf_t1_cookie_timer_expire(const struct sctp_endpoint *ep,
5259 const struct sctp_association *asoc,
5260 const sctp_subtype_t type,
5262 sctp_cmd_seq_t *commands)
5264 struct sctp_chunk *repl = NULL;
5265 int attempts = asoc->init_err_counter + 1;
5267 SCTP_DEBUG_PRINTK("Timer T1 expired (COOKIE-ECHO).\n");
5268 SCTP_INC_STATS(SCTP_MIB_T1_COOKIE_EXPIREDS);
5270 if (attempts <= asoc->max_init_attempts) {
5271 repl = sctp_make_cookie_echo(asoc, NULL);
5273 return SCTP_DISPOSITION_NOMEM;
5275 /* Issue a sideeffect to do the needed accounting. */
5276 sctp_add_cmd_sf(commands, SCTP_CMD_COOKIEECHO_RESTART,
5277 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
5279 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
5281 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5282 SCTP_ERROR(ETIMEDOUT));
5283 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
5284 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5285 return SCTP_DISPOSITION_DELETE_TCB;
5288 return SCTP_DISPOSITION_CONSUME;
5291 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
5292 * with the updated last sequential TSN received from its peer.
5294 * An endpoint should limit the number of retransmissions of the
5295 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
5296 * If this threshold is exceeded the endpoint should destroy the TCB and
5297 * MUST report the peer endpoint unreachable to the upper layer (and
5298 * thus the association enters the CLOSED state). The reception of any
5299 * packet from its peer (i.e. as the peer sends all of its queued DATA
5300 * chunks) should clear the endpoint's retransmission count and restart
5301 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
5302 * all of its queued DATA chunks that have not yet been sent.
5304 sctp_disposition_t sctp_sf_t2_timer_expire(const struct sctp_endpoint *ep,
5305 const struct sctp_association *asoc,
5306 const sctp_subtype_t type,
5308 sctp_cmd_seq_t *commands)
5310 struct sctp_chunk *reply = NULL;
5312 SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
5313 SCTP_INC_STATS(SCTP_MIB_T2_SHUTDOWN_EXPIREDS);
5315 if (asoc->overall_error_count >= asoc->max_retrans) {
5316 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5317 SCTP_ERROR(ETIMEDOUT));
5318 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5319 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5320 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5321 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
5322 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
5323 return SCTP_DISPOSITION_DELETE_TCB;
5326 switch (asoc->state) {
5327 case SCTP_STATE_SHUTDOWN_SENT:
5328 reply = sctp_make_shutdown(asoc, NULL);
5331 case SCTP_STATE_SHUTDOWN_ACK_SENT:
5332 reply = sctp_make_shutdown_ack(asoc, NULL);
5343 /* Do some failure management (Section 8.2). */
5344 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
5345 SCTP_TRANSPORT(asoc->shutdown_last_sent_to));
5347 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
5348 * the T2-shutdown timer.
5350 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
5352 /* Restart the T2-shutdown timer. */
5353 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
5354 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
5355 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
5356 return SCTP_DISPOSITION_CONSUME;
5359 return SCTP_DISPOSITION_NOMEM;
5363 * ADDIP Section 4.1 ASCONF CHunk Procedures
5364 * If the T4 RTO timer expires the endpoint should do B1 to B5
5366 sctp_disposition_t sctp_sf_t4_timer_expire(
5367 const struct sctp_endpoint *ep,
5368 const struct sctp_association *asoc,
5369 const sctp_subtype_t type,
5371 sctp_cmd_seq_t *commands)
5373 struct sctp_chunk *chunk = asoc->addip_last_asconf;
5374 struct sctp_transport *transport = chunk->transport;
5376 SCTP_INC_STATS(SCTP_MIB_T4_RTO_EXPIREDS);
5378 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
5379 * detection on the appropriate destination address as defined in
5380 * RFC2960 [5] section 8.1 and 8.2.
5382 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
5384 /* Reconfig T4 timer and transport. */
5385 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
5387 /* ADDIP 4.1 B2) Increment the association error counters and perform
5388 * endpoint failure detection on the association as defined in
5389 * RFC2960 [5] section 8.1 and 8.2.
5390 * association error counter is incremented in SCTP_CMD_STRIKE.
5392 if (asoc->overall_error_count >= asoc->max_retrans) {
5393 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5394 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
5395 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5396 SCTP_ERROR(ETIMEDOUT));
5397 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5398 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5399 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
5400 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
5401 return SCTP_DISPOSITION_ABORT;
5404 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
5405 * the ASCONF chunk was sent by doubling the RTO timer value.
5406 * This is done in SCTP_CMD_STRIKE.
5409 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
5410 * choose an alternate destination address (please refer to RFC2960
5411 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
5412 * chunk, it MUST be the same (including its serial number) as the last
5415 sctp_chunk_hold(asoc->addip_last_asconf);
5416 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
5417 SCTP_CHUNK(asoc->addip_last_asconf));
5419 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
5420 * destination is selected, then the RTO used will be that of the new
5421 * destination address.
5423 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
5424 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
5426 return SCTP_DISPOSITION_CONSUME;
5429 /* sctpimpguide-05 Section 2.12.2
5430 * The sender of the SHUTDOWN MAY also start an overall guard timer
5431 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5432 * At the expiration of this timer the sender SHOULD abort the association
5433 * by sending an ABORT chunk.
5435 sctp_disposition_t sctp_sf_t5_timer_expire(const struct sctp_endpoint *ep,
5436 const struct sctp_association *asoc,
5437 const sctp_subtype_t type,
5439 sctp_cmd_seq_t *commands)
5441 struct sctp_chunk *reply = NULL;
5443 SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
5444 SCTP_INC_STATS(SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS);
5446 reply = sctp_make_abort(asoc, NULL, 0);
5450 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
5451 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5452 SCTP_ERROR(ETIMEDOUT));
5453 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5454 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5456 return SCTP_DISPOSITION_DELETE_TCB;
5458 return SCTP_DISPOSITION_NOMEM;
5461 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
5462 * the association is automatically closed by starting the shutdown process.
5463 * The work that needs to be done is same as when SHUTDOWN is initiated by
5464 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
5466 sctp_disposition_t sctp_sf_autoclose_timer_expire(
5467 const struct sctp_endpoint *ep,
5468 const struct sctp_association *asoc,
5469 const sctp_subtype_t type,
5471 sctp_cmd_seq_t *commands)
5475 SCTP_INC_STATS(SCTP_MIB_AUTOCLOSE_EXPIREDS);
5477 /* From 9.2 Shutdown of an Association
5478 * Upon receipt of the SHUTDOWN primitive from its upper
5479 * layer, the endpoint enters SHUTDOWN-PENDING state and
5480 * remains there until all outstanding data has been
5481 * acknowledged by its peer. The endpoint accepts no new data
5482 * from its upper layer, but retransmits data to the far end
5483 * if necessary to fill gaps.
5485 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
5486 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
5488 /* sctpimpguide-05 Section 2.12.2
5489 * The sender of the SHUTDOWN MAY also start an overall guard timer
5490 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5492 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
5493 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
5494 disposition = SCTP_DISPOSITION_CONSUME;
5495 if (sctp_outq_is_empty(&asoc->outqueue)) {
5496 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
5502 /*****************************************************************************
5503 * These are sa state functions which could apply to all types of events.
5504 ****************************************************************************/
5507 * This table entry is not implemented.
5510 * (endpoint, asoc, chunk)
5512 * The return value is the disposition of the chunk.
5514 sctp_disposition_t sctp_sf_not_impl(const struct sctp_endpoint *ep,
5515 const struct sctp_association *asoc,
5516 const sctp_subtype_t type,
5518 sctp_cmd_seq_t *commands)
5520 return SCTP_DISPOSITION_NOT_IMPL;
5524 * This table entry represents a bug.
5527 * (endpoint, asoc, chunk)
5529 * The return value is the disposition of the chunk.
5531 sctp_disposition_t sctp_sf_bug(const struct sctp_endpoint *ep,
5532 const struct sctp_association *asoc,
5533 const sctp_subtype_t type,
5535 sctp_cmd_seq_t *commands)
5537 return SCTP_DISPOSITION_BUG;
5541 * This table entry represents the firing of a timer in the wrong state.
5542 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
5543 * when the association is in the wrong state. This event should
5544 * be ignored, so as to prevent any rearming of the timer.
5547 * (endpoint, asoc, chunk)
5549 * The return value is the disposition of the chunk.
5551 sctp_disposition_t sctp_sf_timer_ignore(const struct sctp_endpoint *ep,
5552 const struct sctp_association *asoc,
5553 const sctp_subtype_t type,
5555 sctp_cmd_seq_t *commands)
5557 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type.chunk);
5558 return SCTP_DISPOSITION_CONSUME;
5561 /********************************************************************
5562 * 2nd Level Abstractions
5563 ********************************************************************/
5565 /* Pull the SACK chunk based on the SACK header. */
5566 static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk)
5568 struct sctp_sackhdr *sack;
5573 /* Protect ourselves from reading too far into
5574 * the skb from a bogus sender.
5576 sack = (struct sctp_sackhdr *) chunk->skb->data;
5578 num_blocks = ntohs(sack->num_gap_ack_blocks);
5579 num_dup_tsns = ntohs(sack->num_dup_tsns);
5580 len = sizeof(struct sctp_sackhdr);
5581 len += (num_blocks + num_dup_tsns) * sizeof(__u32);
5582 if (len > chunk->skb->len)
5585 skb_pull(chunk->skb, len);
5590 /* Create an ABORT packet to be sent as a response, with the specified
5593 static struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep,
5594 const struct sctp_association *asoc,
5595 struct sctp_chunk *chunk,
5596 const void *payload,
5599 struct sctp_packet *packet;
5600 struct sctp_chunk *abort;
5602 packet = sctp_ootb_pkt_new(asoc, chunk);
5606 * The T bit will be set if the asoc is NULL.
5608 abort = sctp_make_abort(asoc, chunk, paylen);
5610 sctp_ootb_pkt_free(packet);
5614 /* Reflect vtag if T-Bit is set */
5615 if (sctp_test_T_bit(abort))
5616 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
5618 /* Add specified error causes, i.e., payload, to the
5621 sctp_addto_chunk(abort, paylen, payload);
5623 /* Set the skb to the belonging sock for accounting. */
5624 abort->skb->sk = ep->base.sk;
5626 sctp_packet_append_chunk(packet, abort);
5633 /* Allocate a packet for responding in the OOTB conditions. */
5634 static struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc,
5635 const struct sctp_chunk *chunk)
5637 struct sctp_packet *packet;
5638 struct sctp_transport *transport;
5643 /* Get the source and destination port from the inbound packet. */
5644 sport = ntohs(chunk->sctp_hdr->dest);
5645 dport = ntohs(chunk->sctp_hdr->source);
5647 /* The V-tag is going to be the same as the inbound packet if no
5648 * association exists, otherwise, use the peer's vtag.
5651 /* Special case the INIT-ACK as there is no peer's vtag
5654 switch(chunk->chunk_hdr->type) {
5655 case SCTP_CID_INIT_ACK:
5657 sctp_initack_chunk_t *initack;
5659 initack = (sctp_initack_chunk_t *)chunk->chunk_hdr;
5660 vtag = ntohl(initack->init_hdr.init_tag);
5664 vtag = asoc->peer.i.init_tag;
5668 /* Special case the INIT and stale COOKIE_ECHO as there is no
5671 switch(chunk->chunk_hdr->type) {
5674 sctp_init_chunk_t *init;
5676 init = (sctp_init_chunk_t *)chunk->chunk_hdr;
5677 vtag = ntohl(init->init_hdr.init_tag);
5681 vtag = ntohl(chunk->sctp_hdr->vtag);
5686 /* Make a transport for the bucket, Eliza... */
5687 transport = sctp_transport_new(sctp_source(chunk), GFP_ATOMIC);
5691 /* Cache a route for the transport with the chunk's destination as
5692 * the source address.
5694 sctp_transport_route(transport, (union sctp_addr *)&chunk->dest,
5695 sctp_sk(sctp_get_ctl_sock()));
5697 packet = sctp_packet_init(&transport->packet, transport, sport, dport);
5698 packet = sctp_packet_config(packet, vtag, 0);
5706 /* Free the packet allocated earlier for responding in the OOTB condition. */
5707 void sctp_ootb_pkt_free(struct sctp_packet *packet)
5709 sctp_transport_free(packet->transport);
5712 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
5713 static void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep,
5714 const struct sctp_association *asoc,
5715 const struct sctp_chunk *chunk,
5716 sctp_cmd_seq_t *commands,
5717 struct sctp_chunk *err_chunk)
5719 struct sctp_packet *packet;
5722 packet = sctp_ootb_pkt_new(asoc, chunk);
5724 struct sctp_signed_cookie *cookie;
5726 /* Override the OOTB vtag from the cookie. */
5727 cookie = chunk->subh.cookie_hdr;
5728 packet->vtag = cookie->c.peer_vtag;
5730 /* Set the skb to the belonging sock for accounting. */
5731 err_chunk->skb->sk = ep->base.sk;
5732 sctp_packet_append_chunk(packet, err_chunk);
5733 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
5734 SCTP_PACKET(packet));
5735 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
5737 sctp_chunk_free (err_chunk);
5742 /* Process a data chunk */
5743 static int sctp_eat_data(const struct sctp_association *asoc,
5744 struct sctp_chunk *chunk,
5745 sctp_cmd_seq_t *commands)
5747 sctp_datahdr_t *data_hdr;
5748 struct sctp_chunk *err;
5750 sctp_verb_t deliver;
5753 struct sctp_tsnmap *map = (struct sctp_tsnmap *)&asoc->peer.tsn_map;
5754 struct sock *sk = asoc->base.sk;
5756 data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *)chunk->skb->data;
5757 skb_pull(chunk->skb, sizeof(sctp_datahdr_t));
5759 tsn = ntohl(data_hdr->tsn);
5760 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn);
5762 /* ASSERT: Now skb->data is really the user data. */
5764 /* Process ECN based congestion.
5766 * Since the chunk structure is reused for all chunks within
5767 * a packet, we use ecn_ce_done to track if we've already
5768 * done CE processing for this packet.
5770 * We need to do ECN processing even if we plan to discard the
5774 if (!chunk->ecn_ce_done) {
5776 chunk->ecn_ce_done = 1;
5778 af = sctp_get_af_specific(
5779 ipver2af(ip_hdr(chunk->skb)->version));
5781 if (af && af->is_ce(chunk->skb) && asoc->peer.ecn_capable) {
5782 /* Do real work as sideffect. */
5783 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
5788 tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
5790 /* The TSN is too high--silently discard the chunk and
5791 * count on it getting retransmitted later.
5793 return SCTP_IERROR_HIGH_TSN;
5794 } else if (tmp > 0) {
5795 /* This is a duplicate. Record it. */
5796 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
5797 return SCTP_IERROR_DUP_TSN;
5800 /* This is a new TSN. */
5802 /* Discard if there is no room in the receive window.
5803 * Actually, allow a little bit of overflow (up to a MTU).
5805 datalen = ntohs(chunk->chunk_hdr->length);
5806 datalen -= sizeof(sctp_data_chunk_t);
5808 deliver = SCTP_CMD_CHUNK_ULP;
5810 /* Think about partial delivery. */
5811 if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) {
5813 /* Even if we don't accept this chunk there is
5816 sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL());
5819 /* Spill over rwnd a little bit. Note: While allowed, this spill over
5820 * seems a bit troublesome in that frag_point varies based on
5821 * PMTU. In cases, such as loopback, this might be a rather
5824 if ((!chunk->data_accepted) && (!asoc->rwnd || asoc->rwnd_over ||
5825 (datalen > asoc->rwnd + asoc->frag_point))) {
5827 /* If this is the next TSN, consider reneging to make
5828 * room. Note: Playing nice with a confused sender. A
5829 * malicious sender can still eat up all our buffer
5830 * space and in the future we may want to detect and
5831 * do more drastic reneging.
5833 if (sctp_tsnmap_has_gap(map) &&
5834 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
5835 SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn);
5836 deliver = SCTP_CMD_RENEGE;
5838 SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
5839 "rwnd: %d\n", tsn, datalen,
5841 return SCTP_IERROR_IGNORE_TSN;
5846 * Also try to renege to limit our memory usage in the event that
5847 * we are under memory pressure
5848 * If we can't renege, don't worry about it, the sk_stream_rmem_schedule
5849 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
5850 * memory usage too much
5852 if (*sk->sk_prot_creator->memory_pressure) {
5853 if (sctp_tsnmap_has_gap(map) &&
5854 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
5855 SCTP_DEBUG_PRINTK("Under Pressure! Reneging for tsn:%u\n", tsn);
5856 deliver = SCTP_CMD_RENEGE;
5861 * Section 3.3.10.9 No User Data (9)
5865 * No User Data: This error cause is returned to the originator of a
5866 * DATA chunk if a received DATA chunk has no user data.
5868 if (unlikely(0 == datalen)) {
5869 err = sctp_make_abort_no_data(asoc, chunk, tsn);
5871 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
5874 /* We are going to ABORT, so we might as well stop
5875 * processing the rest of the chunks in the packet.
5877 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
5878 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5879 SCTP_ERROR(ECONNABORTED));
5880 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5881 SCTP_PERR(SCTP_ERROR_NO_DATA));
5882 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
5883 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
5884 return SCTP_IERROR_NO_DATA;
5887 /* If definately accepting the DATA chunk, record its TSN, otherwise
5888 * wait for renege processing.
5890 if (SCTP_CMD_CHUNK_ULP == deliver)
5891 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
5893 chunk->data_accepted = 1;
5895 /* Note: Some chunks may get overcounted (if we drop) or overcounted
5896 * if we renege and the chunk arrives again.
5898 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
5899 SCTP_INC_STATS(SCTP_MIB_INUNORDERCHUNKS);
5901 SCTP_INC_STATS(SCTP_MIB_INORDERCHUNKS);
5903 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
5905 * If an endpoint receive a DATA chunk with an invalid stream
5906 * identifier, it shall acknowledge the reception of the DATA chunk
5907 * following the normal procedure, immediately send an ERROR chunk
5908 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
5909 * and discard the DATA chunk.
5911 if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) {
5912 err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
5914 sizeof(data_hdr->stream));
5916 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
5918 return SCTP_IERROR_BAD_STREAM;
5921 /* Send the data up to the user. Note: Schedule the
5922 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
5923 * chunk needs the updated rwnd.
5925 sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk));
5927 return SCTP_IERROR_NO_ERROR;