1 /* SCTP kernel implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001-2002 Intel Corp.
6 * Copyright (c) 2002 Nokia Corp.
8 * This is part of the SCTP Linux Kernel Implementation.
10 * These are the state functions for the state machine.
12 * This SCTP implementation is free software;
13 * you can redistribute it and/or modify it under the terms of
14 * the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * This SCTP implementation is distributed in the hope that it
19 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
20 * ************************
21 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 * See the GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with GNU CC; see the file COPYING. If not, see
26 * <http://www.gnu.org/licenses/>.
28 * Please send any bug reports or fixes you make to the
30 * lksctp developers <linux-sctp@vger.kernel.org>
32 * Written or modified by:
33 * La Monte H.P. Yarroll <piggy@acm.org>
34 * Karl Knutson <karl@athena.chicago.il.us>
35 * Mathew Kotowsky <kotowsky@sctp.org>
36 * Sridhar Samudrala <samudrala@us.ibm.com>
37 * Jon Grimm <jgrimm@us.ibm.com>
38 * Hui Huang <hui.huang@nokia.com>
39 * Dajiang Zhang <dajiang.zhang@nokia.com>
40 * Daisy Chang <daisyc@us.ibm.com>
41 * Ardelle Fan <ardelle.fan@intel.com>
42 * Ryan Layer <rmlayer@us.ibm.com>
43 * Kevin Gao <kevin.gao@intel.com>
46 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
48 #include <linux/types.h>
49 #include <linux/kernel.h>
51 #include <linux/ipv6.h>
52 #include <linux/net.h>
53 #include <linux/inet.h>
54 #include <linux/slab.h>
56 #include <net/inet_ecn.h>
57 #include <linux/skbuff.h>
58 #include <net/sctp/sctp.h>
59 #include <net/sctp/sm.h>
60 #include <net/sctp/structs.h>
62 #define CREATE_TRACE_POINTS
63 #include <trace/events/sctp.h>
65 static struct sctp_packet *sctp_abort_pkt_new(
67 const struct sctp_endpoint *ep,
68 const struct sctp_association *asoc,
69 struct sctp_chunk *chunk,
70 const void *payload, size_t paylen);
71 static int sctp_eat_data(const struct sctp_association *asoc,
72 struct sctp_chunk *chunk,
73 struct sctp_cmd_seq *commands);
74 static struct sctp_packet *sctp_ootb_pkt_new(
76 const struct sctp_association *asoc,
77 const struct sctp_chunk *chunk);
78 static void sctp_send_stale_cookie_err(struct net *net,
79 const struct sctp_endpoint *ep,
80 const struct sctp_association *asoc,
81 const struct sctp_chunk *chunk,
82 struct sctp_cmd_seq *commands,
83 struct sctp_chunk *err_chunk);
84 static enum sctp_disposition sctp_sf_do_5_2_6_stale(
86 const struct sctp_endpoint *ep,
87 const struct sctp_association *asoc,
88 const union sctp_subtype type,
90 struct sctp_cmd_seq *commands);
91 static enum sctp_disposition sctp_sf_shut_8_4_5(
93 const struct sctp_endpoint *ep,
94 const struct sctp_association *asoc,
95 const union sctp_subtype type,
97 struct sctp_cmd_seq *commands);
98 static enum sctp_disposition sctp_sf_tabort_8_4_8(
100 const struct sctp_endpoint *ep,
101 const struct sctp_association *asoc,
102 const union sctp_subtype type,
104 struct sctp_cmd_seq *commands);
105 static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk);
107 static enum sctp_disposition sctp_stop_t1_and_abort(
109 struct sctp_cmd_seq *commands,
110 __be16 error, int sk_err,
111 const struct sctp_association *asoc,
112 struct sctp_transport *transport);
114 static enum sctp_disposition sctp_sf_abort_violation(
116 const struct sctp_endpoint *ep,
117 const struct sctp_association *asoc,
119 struct sctp_cmd_seq *commands,
121 const size_t paylen);
123 static enum sctp_disposition sctp_sf_violation_chunklen(
125 const struct sctp_endpoint *ep,
126 const struct sctp_association *asoc,
127 const union sctp_subtype type,
129 struct sctp_cmd_seq *commands);
131 static enum sctp_disposition sctp_sf_violation_paramlen(
133 const struct sctp_endpoint *ep,
134 const struct sctp_association *asoc,
135 const union sctp_subtype type,
136 void *arg, void *ext,
137 struct sctp_cmd_seq *commands);
139 static enum sctp_disposition sctp_sf_violation_ctsn(
141 const struct sctp_endpoint *ep,
142 const struct sctp_association *asoc,
143 const union sctp_subtype type,
145 struct sctp_cmd_seq *commands);
147 static enum sctp_disposition sctp_sf_violation_chunk(
149 const struct sctp_endpoint *ep,
150 const struct sctp_association *asoc,
151 const union sctp_subtype type,
153 struct sctp_cmd_seq *commands);
155 static enum sctp_ierror sctp_sf_authenticate(
156 const struct sctp_association *asoc,
157 struct sctp_chunk *chunk);
159 static enum sctp_disposition __sctp_sf_do_9_1_abort(
161 const struct sctp_endpoint *ep,
162 const struct sctp_association *asoc,
163 const union sctp_subtype type,
165 struct sctp_cmd_seq *commands);
167 /* Small helper function that checks if the chunk length
168 * is of the appropriate length. The 'required_length' argument
169 * is set to be the size of a specific chunk we are testing.
170 * Return Values: true = Valid length
171 * false = Invalid length
174 static inline bool sctp_chunk_length_valid(struct sctp_chunk *chunk,
175 __u16 required_length)
177 __u16 chunk_length = ntohs(chunk->chunk_hdr->length);
179 /* Previously already marked? */
180 if (unlikely(chunk->pdiscard))
182 if (unlikely(chunk_length < required_length))
188 /* Check for format error in an ABORT chunk */
189 static inline bool sctp_err_chunk_valid(struct sctp_chunk *chunk)
191 struct sctp_errhdr *err;
193 sctp_walk_errors(err, chunk->chunk_hdr);
195 return (void *)err == (void *)chunk->chunk_end;
198 /**********************************************************
199 * These are the state functions for handling chunk events.
200 **********************************************************/
203 * Process the final SHUTDOWN COMPLETE.
205 * Section: 4 (C) (diagram), 9.2
206 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
207 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
208 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
209 * should stop the T2-shutdown timer and remove all knowledge of the
210 * association (and thus the association enters the CLOSED state).
212 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
213 * C) Rules for packet carrying SHUTDOWN COMPLETE:
215 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
216 * if the Verification Tag field of the packet matches its own tag and
217 * the T bit is not set
219 * it is set to its peer's tag and the T bit is set in the Chunk
221 * Otherwise, the receiver MUST silently discard the packet
222 * and take no further action. An endpoint MUST ignore the
223 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
226 * (endpoint, asoc, chunk)
229 * (asoc, reply_msg, msg_up, timers, counters)
231 * The return value is the disposition of the chunk.
233 enum sctp_disposition sctp_sf_do_4_C(struct net *net,
234 const struct sctp_endpoint *ep,
235 const struct sctp_association *asoc,
236 const union sctp_subtype type,
237 void *arg, struct sctp_cmd_seq *commands)
239 struct sctp_chunk *chunk = arg;
240 struct sctp_ulpevent *ev;
242 if (!sctp_vtag_verify_either(chunk, asoc))
243 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
245 /* RFC 2960 6.10 Bundling
247 * An endpoint MUST NOT bundle INIT, INIT ACK or
248 * SHUTDOWN COMPLETE with any other chunks.
250 if (!chunk->singleton)
251 return sctp_sf_violation_chunk(net, ep, asoc, type, arg, commands);
253 /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */
254 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
255 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
258 /* RFC 2960 10.2 SCTP-to-ULP
260 * H) SHUTDOWN COMPLETE notification
262 * When SCTP completes the shutdown procedures (section 9.2) this
263 * notification is passed to the upper layer.
265 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
266 0, 0, 0, NULL, GFP_ATOMIC);
268 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
271 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
272 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
273 * not the chunk should be discarded. If the endpoint is in
274 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
275 * T2-shutdown timer and remove all knowledge of the
276 * association (and thus the association enters the CLOSED
279 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
280 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
282 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
283 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
285 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
286 SCTP_STATE(SCTP_STATE_CLOSED));
288 SCTP_INC_STATS(net, SCTP_MIB_SHUTDOWNS);
289 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
291 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
293 return SCTP_DISPOSITION_DELETE_TCB;
297 * Respond to a normal INIT chunk.
298 * We are the side that is being asked for an association.
300 * Section: 5.1 Normal Establishment of an Association, B
301 * B) "Z" shall respond immediately with an INIT ACK chunk. The
302 * destination IP address of the INIT ACK MUST be set to the source
303 * IP address of the INIT to which this INIT ACK is responding. In
304 * the response, besides filling in other parameters, "Z" must set the
305 * Verification Tag field to Tag_A, and also provide its own
306 * Verification Tag (Tag_Z) in the Initiate Tag field.
308 * Verification Tag: Must be 0.
311 * (endpoint, asoc, chunk)
314 * (asoc, reply_msg, msg_up, timers, counters)
316 * The return value is the disposition of the chunk.
318 enum sctp_disposition sctp_sf_do_5_1B_init(struct net *net,
319 const struct sctp_endpoint *ep,
320 const struct sctp_association *asoc,
321 const union sctp_subtype type,
323 struct sctp_cmd_seq *commands)
325 struct sctp_chunk *chunk = arg, *repl, *err_chunk;
326 struct sctp_unrecognized_param *unk_param;
327 struct sctp_association *new_asoc;
328 struct sctp_packet *packet;
331 /* Update socket peer label if first association. */
332 if (security_sctp_assoc_request((struct sctp_endpoint *)ep,
334 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
337 * An endpoint MUST NOT bundle INIT, INIT ACK or
338 * SHUTDOWN COMPLETE with any other chunks.
341 * Furthermore, we require that the receiver of an INIT chunk MUST
342 * enforce these rules by silently discarding an arriving packet
343 * with an INIT chunk that is bundled with other chunks.
345 if (!chunk->singleton)
346 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
348 /* If the packet is an OOTB packet which is temporarily on the
349 * control endpoint, respond with an ABORT.
351 if (ep == sctp_sk(net->sctp.ctl_sock)->ep) {
352 SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES);
353 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
356 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
359 if (chunk->sctp_hdr->vtag != 0)
360 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
362 /* Make sure that the INIT chunk has a valid length.
363 * Normally, this would cause an ABORT with a Protocol Violation
364 * error, but since we don't have an association, we'll
365 * just discard the packet.
367 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_init_chunk)))
368 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
370 /* If the INIT is coming toward a closing socket, we'll send back
371 * and ABORT. Essentially, this catches the race of INIT being
372 * backloged to the socket at the same time as the user isses close().
373 * Since the socket and all its associations are going away, we
374 * can treat this OOTB
376 if (sctp_sstate(ep->base.sk, CLOSING))
377 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
379 /* Verify the INIT chunk before processing it. */
381 if (!sctp_verify_init(net, ep, asoc, chunk->chunk_hdr->type,
382 (struct sctp_init_chunk *)chunk->chunk_hdr, chunk,
384 /* This chunk contains fatal error. It is to be discarded.
385 * Send an ABORT, with causes if there is any.
388 packet = sctp_abort_pkt_new(net, ep, asoc, arg,
389 (__u8 *)(err_chunk->chunk_hdr) +
390 sizeof(struct sctp_chunkhdr),
391 ntohs(err_chunk->chunk_hdr->length) -
392 sizeof(struct sctp_chunkhdr));
394 sctp_chunk_free(err_chunk);
397 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
398 SCTP_PACKET(packet));
399 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
400 return SCTP_DISPOSITION_CONSUME;
402 return SCTP_DISPOSITION_NOMEM;
405 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg,
410 /* Grab the INIT header. */
411 chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data;
413 /* Tag the variable length parameters. */
414 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(struct sctp_inithdr));
416 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
420 if (sctp_assoc_set_bind_addr_from_ep(new_asoc,
421 sctp_scope(sctp_source(chunk)),
425 /* The call, sctp_process_init(), can fail on memory allocation. */
426 if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk),
427 (struct sctp_init_chunk *)chunk->chunk_hdr,
431 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
433 /* If there are errors need to be reported for unknown parameters,
434 * make sure to reserve enough room in the INIT ACK for them.
438 len = ntohs(err_chunk->chunk_hdr->length) -
439 sizeof(struct sctp_chunkhdr);
441 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
445 /* If there are errors need to be reported for unknown parameters,
446 * include them in the outgoing INIT ACK as "Unrecognized parameter"
450 /* Get the "Unrecognized parameter" parameter(s) out of the
451 * ERROR chunk generated by sctp_verify_init(). Since the
452 * error cause code for "unknown parameter" and the
453 * "Unrecognized parameter" type is the same, we can
454 * construct the parameters in INIT ACK by copying the
457 unk_param = (struct sctp_unrecognized_param *)
458 ((__u8 *)(err_chunk->chunk_hdr) +
459 sizeof(struct sctp_chunkhdr));
460 /* Replace the cause code with the "Unrecognized parameter"
463 sctp_addto_chunk(repl, len, unk_param);
464 sctp_chunk_free(err_chunk);
467 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
469 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
472 * Note: After sending out INIT ACK with the State Cookie parameter,
473 * "Z" MUST NOT allocate any resources, nor keep any states for the
474 * new association. Otherwise, "Z" will be vulnerable to resource
477 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
479 return SCTP_DISPOSITION_DELETE_TCB;
482 sctp_association_free(new_asoc);
485 sctp_chunk_free(err_chunk);
486 return SCTP_DISPOSITION_NOMEM;
490 * Respond to a normal INIT ACK chunk.
491 * We are the side that is initiating the association.
493 * Section: 5.1 Normal Establishment of an Association, C
494 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
495 * timer and leave COOKIE-WAIT state. "A" shall then send the State
496 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
497 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
499 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
500 * DATA chunks, but it MUST be the first chunk in the packet and
501 * until the COOKIE ACK is returned the sender MUST NOT send any
502 * other packets to the peer.
504 * Verification Tag: 3.3.3
505 * If the value of the Initiate Tag in a received INIT ACK chunk is
506 * found to be 0, the receiver MUST treat it as an error and close the
507 * association by transmitting an ABORT.
510 * (endpoint, asoc, chunk)
513 * (asoc, reply_msg, msg_up, timers, counters)
515 * The return value is the disposition of the chunk.
517 enum sctp_disposition sctp_sf_do_5_1C_ack(struct net *net,
518 const struct sctp_endpoint *ep,
519 const struct sctp_association *asoc,
520 const union sctp_subtype type,
522 struct sctp_cmd_seq *commands)
524 struct sctp_init_chunk *initchunk;
525 struct sctp_chunk *chunk = arg;
526 struct sctp_chunk *err_chunk;
527 struct sctp_packet *packet;
529 if (!sctp_vtag_verify(chunk, asoc))
530 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
533 * An endpoint MUST NOT bundle INIT, INIT ACK or
534 * SHUTDOWN COMPLETE with any other chunks.
536 if (!chunk->singleton)
537 return sctp_sf_violation_chunk(net, ep, asoc, type, arg, commands);
539 /* Make sure that the INIT-ACK chunk has a valid length */
540 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_initack_chunk)))
541 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
543 /* Grab the INIT header. */
544 chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data;
546 /* Verify the INIT chunk before processing it. */
548 if (!sctp_verify_init(net, ep, asoc, chunk->chunk_hdr->type,
549 (struct sctp_init_chunk *)chunk->chunk_hdr, chunk,
552 enum sctp_error error = SCTP_ERROR_NO_RESOURCE;
554 /* This chunk contains fatal error. It is to be discarded.
555 * Send an ABORT, with causes. If there are no causes,
556 * then there wasn't enough memory. Just terminate
560 packet = sctp_abort_pkt_new(net, ep, asoc, arg,
561 (__u8 *)(err_chunk->chunk_hdr) +
562 sizeof(struct sctp_chunkhdr),
563 ntohs(err_chunk->chunk_hdr->length) -
564 sizeof(struct sctp_chunkhdr));
566 sctp_chunk_free(err_chunk);
569 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
570 SCTP_PACKET(packet));
571 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
572 error = SCTP_ERROR_INV_PARAM;
576 /* SCTP-AUTH, Section 6.3:
577 * It should be noted that if the receiver wants to tear
578 * down an association in an authenticated way only, the
579 * handling of malformed packets should not result in
580 * tearing down the association.
582 * This means that if we only want to abort associations
583 * in an authenticated way (i.e AUTH+ABORT), then we
584 * can't destroy this association just because the packet
587 if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
588 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
590 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
591 return sctp_stop_t1_and_abort(net, commands, error, ECONNREFUSED,
592 asoc, chunk->transport);
595 /* Tag the variable length parameters. Note that we never
596 * convert the parameters in an INIT chunk.
598 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(struct sctp_inithdr));
600 initchunk = (struct sctp_init_chunk *)chunk->chunk_hdr;
602 sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT,
603 SCTP_PEER_INIT(initchunk));
605 /* Reset init error count upon receipt of INIT-ACK. */
606 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
608 /* 5.1 C) "A" shall stop the T1-init timer and leave
609 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
610 * timer, and enter the COOKIE-ECHOED state.
612 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
613 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
614 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
615 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
616 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
617 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED));
619 /* SCTP-AUTH: genereate the assocition shared keys so that
620 * we can potentially signe the COOKIE-ECHO.
622 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_SHKEY, SCTP_NULL());
624 /* 5.1 C) "A" shall then send the State Cookie received in the
625 * INIT ACK chunk in a COOKIE ECHO chunk, ...
627 /* If there is any errors to report, send the ERROR chunk generated
628 * for unknown parameters as well.
630 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO,
631 SCTP_CHUNK(err_chunk));
633 return SCTP_DISPOSITION_CONSUME;
636 static bool sctp_auth_chunk_verify(struct net *net, struct sctp_chunk *chunk,
637 const struct sctp_association *asoc)
639 struct sctp_chunk auth;
641 if (!chunk->auth_chunk)
644 /* SCTP-AUTH: auth_chunk pointer is only set when the cookie-echo
645 * is supposed to be authenticated and we have to do delayed
646 * authentication. We've just recreated the association using
647 * the information in the cookie and now it's much easier to
648 * do the authentication.
651 /* Make sure that we and the peer are AUTH capable */
652 if (!net->sctp.auth_enable || !asoc->peer.auth_capable)
655 /* set-up our fake chunk so that we can process it */
656 auth.skb = chunk->auth_chunk;
657 auth.asoc = chunk->asoc;
658 auth.sctp_hdr = chunk->sctp_hdr;
659 auth.chunk_hdr = (struct sctp_chunkhdr *)
660 skb_push(chunk->auth_chunk,
661 sizeof(struct sctp_chunkhdr));
662 skb_pull(chunk->auth_chunk, sizeof(struct sctp_chunkhdr));
663 auth.transport = chunk->transport;
665 return sctp_sf_authenticate(asoc, &auth) == SCTP_IERROR_NO_ERROR;
669 * Respond to a normal COOKIE ECHO chunk.
670 * We are the side that is being asked for an association.
672 * Section: 5.1 Normal Establishment of an Association, D
673 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
674 * with a COOKIE ACK chunk after building a TCB and moving to
675 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
676 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
677 * chunk MUST be the first chunk in the packet.
679 * IMPLEMENTATION NOTE: An implementation may choose to send the
680 * Communication Up notification to the SCTP user upon reception
681 * of a valid COOKIE ECHO chunk.
683 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
684 * D) Rules for packet carrying a COOKIE ECHO
686 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
687 * Initial Tag received in the INIT ACK.
689 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
692 * (endpoint, asoc, chunk)
695 * (asoc, reply_msg, msg_up, timers, counters)
697 * The return value is the disposition of the chunk.
699 enum sctp_disposition sctp_sf_do_5_1D_ce(struct net *net,
700 const struct sctp_endpoint *ep,
701 const struct sctp_association *asoc,
702 const union sctp_subtype type,
704 struct sctp_cmd_seq *commands)
706 struct sctp_ulpevent *ev, *ai_ev = NULL, *auth_ev = NULL;
707 struct sctp_association *new_asoc;
708 struct sctp_init_chunk *peer_init;
709 struct sctp_chunk *chunk = arg;
710 struct sctp_chunk *err_chk_p;
711 struct sctp_chunk *repl;
715 /* If the packet is an OOTB packet which is temporarily on the
716 * control endpoint, respond with an ABORT.
718 if (ep == sctp_sk(net->sctp.ctl_sock)->ep) {
719 SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES);
720 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
723 /* Make sure that the COOKIE_ECHO chunk has a valid length.
724 * In this case, we check that we have enough for at least a
725 * chunk header. More detailed verification is done
726 * in sctp_unpack_cookie().
728 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
729 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
731 /* If the endpoint is not listening or if the number of associations
732 * on the TCP-style socket exceed the max backlog, respond with an
736 if (!sctp_sstate(sk, LISTENING) ||
737 (sctp_style(sk, TCP) && sk_acceptq_is_full(sk)))
738 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
740 /* "Decode" the chunk. We have no optional parameters so we
743 chunk->subh.cookie_hdr =
744 (struct sctp_signed_cookie *)chunk->skb->data;
745 if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
746 sizeof(struct sctp_chunkhdr)))
749 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
750 * "Z" will reply with a COOKIE ACK chunk after building a TCB
751 * and moving to the ESTABLISHED state.
753 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
757 * If the re-build failed, what is the proper error path
760 * [We should abort the association. --piggy]
763 /* FIXME: Several errors are possible. A bad cookie should
764 * be silently discarded, but think about logging it too.
767 case -SCTP_IERROR_NOMEM:
770 case -SCTP_IERROR_STALE_COOKIE:
771 sctp_send_stale_cookie_err(net, ep, asoc, chunk, commands,
773 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
775 case -SCTP_IERROR_BAD_SIG:
777 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
782 /* Delay state machine commands until later.
784 * Re-build the bind address for the association is done in
785 * the sctp_unpack_cookie() already.
787 /* This is a brand-new association, so these are not yet side
788 * effects--it is safe to run them here.
790 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
792 if (!sctp_process_init(new_asoc, chunk,
793 &chunk->subh.cookie_hdr->c.peer_addr,
794 peer_init, GFP_ATOMIC))
797 /* SCTP-AUTH: Now that we've populate required fields in
798 * sctp_process_init, set up the assocaition shared keys as
799 * necessary so that we can potentially authenticate the ACK
801 error = sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC);
805 if (!sctp_auth_chunk_verify(net, chunk, new_asoc)) {
806 sctp_association_free(new_asoc);
807 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
810 repl = sctp_make_cookie_ack(new_asoc, chunk);
814 /* RFC 2960 5.1 Normal Establishment of an Association
816 * D) IMPLEMENTATION NOTE: An implementation may choose to
817 * send the Communication Up notification to the SCTP user
818 * upon reception of a valid COOKIE ECHO chunk.
820 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0,
821 new_asoc->c.sinit_num_ostreams,
822 new_asoc->c.sinit_max_instreams,
827 /* Sockets API Draft Section 5.3.1.6
828 * When a peer sends a Adaptation Layer Indication parameter , SCTP
829 * delivers this notification to inform the application that of the
830 * peers requested adaptation layer.
832 if (new_asoc->peer.adaptation_ind) {
833 ai_ev = sctp_ulpevent_make_adaptation_indication(new_asoc,
839 if (!new_asoc->peer.auth_capable) {
840 auth_ev = sctp_ulpevent_make_authkey(new_asoc, 0,
847 /* Add all the state machine commands now since we've created
848 * everything. This way we don't introduce memory corruptions
849 * during side-effect processing and correclty count established
852 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
853 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
854 SCTP_STATE(SCTP_STATE_ESTABLISHED));
855 SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB);
856 SCTP_INC_STATS(net, SCTP_MIB_PASSIVEESTABS);
857 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
859 if (new_asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE])
860 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
861 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
863 /* This will send the COOKIE ACK */
864 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
866 /* Queue the ASSOC_CHANGE event */
867 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
869 /* Send up the Adaptation Layer Indication event */
871 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
872 SCTP_ULPEVENT(ai_ev));
875 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
876 SCTP_ULPEVENT(auth_ev));
878 return SCTP_DISPOSITION_CONSUME;
881 sctp_ulpevent_free(ai_ev);
883 sctp_ulpevent_free(ev);
885 sctp_chunk_free(repl);
887 sctp_association_free(new_asoc);
889 return SCTP_DISPOSITION_NOMEM;
893 * Respond to a normal COOKIE ACK chunk.
894 * We are the side that is asking for an association.
896 * RFC 2960 5.1 Normal Establishment of an Association
898 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
899 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
900 * timer. It may also notify its ULP about the successful
901 * establishment of the association with a Communication Up
902 * notification (see Section 10).
906 * (endpoint, asoc, chunk)
909 * (asoc, reply_msg, msg_up, timers, counters)
911 * The return value is the disposition of the chunk.
913 enum sctp_disposition sctp_sf_do_5_1E_ca(struct net *net,
914 const struct sctp_endpoint *ep,
915 const struct sctp_association *asoc,
916 const union sctp_subtype type,
918 struct sctp_cmd_seq *commands)
920 struct sctp_chunk *chunk = arg;
921 struct sctp_ulpevent *ev;
923 if (!sctp_vtag_verify(chunk, asoc))
924 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
926 /* Verify that the chunk length for the COOKIE-ACK is OK.
927 * If we don't do this, any bundled chunks may be junked.
929 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
930 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
933 /* Reset init error count upon receipt of COOKIE-ACK,
934 * to avoid problems with the managemement of this
935 * counter in stale cookie situations when a transition back
936 * from the COOKIE-ECHOED state to the COOKIE-WAIT
937 * state is performed.
939 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
941 /* Set peer label for connection. */
942 security_inet_conn_established(ep->base.sk, chunk->skb);
944 /* RFC 2960 5.1 Normal Establishment of an Association
946 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
947 * from the COOKIE-ECHOED state to the ESTABLISHED state,
948 * stopping the T1-cookie timer.
950 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
951 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
952 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
953 SCTP_STATE(SCTP_STATE_ESTABLISHED));
954 SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB);
955 SCTP_INC_STATS(net, SCTP_MIB_ACTIVEESTABS);
956 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
957 if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE])
958 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
959 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
961 /* It may also notify its ULP about the successful
962 * establishment of the association with a Communication Up
963 * notification (see Section 10).
965 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP,
966 0, asoc->c.sinit_num_ostreams,
967 asoc->c.sinit_max_instreams,
973 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
975 /* Sockets API Draft Section 5.3.1.6
976 * When a peer sends a Adaptation Layer Indication parameter , SCTP
977 * delivers this notification to inform the application that of the
978 * peers requested adaptation layer.
980 if (asoc->peer.adaptation_ind) {
981 ev = sctp_ulpevent_make_adaptation_indication(asoc, GFP_ATOMIC);
985 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
989 if (!asoc->peer.auth_capable) {
990 ev = sctp_ulpevent_make_authkey(asoc, 0, SCTP_AUTH_NO_AUTH,
994 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
998 return SCTP_DISPOSITION_CONSUME;
1000 return SCTP_DISPOSITION_NOMEM;
1003 /* Generate and sendout a heartbeat packet. */
1004 static enum sctp_disposition sctp_sf_heartbeat(
1005 const struct sctp_endpoint *ep,
1006 const struct sctp_association *asoc,
1007 const union sctp_subtype type,
1009 struct sctp_cmd_seq *commands)
1011 struct sctp_transport *transport = (struct sctp_transport *) arg;
1012 struct sctp_chunk *reply;
1014 /* Send a heartbeat to our peer. */
1015 reply = sctp_make_heartbeat(asoc, transport);
1017 return SCTP_DISPOSITION_NOMEM;
1019 /* Set rto_pending indicating that an RTT measurement
1020 * is started with this heartbeat chunk.
1022 sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING,
1023 SCTP_TRANSPORT(transport));
1025 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
1026 return SCTP_DISPOSITION_CONSUME;
1029 /* Generate a HEARTBEAT packet on the given transport. */
1030 enum sctp_disposition sctp_sf_sendbeat_8_3(struct net *net,
1031 const struct sctp_endpoint *ep,
1032 const struct sctp_association *asoc,
1033 const union sctp_subtype type,
1035 struct sctp_cmd_seq *commands)
1037 struct sctp_transport *transport = (struct sctp_transport *) arg;
1039 if (asoc->overall_error_count >= asoc->max_retrans) {
1040 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
1041 SCTP_ERROR(ETIMEDOUT));
1042 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
1043 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
1044 SCTP_PERR(SCTP_ERROR_NO_ERROR));
1045 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
1046 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
1047 return SCTP_DISPOSITION_DELETE_TCB;
1051 * The Sender-specific Heartbeat Info field should normally include
1052 * information about the sender's current time when this HEARTBEAT
1053 * chunk is sent and the destination transport address to which this
1054 * HEARTBEAT is sent (see Section 8.3).
1057 if (transport->param_flags & SPP_HB_ENABLE) {
1058 if (SCTP_DISPOSITION_NOMEM ==
1059 sctp_sf_heartbeat(ep, asoc, type, arg,
1061 return SCTP_DISPOSITION_NOMEM;
1063 /* Set transport error counter and association error counter
1064 * when sending heartbeat.
1066 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_HB_SENT,
1067 SCTP_TRANSPORT(transport));
1069 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_IDLE,
1070 SCTP_TRANSPORT(transport));
1071 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE,
1072 SCTP_TRANSPORT(transport));
1074 return SCTP_DISPOSITION_CONSUME;
1077 /* resend asoc strreset_chunk. */
1078 enum sctp_disposition sctp_sf_send_reconf(struct net *net,
1079 const struct sctp_endpoint *ep,
1080 const struct sctp_association *asoc,
1081 const union sctp_subtype type,
1083 struct sctp_cmd_seq *commands)
1085 struct sctp_transport *transport = arg;
1087 if (asoc->overall_error_count >= asoc->max_retrans) {
1088 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
1089 SCTP_ERROR(ETIMEDOUT));
1090 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
1091 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
1092 SCTP_PERR(SCTP_ERROR_NO_ERROR));
1093 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
1094 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
1095 return SCTP_DISPOSITION_DELETE_TCB;
1098 sctp_chunk_hold(asoc->strreset_chunk);
1099 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1100 SCTP_CHUNK(asoc->strreset_chunk));
1101 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
1103 return SCTP_DISPOSITION_CONSUME;
1107 * Process an heartbeat request.
1109 * Section: 8.3 Path Heartbeat
1110 * The receiver of the HEARTBEAT should immediately respond with a
1111 * HEARTBEAT ACK that contains the Heartbeat Information field copied
1112 * from the received HEARTBEAT chunk.
1114 * Verification Tag: 8.5 Verification Tag [Normal verification]
1115 * When receiving an SCTP packet, the endpoint MUST ensure that the
1116 * value in the Verification Tag field of the received SCTP packet
1117 * matches its own Tag. If the received Verification Tag value does not
1118 * match the receiver's own tag value, the receiver shall silently
1119 * discard the packet and shall not process it any further except for
1120 * those cases listed in Section 8.5.1 below.
1123 * (endpoint, asoc, chunk)
1126 * (asoc, reply_msg, msg_up, timers, counters)
1128 * The return value is the disposition of the chunk.
1130 enum sctp_disposition sctp_sf_beat_8_3(struct net *net,
1131 const struct sctp_endpoint *ep,
1132 const struct sctp_association *asoc,
1133 const union sctp_subtype type,
1134 void *arg, struct sctp_cmd_seq *commands)
1136 struct sctp_paramhdr *param_hdr;
1137 struct sctp_chunk *chunk = arg;
1138 struct sctp_chunk *reply;
1141 if (!sctp_vtag_verify(chunk, asoc))
1142 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
1144 /* Make sure that the HEARTBEAT chunk has a valid length. */
1145 if (!sctp_chunk_length_valid(chunk,
1146 sizeof(struct sctp_heartbeat_chunk)))
1147 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
1150 /* 8.3 The receiver of the HEARTBEAT should immediately
1151 * respond with a HEARTBEAT ACK that contains the Heartbeat
1152 * Information field copied from the received HEARTBEAT chunk.
1154 chunk->subh.hb_hdr = (struct sctp_heartbeathdr *)chunk->skb->data;
1155 param_hdr = (struct sctp_paramhdr *)chunk->subh.hb_hdr;
1156 paylen = ntohs(chunk->chunk_hdr->length) - sizeof(struct sctp_chunkhdr);
1158 if (ntohs(param_hdr->length) > paylen)
1159 return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
1160 param_hdr, commands);
1162 if (!pskb_pull(chunk->skb, paylen))
1165 reply = sctp_make_heartbeat_ack(asoc, chunk, param_hdr, paylen);
1169 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
1170 return SCTP_DISPOSITION_CONSUME;
1173 return SCTP_DISPOSITION_NOMEM;
1177 * Process the returning HEARTBEAT ACK.
1179 * Section: 8.3 Path Heartbeat
1180 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
1181 * should clear the error counter of the destination transport
1182 * address to which the HEARTBEAT was sent, and mark the destination
1183 * transport address as active if it is not so marked. The endpoint may
1184 * optionally report to the upper layer when an inactive destination
1185 * address is marked as active due to the reception of the latest
1186 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
1187 * clear the association overall error count as well (as defined
1190 * The receiver of the HEARTBEAT ACK should also perform an RTT
1191 * measurement for that destination transport address using the time
1192 * value carried in the HEARTBEAT ACK chunk.
1194 * Verification Tag: 8.5 Verification Tag [Normal verification]
1197 * (endpoint, asoc, chunk)
1200 * (asoc, reply_msg, msg_up, timers, counters)
1202 * The return value is the disposition of the chunk.
1204 enum sctp_disposition sctp_sf_backbeat_8_3(struct net *net,
1205 const struct sctp_endpoint *ep,
1206 const struct sctp_association *asoc,
1207 const union sctp_subtype type,
1209 struct sctp_cmd_seq *commands)
1211 struct sctp_sender_hb_info *hbinfo;
1212 struct sctp_chunk *chunk = arg;
1213 struct sctp_transport *link;
1214 unsigned long max_interval;
1215 union sctp_addr from_addr;
1217 if (!sctp_vtag_verify(chunk, asoc))
1218 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
1220 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1221 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr) +
1223 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
1226 hbinfo = (struct sctp_sender_hb_info *)chunk->skb->data;
1227 /* Make sure that the length of the parameter is what we expect */
1228 if (ntohs(hbinfo->param_hdr.length) != sizeof(*hbinfo))
1229 return SCTP_DISPOSITION_DISCARD;
1231 from_addr = hbinfo->daddr;
1232 link = sctp_assoc_lookup_paddr(asoc, &from_addr);
1234 /* This should never happen, but lets log it if so. */
1235 if (unlikely(!link)) {
1236 if (from_addr.sa.sa_family == AF_INET6) {
1237 net_warn_ratelimited("%s association %p could not find address %pI6\n",
1240 &from_addr.v6.sin6_addr);
1242 net_warn_ratelimited("%s association %p could not find address %pI4\n",
1245 &from_addr.v4.sin_addr.s_addr);
1247 return SCTP_DISPOSITION_DISCARD;
1250 /* Validate the 64-bit random nonce. */
1251 if (hbinfo->hb_nonce != link->hb_nonce)
1252 return SCTP_DISPOSITION_DISCARD;
1254 max_interval = link->hbinterval + link->rto;
1256 /* Check if the timestamp looks valid. */
1257 if (time_after(hbinfo->sent_at, jiffies) ||
1258 time_after(jiffies, hbinfo->sent_at + max_interval)) {
1259 pr_debug("%s: HEARTBEAT ACK with invalid timestamp received "
1260 "for transport:%p\n", __func__, link);
1262 return SCTP_DISPOSITION_DISCARD;
1265 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1266 * the HEARTBEAT should clear the error counter of the
1267 * destination transport address to which the HEARTBEAT was
1268 * sent and mark the destination transport address as active if
1269 * it is not so marked.
1271 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link));
1273 return SCTP_DISPOSITION_CONSUME;
1276 /* Helper function to send out an abort for the restart
1279 static int sctp_sf_send_restart_abort(struct net *net, union sctp_addr *ssa,
1280 struct sctp_chunk *init,
1281 struct sctp_cmd_seq *commands)
1283 struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family);
1284 union sctp_addr_param *addrparm;
1285 struct sctp_errhdr *errhdr;
1286 char buffer[sizeof(*errhdr) + sizeof(*addrparm)];
1287 struct sctp_endpoint *ep;
1288 struct sctp_packet *pkt;
1291 /* Build the error on the stack. We are way to malloc crazy
1292 * throughout the code today.
1294 errhdr = (struct sctp_errhdr *)buffer;
1295 addrparm = (union sctp_addr_param *)errhdr->variable;
1297 /* Copy into a parm format. */
1298 len = af->to_addr_param(ssa, addrparm);
1299 len += sizeof(*errhdr);
1301 errhdr->cause = SCTP_ERROR_RESTART;
1302 errhdr->length = htons(len);
1304 /* Assign to the control socket. */
1305 ep = sctp_sk(net->sctp.ctl_sock)->ep;
1307 /* Association is NULL since this may be a restart attack and we
1308 * want to send back the attacker's vtag.
1310 pkt = sctp_abort_pkt_new(net, ep, NULL, init, errhdr, len);
1314 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt));
1316 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
1318 /* Discard the rest of the inbound packet. */
1319 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
1322 /* Even if there is no memory, treat as a failure so
1323 * the packet will get dropped.
1328 static bool list_has_sctp_addr(const struct list_head *list,
1329 union sctp_addr *ipaddr)
1331 struct sctp_transport *addr;
1333 list_for_each_entry(addr, list, transports) {
1334 if (sctp_cmp_addr_exact(ipaddr, &addr->ipaddr))
1340 /* A restart is occurring, check to make sure no new addresses
1341 * are being added as we may be under a takeover attack.
1343 static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc,
1344 const struct sctp_association *asoc,
1345 struct sctp_chunk *init,
1346 struct sctp_cmd_seq *commands)
1348 struct net *net = sock_net(new_asoc->base.sk);
1349 struct sctp_transport *new_addr;
1352 /* Implementor's Guide - Section 5.2.2
1354 * Before responding the endpoint MUST check to see if the
1355 * unexpected INIT adds new addresses to the association. If new
1356 * addresses are added to the association, the endpoint MUST respond
1360 /* Search through all current addresses and make sure
1361 * we aren't adding any new ones.
1363 list_for_each_entry(new_addr, &new_asoc->peer.transport_addr_list,
1365 if (!list_has_sctp_addr(&asoc->peer.transport_addr_list,
1366 &new_addr->ipaddr)) {
1367 sctp_sf_send_restart_abort(net, &new_addr->ipaddr, init,
1374 /* Return success if all addresses were found. */
1378 /* Populate the verification/tie tags based on overlapping INIT
1381 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1383 static void sctp_tietags_populate(struct sctp_association *new_asoc,
1384 const struct sctp_association *asoc)
1386 switch (asoc->state) {
1388 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1390 case SCTP_STATE_COOKIE_WAIT:
1391 new_asoc->c.my_vtag = asoc->c.my_vtag;
1392 new_asoc->c.my_ttag = asoc->c.my_vtag;
1393 new_asoc->c.peer_ttag = 0;
1396 case SCTP_STATE_COOKIE_ECHOED:
1397 new_asoc->c.my_vtag = asoc->c.my_vtag;
1398 new_asoc->c.my_ttag = asoc->c.my_vtag;
1399 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1402 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1403 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1406 new_asoc->c.my_ttag = asoc->c.my_vtag;
1407 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1411 /* Other parameters for the endpoint SHOULD be copied from the
1412 * existing parameters of the association (e.g. number of
1413 * outbound streams) into the INIT ACK and cookie.
1415 new_asoc->rwnd = asoc->rwnd;
1416 new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams;
1417 new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams;
1418 new_asoc->c.initial_tsn = asoc->c.initial_tsn;
1422 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1425 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1427 * Returns value representing action to be taken. These action values
1428 * correspond to Action/Description values in RFC 2960, Table 2.
1430 static char sctp_tietags_compare(struct sctp_association *new_asoc,
1431 const struct sctp_association *asoc)
1433 /* In this case, the peer may have restarted. */
1434 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1435 (asoc->c.peer_vtag != new_asoc->c.peer_vtag) &&
1436 (asoc->c.my_vtag == new_asoc->c.my_ttag) &&
1437 (asoc->c.peer_vtag == new_asoc->c.peer_ttag))
1440 /* Collision case B. */
1441 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1442 ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) ||
1443 (0 == asoc->c.peer_vtag))) {
1447 /* Collision case D. */
1448 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1449 (asoc->c.peer_vtag == new_asoc->c.peer_vtag))
1452 /* Collision case C. */
1453 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1454 (asoc->c.peer_vtag == new_asoc->c.peer_vtag) &&
1455 (0 == new_asoc->c.my_ttag) &&
1456 (0 == new_asoc->c.peer_ttag))
1459 /* No match to any of the special cases; discard this packet. */
1463 /* Common helper routine for both duplicate and simulataneous INIT
1466 static enum sctp_disposition sctp_sf_do_unexpected_init(
1468 const struct sctp_endpoint *ep,
1469 const struct sctp_association *asoc,
1470 const union sctp_subtype type,
1472 struct sctp_cmd_seq *commands)
1474 struct sctp_chunk *chunk = arg, *repl, *err_chunk;
1475 struct sctp_unrecognized_param *unk_param;
1476 struct sctp_association *new_asoc;
1477 enum sctp_disposition retval;
1478 struct sctp_packet *packet;
1481 /* Update socket peer label if first association. */
1482 if (security_sctp_assoc_request((struct sctp_endpoint *)ep,
1484 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
1487 * An endpoint MUST NOT bundle INIT, INIT ACK or
1488 * SHUTDOWN COMPLETE with any other chunks.
1491 * Furthermore, we require that the receiver of an INIT chunk MUST
1492 * enforce these rules by silently discarding an arriving packet
1493 * with an INIT chunk that is bundled with other chunks.
1495 if (!chunk->singleton)
1496 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
1498 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1501 if (chunk->sctp_hdr->vtag != 0)
1502 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
1504 /* Make sure that the INIT chunk has a valid length.
1505 * In this case, we generate a protocol violation since we have
1506 * an association established.
1508 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_init_chunk)))
1509 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
1511 /* Grab the INIT header. */
1512 chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data;
1514 /* Tag the variable length parameters. */
1515 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(struct sctp_inithdr));
1517 /* Verify the INIT chunk before processing it. */
1519 if (!sctp_verify_init(net, ep, asoc, chunk->chunk_hdr->type,
1520 (struct sctp_init_chunk *)chunk->chunk_hdr, chunk,
1522 /* This chunk contains fatal error. It is to be discarded.
1523 * Send an ABORT, with causes if there is any.
1526 packet = sctp_abort_pkt_new(net, ep, asoc, arg,
1527 (__u8 *)(err_chunk->chunk_hdr) +
1528 sizeof(struct sctp_chunkhdr),
1529 ntohs(err_chunk->chunk_hdr->length) -
1530 sizeof(struct sctp_chunkhdr));
1533 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
1534 SCTP_PACKET(packet));
1535 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
1536 retval = SCTP_DISPOSITION_CONSUME;
1538 retval = SCTP_DISPOSITION_NOMEM;
1542 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg,
1548 * Other parameters for the endpoint SHOULD be copied from the
1549 * existing parameters of the association (e.g. number of
1550 * outbound streams) into the INIT ACK and cookie.
1551 * FIXME: We are copying parameters from the endpoint not the
1554 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
1558 if (sctp_assoc_set_bind_addr_from_ep(new_asoc,
1559 sctp_scope(sctp_source(chunk)), GFP_ATOMIC) < 0)
1562 /* In the outbound INIT ACK the endpoint MUST copy its current
1563 * Verification Tag and Peers Verification tag into a reserved
1564 * place (local tie-tag and per tie-tag) within the state cookie.
1566 if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk),
1567 (struct sctp_init_chunk *)chunk->chunk_hdr,
1571 /* Make sure no new addresses are being added during the
1572 * restart. Do not do this check for COOKIE-WAIT state,
1573 * since there are no peer addresses to check against.
1574 * Upon return an ABORT will have been sent if needed.
1576 if (!sctp_state(asoc, COOKIE_WAIT)) {
1577 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
1579 retval = SCTP_DISPOSITION_CONSUME;
1584 sctp_tietags_populate(new_asoc, asoc);
1586 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1588 /* If there are errors need to be reported for unknown parameters,
1589 * make sure to reserve enough room in the INIT ACK for them.
1593 len = ntohs(err_chunk->chunk_hdr->length) -
1594 sizeof(struct sctp_chunkhdr);
1597 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
1601 /* If there are errors need to be reported for unknown parameters,
1602 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1606 /* Get the "Unrecognized parameter" parameter(s) out of the
1607 * ERROR chunk generated by sctp_verify_init(). Since the
1608 * error cause code for "unknown parameter" and the
1609 * "Unrecognized parameter" type is the same, we can
1610 * construct the parameters in INIT ACK by copying the
1611 * ERROR causes over.
1613 unk_param = (struct sctp_unrecognized_param *)
1614 ((__u8 *)(err_chunk->chunk_hdr) +
1615 sizeof(struct sctp_chunkhdr));
1616 /* Replace the cause code with the "Unrecognized parameter"
1619 sctp_addto_chunk(repl, len, unk_param);
1622 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1623 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1626 * Note: After sending out INIT ACK with the State Cookie parameter,
1627 * "Z" MUST NOT allocate any resources for this new association.
1628 * Otherwise, "Z" will be vulnerable to resource attacks.
1630 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1631 retval = SCTP_DISPOSITION_CONSUME;
1636 retval = SCTP_DISPOSITION_NOMEM;
1639 sctp_association_free(new_asoc);
1642 sctp_chunk_free(err_chunk);
1647 * Handle simultaneous INIT.
1648 * This means we started an INIT and then we got an INIT request from
1651 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1652 * This usually indicates an initialization collision, i.e., each
1653 * endpoint is attempting, at about the same time, to establish an
1654 * association with the other endpoint.
1656 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1657 * endpoint MUST respond with an INIT ACK using the same parameters it
1658 * sent in its original INIT chunk (including its Verification Tag,
1659 * unchanged). These original parameters are combined with those from the
1660 * newly received INIT chunk. The endpoint shall also generate a State
1661 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1662 * INIT to calculate the State Cookie.
1664 * After that, the endpoint MUST NOT change its state, the T1-init
1665 * timer shall be left running and the corresponding TCB MUST NOT be
1666 * destroyed. The normal procedures for handling State Cookies when
1667 * a TCB exists will resolve the duplicate INITs to a single association.
1669 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1670 * its Tie-Tags with the Tag information of itself and its peer (see
1671 * section 5.2.2 for a description of the Tie-Tags).
1673 * Verification Tag: Not explicit, but an INIT can not have a valid
1674 * verification tag, so we skip the check.
1677 * (endpoint, asoc, chunk)
1680 * (asoc, reply_msg, msg_up, timers, counters)
1682 * The return value is the disposition of the chunk.
1684 enum sctp_disposition sctp_sf_do_5_2_1_siminit(
1686 const struct sctp_endpoint *ep,
1687 const struct sctp_association *asoc,
1688 const union sctp_subtype type,
1690 struct sctp_cmd_seq *commands)
1692 /* Call helper to do the real work for both simulataneous and
1693 * duplicate INIT chunk handling.
1695 return sctp_sf_do_unexpected_init(net, ep, asoc, type, arg, commands);
1699 * Handle duplicated INIT messages. These are usually delayed
1702 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1703 * COOKIE-ECHOED and COOKIE-WAIT
1705 * Unless otherwise stated, upon reception of an unexpected INIT for
1706 * this association, the endpoint shall generate an INIT ACK with a
1707 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1708 * current Verification Tag and peer's Verification Tag into a reserved
1709 * place within the state cookie. We shall refer to these locations as
1710 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1711 * containing this INIT ACK MUST carry a Verification Tag value equal to
1712 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1713 * MUST contain a new Initiation Tag (randomly generated see Section
1714 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1715 * existing parameters of the association (e.g. number of outbound
1716 * streams) into the INIT ACK and cookie.
1718 * After sending out the INIT ACK, the endpoint shall take no further
1719 * actions, i.e., the existing association, including its current state,
1720 * and the corresponding TCB MUST NOT be changed.
1722 * Note: Only when a TCB exists and the association is not in a COOKIE-
1723 * WAIT state are the Tie-Tags populated. For a normal association INIT
1724 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1725 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1726 * State Cookie are populated as specified in section 5.2.1.
1728 * Verification Tag: Not specified, but an INIT has no way of knowing
1729 * what the verification tag could be, so we ignore it.
1732 * (endpoint, asoc, chunk)
1735 * (asoc, reply_msg, msg_up, timers, counters)
1737 * The return value is the disposition of the chunk.
1739 enum sctp_disposition sctp_sf_do_5_2_2_dupinit(
1741 const struct sctp_endpoint *ep,
1742 const struct sctp_association *asoc,
1743 const union sctp_subtype type,
1745 struct sctp_cmd_seq *commands)
1747 /* Call helper to do the real work for both simulataneous and
1748 * duplicate INIT chunk handling.
1750 return sctp_sf_do_unexpected_init(net, ep, asoc, type, arg, commands);
1755 * Unexpected INIT-ACK handler.
1758 * If an INIT ACK received by an endpoint in any state other than the
1759 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1760 * An unexpected INIT ACK usually indicates the processing of an old or
1761 * duplicated INIT chunk.
1763 enum sctp_disposition sctp_sf_do_5_2_3_initack(
1765 const struct sctp_endpoint *ep,
1766 const struct sctp_association *asoc,
1767 const union sctp_subtype type,
1769 struct sctp_cmd_seq *commands)
1771 /* Per the above section, we'll discard the chunk if we have an
1772 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1774 if (ep == sctp_sk(net->sctp.ctl_sock)->ep)
1775 return sctp_sf_ootb(net, ep, asoc, type, arg, commands);
1777 return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands);
1780 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1783 * A) In this case, the peer may have restarted.
1785 static enum sctp_disposition sctp_sf_do_dupcook_a(
1787 const struct sctp_endpoint *ep,
1788 const struct sctp_association *asoc,
1789 struct sctp_chunk *chunk,
1790 struct sctp_cmd_seq *commands,
1791 struct sctp_association *new_asoc)
1793 struct sctp_init_chunk *peer_init;
1794 enum sctp_disposition disposition;
1795 struct sctp_ulpevent *ev;
1796 struct sctp_chunk *repl;
1797 struct sctp_chunk *err;
1799 /* new_asoc is a brand-new association, so these are not yet
1800 * side effects--it is safe to run them here.
1802 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1804 if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk), peer_init,
1808 if (sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC))
1811 if (!sctp_auth_chunk_verify(net, chunk, new_asoc))
1812 return SCTP_DISPOSITION_DISCARD;
1814 /* Make sure no new addresses are being added during the
1815 * restart. Though this is a pretty complicated attack
1816 * since you'd have to get inside the cookie.
1818 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands))
1819 return SCTP_DISPOSITION_CONSUME;
1821 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1822 * the peer has restarted (Action A), it MUST NOT setup a new
1823 * association but instead resend the SHUTDOWN ACK and send an ERROR
1824 * chunk with a "Cookie Received while Shutting Down" error cause to
1827 if (sctp_state(asoc, SHUTDOWN_ACK_SENT)) {
1828 disposition = sctp_sf_do_9_2_reshutack(net, ep, asoc,
1829 SCTP_ST_CHUNK(chunk->chunk_hdr->type),
1831 if (SCTP_DISPOSITION_NOMEM == disposition)
1834 err = sctp_make_op_error(asoc, chunk,
1835 SCTP_ERROR_COOKIE_IN_SHUTDOWN,
1838 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1841 return SCTP_DISPOSITION_CONSUME;
1844 /* For now, stop pending T3-rtx and SACK timers, fail any unsent/unacked
1845 * data. Consider the optional choice of resending of this data.
1847 sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL());
1848 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1849 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
1850 sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL());
1852 /* Stop pending T4-rto timer, teardown ASCONF queue, ASCONF-ACK queue
1853 * and ASCONF-ACK cache.
1855 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1856 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
1857 sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_ASCONF_QUEUE, SCTP_NULL());
1859 /* Update the content of current association. */
1860 if (sctp_assoc_update((struct sctp_association *)asoc, new_asoc)) {
1861 struct sctp_chunk *abort;
1863 abort = sctp_make_abort(asoc, NULL, sizeof(struct sctp_errhdr));
1865 sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, 0);
1866 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
1868 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNABORTED));
1869 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
1870 SCTP_PERR(SCTP_ERROR_RSRC_LOW));
1871 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
1872 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
1876 repl = sctp_make_cookie_ack(asoc, chunk);
1880 /* Report association restart to upper layer. */
1881 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0,
1882 asoc->c.sinit_num_ostreams,
1883 asoc->c.sinit_max_instreams,
1888 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1889 if ((sctp_state(asoc, SHUTDOWN_PENDING) ||
1890 sctp_state(asoc, SHUTDOWN_SENT)) &&
1891 (sctp_sstate(asoc->base.sk, CLOSING) ||
1892 sock_flag(asoc->base.sk, SOCK_DEAD))) {
1893 /* If the socket has been closed by user, don't
1894 * transition to ESTABLISHED. Instead trigger SHUTDOWN
1895 * bundled with COOKIE_ACK.
1897 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1898 return sctp_sf_do_9_2_start_shutdown(net, ep, asoc,
1899 SCTP_ST_CHUNK(0), repl,
1902 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1903 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1904 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1906 return SCTP_DISPOSITION_CONSUME;
1909 sctp_chunk_free(repl);
1911 return SCTP_DISPOSITION_NOMEM;
1914 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1917 * B) In this case, both sides may be attempting to start an association
1918 * at about the same time but the peer endpoint started its INIT
1919 * after responding to the local endpoint's INIT
1921 /* This case represents an initialization collision. */
1922 static enum sctp_disposition sctp_sf_do_dupcook_b(
1924 const struct sctp_endpoint *ep,
1925 const struct sctp_association *asoc,
1926 struct sctp_chunk *chunk,
1927 struct sctp_cmd_seq *commands,
1928 struct sctp_association *new_asoc)
1930 struct sctp_init_chunk *peer_init;
1931 struct sctp_chunk *repl;
1933 /* new_asoc is a brand-new association, so these are not yet
1934 * side effects--it is safe to run them here.
1936 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1937 if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk), peer_init,
1941 if (sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC))
1944 if (!sctp_auth_chunk_verify(net, chunk, new_asoc))
1945 return SCTP_DISPOSITION_DISCARD;
1947 /* Update the content of current association. */
1948 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1949 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1950 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1951 if (asoc->state < SCTP_STATE_ESTABLISHED)
1952 SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB);
1953 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
1955 repl = sctp_make_cookie_ack(new_asoc, chunk);
1959 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1961 /* RFC 2960 5.1 Normal Establishment of an Association
1963 * D) IMPLEMENTATION NOTE: An implementation may choose to
1964 * send the Communication Up notification to the SCTP user
1965 * upon reception of a valid COOKIE ECHO chunk.
1967 * Sadly, this needs to be implemented as a side-effect, because
1968 * we are not guaranteed to have set the association id of the real
1969 * association and so these notifications need to be delayed until
1970 * the association id is allocated.
1973 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_CHANGE, SCTP_U8(SCTP_COMM_UP));
1975 /* Sockets API Draft Section 5.3.1.6
1976 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1977 * delivers this notification to inform the application that of the
1978 * peers requested adaptation layer.
1980 * This also needs to be done as a side effect for the same reason as
1983 if (asoc->peer.adaptation_ind)
1984 sctp_add_cmd_sf(commands, SCTP_CMD_ADAPTATION_IND, SCTP_NULL());
1986 if (!asoc->peer.auth_capable)
1987 sctp_add_cmd_sf(commands, SCTP_CMD_PEER_NO_AUTH, SCTP_NULL());
1989 return SCTP_DISPOSITION_CONSUME;
1992 return SCTP_DISPOSITION_NOMEM;
1995 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1998 * C) In this case, the local endpoint's cookie has arrived late.
1999 * Before it arrived, the local endpoint sent an INIT and received an
2000 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
2001 * but a new tag of its own.
2003 /* This case represents an initialization collision. */
2004 static enum sctp_disposition sctp_sf_do_dupcook_c(
2006 const struct sctp_endpoint *ep,
2007 const struct sctp_association *asoc,
2008 struct sctp_chunk *chunk,
2009 struct sctp_cmd_seq *commands,
2010 struct sctp_association *new_asoc)
2012 /* The cookie should be silently discarded.
2013 * The endpoint SHOULD NOT change states and should leave
2014 * any timers running.
2016 return SCTP_DISPOSITION_DISCARD;
2019 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
2023 * D) When both local and remote tags match the endpoint should always
2024 * enter the ESTABLISHED state, if it has not already done so.
2026 /* This case represents an initialization collision. */
2027 static enum sctp_disposition sctp_sf_do_dupcook_d(
2029 const struct sctp_endpoint *ep,
2030 const struct sctp_association *asoc,
2031 struct sctp_chunk *chunk,
2032 struct sctp_cmd_seq *commands,
2033 struct sctp_association *new_asoc)
2035 struct sctp_ulpevent *ev = NULL, *ai_ev = NULL, *auth_ev = NULL;
2036 struct sctp_chunk *repl;
2038 /* Clarification from Implementor's Guide:
2039 * D) When both local and remote tags match the endpoint should
2040 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
2041 * It should stop any cookie timer that may be running and send
2045 if (!sctp_auth_chunk_verify(net, chunk, asoc))
2046 return SCTP_DISPOSITION_DISCARD;
2048 /* Don't accidentally move back into established state. */
2049 if (asoc->state < SCTP_STATE_ESTABLISHED) {
2050 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2051 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
2052 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2053 SCTP_STATE(SCTP_STATE_ESTABLISHED));
2054 SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB);
2055 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START,
2058 /* RFC 2960 5.1 Normal Establishment of an Association
2060 * D) IMPLEMENTATION NOTE: An implementation may choose
2061 * to send the Communication Up notification to the
2062 * SCTP user upon reception of a valid COOKIE
2065 ev = sctp_ulpevent_make_assoc_change(asoc, 0,
2067 asoc->c.sinit_num_ostreams,
2068 asoc->c.sinit_max_instreams,
2073 /* Sockets API Draft Section 5.3.1.6
2074 * When a peer sends a Adaptation Layer Indication parameter,
2075 * SCTP delivers this notification to inform the application
2076 * that of the peers requested adaptation layer.
2078 if (asoc->peer.adaptation_ind) {
2079 ai_ev = sctp_ulpevent_make_adaptation_indication(asoc,
2086 if (!asoc->peer.auth_capable) {
2087 auth_ev = sctp_ulpevent_make_authkey(asoc, 0,
2095 repl = sctp_make_cookie_ack(asoc, chunk);
2099 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
2102 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
2105 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
2106 SCTP_ULPEVENT(ai_ev));
2108 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
2109 SCTP_ULPEVENT(auth_ev));
2111 return SCTP_DISPOSITION_CONSUME;
2115 sctp_ulpevent_free(auth_ev);
2117 sctp_ulpevent_free(ai_ev);
2119 sctp_ulpevent_free(ev);
2120 return SCTP_DISPOSITION_NOMEM;
2124 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
2125 * chunk was retransmitted and then delayed in the network.
2127 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
2129 * Verification Tag: None. Do cookie validation.
2132 * (endpoint, asoc, chunk)
2135 * (asoc, reply_msg, msg_up, timers, counters)
2137 * The return value is the disposition of the chunk.
2139 enum sctp_disposition sctp_sf_do_5_2_4_dupcook(
2141 const struct sctp_endpoint *ep,
2142 const struct sctp_association *asoc,
2143 const union sctp_subtype type,
2145 struct sctp_cmd_seq *commands)
2147 struct sctp_association *new_asoc;
2148 struct sctp_chunk *chunk = arg;
2149 enum sctp_disposition retval;
2150 struct sctp_chunk *err_chk_p;
2154 /* Make sure that the chunk has a valid length from the protocol
2155 * perspective. In this case check to make sure we have at least
2156 * enough for the chunk header. Cookie length verification is
2159 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
2160 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
2163 /* "Decode" the chunk. We have no optional parameters so we
2164 * are in good shape.
2166 chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data;
2167 if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
2168 sizeof(struct sctp_chunkhdr)))
2171 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
2172 * of a duplicate COOKIE ECHO match the Verification Tags of the
2173 * current association, consider the State Cookie valid even if
2174 * the lifespan is exceeded.
2176 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
2180 * If the re-build failed, what is the proper error path
2183 * [We should abort the association. --piggy]
2186 /* FIXME: Several errors are possible. A bad cookie should
2187 * be silently discarded, but think about logging it too.
2190 case -SCTP_IERROR_NOMEM:
2193 case -SCTP_IERROR_STALE_COOKIE:
2194 sctp_send_stale_cookie_err(net, ep, asoc, chunk, commands,
2196 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2197 case -SCTP_IERROR_BAD_SIG:
2199 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2203 /* Update socket peer label if first association. */
2204 if (security_sctp_assoc_request((struct sctp_endpoint *)ep,
2206 sctp_association_free(new_asoc);
2207 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2210 /* Set temp so that it won't be added into hashtable */
2213 /* Compare the tie_tag in cookie with the verification tag of
2214 * current association.
2216 action = sctp_tietags_compare(new_asoc, asoc);
2219 case 'A': /* Association restart. */
2220 retval = sctp_sf_do_dupcook_a(net, ep, asoc, chunk, commands,
2224 case 'B': /* Collision case B. */
2225 retval = sctp_sf_do_dupcook_b(net, ep, asoc, chunk, commands,
2229 case 'C': /* Collision case C. */
2230 retval = sctp_sf_do_dupcook_c(net, ep, asoc, chunk, commands,
2234 case 'D': /* Collision case D. */
2235 retval = sctp_sf_do_dupcook_d(net, ep, asoc, chunk, commands,
2239 default: /* Discard packet for all others. */
2240 retval = sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2244 /* Delete the tempory new association. */
2245 sctp_add_cmd_sf(commands, SCTP_CMD_SET_ASOC, SCTP_ASOC(new_asoc));
2246 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
2248 /* Restore association pointer to provide SCTP command interpeter
2249 * with a valid context in case it needs to manipulate
2251 sctp_add_cmd_sf(commands, SCTP_CMD_SET_ASOC,
2252 SCTP_ASOC((struct sctp_association *)asoc));
2257 return SCTP_DISPOSITION_NOMEM;
2261 * Process an ABORT. (SHUTDOWN-PENDING state)
2263 * See sctp_sf_do_9_1_abort().
2265 enum sctp_disposition sctp_sf_shutdown_pending_abort(
2267 const struct sctp_endpoint *ep,
2268 const struct sctp_association *asoc,
2269 const union sctp_subtype type,
2271 struct sctp_cmd_seq *commands)
2273 struct sctp_chunk *chunk = arg;
2275 if (!sctp_vtag_verify_either(chunk, asoc))
2276 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2278 /* Make sure that the ABORT chunk has a valid length.
2279 * Since this is an ABORT chunk, we have to discard it
2280 * because of the following text:
2281 * RFC 2960, Section 3.3.7
2282 * If an endpoint receives an ABORT with a format error or for an
2283 * association that doesn't exist, it MUST silently discard it.
2284 * Because the length is "invalid", we can't really discard just
2285 * as we do not know its true length. So, to be safe, discard the
2288 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk)))
2289 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2291 /* ADD-IP: Special case for ABORT chunks
2292 * F4) One special consideration is that ABORT Chunks arriving
2293 * destined to the IP address being deleted MUST be
2294 * ignored (see Section 5.3.1 for further details).
2296 if (SCTP_ADDR_DEL ==
2297 sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
2298 return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands);
2300 if (!sctp_err_chunk_valid(chunk))
2301 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2303 return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands);
2307 * Process an ABORT. (SHUTDOWN-SENT state)
2309 * See sctp_sf_do_9_1_abort().
2311 enum sctp_disposition sctp_sf_shutdown_sent_abort(
2313 const struct sctp_endpoint *ep,
2314 const struct sctp_association *asoc,
2315 const union sctp_subtype type,
2317 struct sctp_cmd_seq *commands)
2319 struct sctp_chunk *chunk = arg;
2321 if (!sctp_vtag_verify_either(chunk, asoc))
2322 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2324 /* Make sure that the ABORT chunk has a valid length.
2325 * Since this is an ABORT chunk, we have to discard it
2326 * because of the following text:
2327 * RFC 2960, Section 3.3.7
2328 * If an endpoint receives an ABORT with a format error or for an
2329 * association that doesn't exist, it MUST silently discard it.
2330 * Because the length is "invalid", we can't really discard just
2331 * as we do not know its true length. So, to be safe, discard the
2334 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk)))
2335 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2337 /* ADD-IP: Special case for ABORT chunks
2338 * F4) One special consideration is that ABORT Chunks arriving
2339 * destined to the IP address being deleted MUST be
2340 * ignored (see Section 5.3.1 for further details).
2342 if (SCTP_ADDR_DEL ==
2343 sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
2344 return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands);
2346 if (!sctp_err_chunk_valid(chunk))
2347 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2349 /* Stop the T2-shutdown timer. */
2350 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2351 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2353 /* Stop the T5-shutdown guard timer. */
2354 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2355 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
2357 return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands);
2361 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2363 * See sctp_sf_do_9_1_abort().
2365 enum sctp_disposition sctp_sf_shutdown_ack_sent_abort(
2367 const struct sctp_endpoint *ep,
2368 const struct sctp_association *asoc,
2369 const union sctp_subtype type,
2371 struct sctp_cmd_seq *commands)
2373 /* The same T2 timer, so we should be able to use
2374 * common function with the SHUTDOWN-SENT state.
2376 return sctp_sf_shutdown_sent_abort(net, ep, asoc, type, arg, commands);
2380 * Handle an Error received in COOKIE_ECHOED state.
2382 * Only handle the error type of stale COOKIE Error, the other errors will
2386 * (endpoint, asoc, chunk)
2389 * (asoc, reply_msg, msg_up, timers, counters)
2391 * The return value is the disposition of the chunk.
2393 enum sctp_disposition sctp_sf_cookie_echoed_err(
2395 const struct sctp_endpoint *ep,
2396 const struct sctp_association *asoc,
2397 const union sctp_subtype type,
2399 struct sctp_cmd_seq *commands)
2401 struct sctp_chunk *chunk = arg;
2402 struct sctp_errhdr *err;
2404 if (!sctp_vtag_verify(chunk, asoc))
2405 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2407 /* Make sure that the ERROR chunk has a valid length.
2408 * The parameter walking depends on this as well.
2410 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_operr_chunk)))
2411 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
2414 /* Process the error here */
2415 /* FUTURE FIXME: When PR-SCTP related and other optional
2416 * parms are emitted, this will have to change to handle multiple
2419 sctp_walk_errors(err, chunk->chunk_hdr) {
2420 if (SCTP_ERROR_STALE_COOKIE == err->cause)
2421 return sctp_sf_do_5_2_6_stale(net, ep, asoc, type,
2425 /* It is possible to have malformed error causes, and that
2426 * will cause us to end the walk early. However, since
2427 * we are discarding the packet, there should be no adverse
2430 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2434 * Handle a Stale COOKIE Error
2436 * Section: 5.2.6 Handle Stale COOKIE Error
2437 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2438 * one of the following three alternatives.
2440 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2441 * Preservative parameter requesting an extension to the lifetime of
2442 * the State Cookie. When calculating the time extension, an
2443 * implementation SHOULD use the RTT information measured based on the
2444 * previous COOKIE ECHO / ERROR exchange, and should add no more
2445 * than 1 second beyond the measured RTT, due to long State Cookie
2446 * lifetimes making the endpoint more subject to a replay attack.
2448 * Verification Tag: Not explicit, but safe to ignore.
2451 * (endpoint, asoc, chunk)
2454 * (asoc, reply_msg, msg_up, timers, counters)
2456 * The return value is the disposition of the chunk.
2458 static enum sctp_disposition sctp_sf_do_5_2_6_stale(
2460 const struct sctp_endpoint *ep,
2461 const struct sctp_association *asoc,
2462 const union sctp_subtype type,
2464 struct sctp_cmd_seq *commands)
2466 int attempts = asoc->init_err_counter + 1;
2467 struct sctp_chunk *chunk = arg, *reply;
2468 struct sctp_cookie_preserve_param bht;
2469 struct sctp_bind_addr *bp;
2470 struct sctp_errhdr *err;
2473 if (attempts > asoc->max_init_attempts) {
2474 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
2475 SCTP_ERROR(ETIMEDOUT));
2476 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2477 SCTP_PERR(SCTP_ERROR_STALE_COOKIE));
2478 return SCTP_DISPOSITION_DELETE_TCB;
2481 err = (struct sctp_errhdr *)(chunk->skb->data);
2483 /* When calculating the time extension, an implementation
2484 * SHOULD use the RTT information measured based on the
2485 * previous COOKIE ECHO / ERROR exchange, and should add no
2486 * more than 1 second beyond the measured RTT, due to long
2487 * State Cookie lifetimes making the endpoint more subject to
2489 * Measure of Staleness's unit is usec. (1/1000000 sec)
2490 * Suggested Cookie Life-span Increment's unit is msec.
2492 * In general, if you use the suggested cookie life, the value
2493 * found in the field of measure of staleness should be doubled
2494 * to give ample time to retransmit the new cookie and thus
2495 * yield a higher probability of success on the reattempt.
2497 stale = ntohl(*(__be32 *)((u8 *)err + sizeof(*err)));
2498 stale = (stale * 2) / 1000;
2500 bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE;
2501 bht.param_hdr.length = htons(sizeof(bht));
2502 bht.lifespan_increment = htonl(stale);
2504 /* Build that new INIT chunk. */
2505 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
2506 reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht));
2510 sctp_addto_chunk(reply, sizeof(bht), &bht);
2512 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2513 sctp_add_cmd_sf(commands, SCTP_CMD_CLEAR_INIT_TAG, SCTP_NULL());
2515 /* Stop pending T3-rtx and heartbeat timers */
2516 sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL());
2517 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
2519 /* Delete non-primary peer ip addresses since we are transitioning
2520 * back to the COOKIE-WAIT state
2522 sctp_add_cmd_sf(commands, SCTP_CMD_DEL_NON_PRIMARY, SCTP_NULL());
2524 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2527 sctp_add_cmd_sf(commands, SCTP_CMD_T1_RETRAN,
2528 SCTP_TRANSPORT(asoc->peer.primary_path));
2530 /* Cast away the const modifier, as we want to just
2531 * rerun it through as a sideffect.
2533 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_INC, SCTP_NULL());
2535 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2536 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
2537 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2538 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
2539 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
2540 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2542 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2544 return SCTP_DISPOSITION_CONSUME;
2547 return SCTP_DISPOSITION_NOMEM;
2554 * After checking the Verification Tag, the receiving endpoint shall
2555 * remove the association from its record, and shall report the
2556 * termination to its upper layer.
2558 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2559 * B) Rules for packet carrying ABORT:
2561 * - The endpoint shall always fill in the Verification Tag field of the
2562 * outbound packet with the destination endpoint's tag value if it
2565 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2566 * MUST follow the procedure described in Section 8.4.
2568 * - The receiver MUST accept the packet if the Verification Tag
2569 * matches either its own tag, OR the tag of its peer. Otherwise, the
2570 * receiver MUST silently discard the packet and take no further
2574 * (endpoint, asoc, chunk)
2577 * (asoc, reply_msg, msg_up, timers, counters)
2579 * The return value is the disposition of the chunk.
2581 enum sctp_disposition sctp_sf_do_9_1_abort(
2583 const struct sctp_endpoint *ep,
2584 const struct sctp_association *asoc,
2585 const union sctp_subtype type,
2587 struct sctp_cmd_seq *commands)
2589 struct sctp_chunk *chunk = arg;
2591 if (!sctp_vtag_verify_either(chunk, asoc))
2592 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2594 /* Make sure that the ABORT chunk has a valid length.
2595 * Since this is an ABORT chunk, we have to discard it
2596 * because of the following text:
2597 * RFC 2960, Section 3.3.7
2598 * If an endpoint receives an ABORT with a format error or for an
2599 * association that doesn't exist, it MUST silently discard it.
2600 * Because the length is "invalid", we can't really discard just
2601 * as we do not know its true length. So, to be safe, discard the
2604 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk)))
2605 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2607 /* ADD-IP: Special case for ABORT chunks
2608 * F4) One special consideration is that ABORT Chunks arriving
2609 * destined to the IP address being deleted MUST be
2610 * ignored (see Section 5.3.1 for further details).
2612 if (SCTP_ADDR_DEL ==
2613 sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
2614 return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands);
2616 if (!sctp_err_chunk_valid(chunk))
2617 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2619 return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands);
2622 static enum sctp_disposition __sctp_sf_do_9_1_abort(
2624 const struct sctp_endpoint *ep,
2625 const struct sctp_association *asoc,
2626 const union sctp_subtype type,
2628 struct sctp_cmd_seq *commands)
2630 __be16 error = SCTP_ERROR_NO_ERROR;
2631 struct sctp_chunk *chunk = arg;
2634 /* See if we have an error cause code in the chunk. */
2635 len = ntohs(chunk->chunk_hdr->length);
2636 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2637 error = ((struct sctp_errhdr *)chunk->skb->data)->cause;
2639 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNRESET));
2640 /* ASSOC_FAILED will DELETE_TCB. */
2641 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_PERR(error));
2642 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
2643 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
2645 return SCTP_DISPOSITION_ABORT;
2649 * Process an ABORT. (COOKIE-WAIT state)
2651 * See sctp_sf_do_9_1_abort() above.
2653 enum sctp_disposition sctp_sf_cookie_wait_abort(
2655 const struct sctp_endpoint *ep,
2656 const struct sctp_association *asoc,
2657 const union sctp_subtype type,
2659 struct sctp_cmd_seq *commands)
2661 __be16 error = SCTP_ERROR_NO_ERROR;
2662 struct sctp_chunk *chunk = arg;
2665 if (!sctp_vtag_verify_either(chunk, asoc))
2666 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2668 /* Make sure that the ABORT chunk has a valid length.
2669 * Since this is an ABORT chunk, we have to discard it
2670 * because of the following text:
2671 * RFC 2960, Section 3.3.7
2672 * If an endpoint receives an ABORT with a format error or for an
2673 * association that doesn't exist, it MUST silently discard it.
2674 * Because the length is "invalid", we can't really discard just
2675 * as we do not know its true length. So, to be safe, discard the
2678 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk)))
2679 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2681 /* See if we have an error cause code in the chunk. */
2682 len = ntohs(chunk->chunk_hdr->length);
2683 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2684 error = ((struct sctp_errhdr *)chunk->skb->data)->cause;
2686 return sctp_stop_t1_and_abort(net, commands, error, ECONNREFUSED, asoc,
2691 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2693 enum sctp_disposition sctp_sf_cookie_wait_icmp_abort(
2695 const struct sctp_endpoint *ep,
2696 const struct sctp_association *asoc,
2697 const union sctp_subtype type,
2699 struct sctp_cmd_seq *commands)
2701 return sctp_stop_t1_and_abort(net, commands, SCTP_ERROR_NO_ERROR,
2703 (struct sctp_transport *)arg);
2707 * Process an ABORT. (COOKIE-ECHOED state)
2709 enum sctp_disposition sctp_sf_cookie_echoed_abort(
2711 const struct sctp_endpoint *ep,
2712 const struct sctp_association *asoc,
2713 const union sctp_subtype type,
2715 struct sctp_cmd_seq *commands)
2717 /* There is a single T1 timer, so we should be able to use
2718 * common function with the COOKIE-WAIT state.
2720 return sctp_sf_cookie_wait_abort(net, ep, asoc, type, arg, commands);
2724 * Stop T1 timer and abort association with "INIT failed".
2726 * This is common code called by several sctp_sf_*_abort() functions above.
2728 static enum sctp_disposition sctp_stop_t1_and_abort(
2730 struct sctp_cmd_seq *commands,
2731 __be16 error, int sk_err,
2732 const struct sctp_association *asoc,
2733 struct sctp_transport *transport)
2735 pr_debug("%s: ABORT received (INIT)\n", __func__);
2737 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2738 SCTP_STATE(SCTP_STATE_CLOSED));
2739 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
2740 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2741 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2742 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(sk_err));
2743 /* CMD_INIT_FAILED will DELETE_TCB. */
2744 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2747 return SCTP_DISPOSITION_ABORT;
2751 * sctp_sf_do_9_2_shut
2754 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2755 * - enter the SHUTDOWN-RECEIVED state,
2757 * - stop accepting new data from its SCTP user
2759 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2760 * that all its outstanding DATA chunks have been received by the
2763 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2764 * send a SHUTDOWN in response to a ULP request. And should discard
2765 * subsequent SHUTDOWN chunks.
2767 * If there are still outstanding DATA chunks left, the SHUTDOWN
2768 * receiver shall continue to follow normal data transmission
2769 * procedures defined in Section 6 until all outstanding DATA chunks
2770 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2771 * new data from its SCTP user.
2773 * Verification Tag: 8.5 Verification Tag [Normal verification]
2776 * (endpoint, asoc, chunk)
2779 * (asoc, reply_msg, msg_up, timers, counters)
2781 * The return value is the disposition of the chunk.
2783 enum sctp_disposition sctp_sf_do_9_2_shutdown(
2785 const struct sctp_endpoint *ep,
2786 const struct sctp_association *asoc,
2787 const union sctp_subtype type,
2789 struct sctp_cmd_seq *commands)
2791 enum sctp_disposition disposition;
2792 struct sctp_chunk *chunk = arg;
2793 struct sctp_shutdownhdr *sdh;
2794 struct sctp_ulpevent *ev;
2797 if (!sctp_vtag_verify(chunk, asoc))
2798 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2800 /* Make sure that the SHUTDOWN chunk has a valid length. */
2801 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk)))
2802 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
2805 /* Convert the elaborate header. */
2806 sdh = (struct sctp_shutdownhdr *)chunk->skb->data;
2807 skb_pull(chunk->skb, sizeof(*sdh));
2808 chunk->subh.shutdown_hdr = sdh;
2809 ctsn = ntohl(sdh->cum_tsn_ack);
2811 if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
2812 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__, ctsn,
2813 asoc->ctsn_ack_point);
2815 return SCTP_DISPOSITION_DISCARD;
2818 /* If Cumulative TSN Ack beyond the max tsn currently
2819 * send, terminating the association and respond to the
2820 * sender with an ABORT.
2822 if (!TSN_lt(ctsn, asoc->next_tsn))
2823 return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands);
2825 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2826 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2827 * inform the application that it should cease sending data.
2829 ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC);
2831 disposition = SCTP_DISPOSITION_NOMEM;
2834 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
2836 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2837 * - enter the SHUTDOWN-RECEIVED state,
2838 * - stop accepting new data from its SCTP user
2840 * [This is implicit in the new state.]
2842 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2843 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED));
2844 disposition = SCTP_DISPOSITION_CONSUME;
2846 if (sctp_outq_is_empty(&asoc->outqueue)) {
2847 disposition = sctp_sf_do_9_2_shutdown_ack(net, ep, asoc, type,
2851 if (SCTP_DISPOSITION_NOMEM == disposition)
2854 /* - verify, by checking the Cumulative TSN Ack field of the
2855 * chunk, that all its outstanding DATA chunks have been
2856 * received by the SHUTDOWN sender.
2858 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
2859 SCTP_BE32(chunk->subh.shutdown_hdr->cum_tsn_ack));
2866 * sctp_sf_do_9_2_shut_ctsn
2868 * Once an endpoint has reached the SHUTDOWN-RECEIVED state,
2869 * it MUST NOT send a SHUTDOWN in response to a ULP request.
2870 * The Cumulative TSN Ack of the received SHUTDOWN chunk
2871 * MUST be processed.
2873 enum sctp_disposition sctp_sf_do_9_2_shut_ctsn(
2875 const struct sctp_endpoint *ep,
2876 const struct sctp_association *asoc,
2877 const union sctp_subtype type,
2879 struct sctp_cmd_seq *commands)
2881 struct sctp_chunk *chunk = arg;
2882 struct sctp_shutdownhdr *sdh;
2885 if (!sctp_vtag_verify(chunk, asoc))
2886 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
2888 /* Make sure that the SHUTDOWN chunk has a valid length. */
2889 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk)))
2890 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
2893 sdh = (struct sctp_shutdownhdr *)chunk->skb->data;
2894 ctsn = ntohl(sdh->cum_tsn_ack);
2896 if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
2897 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__, ctsn,
2898 asoc->ctsn_ack_point);
2900 return SCTP_DISPOSITION_DISCARD;
2903 /* If Cumulative TSN Ack beyond the max tsn currently
2904 * send, terminating the association and respond to the
2905 * sender with an ABORT.
2907 if (!TSN_lt(ctsn, asoc->next_tsn))
2908 return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands);
2910 /* verify, by checking the Cumulative TSN Ack field of the
2911 * chunk, that all its outstanding DATA chunks have been
2912 * received by the SHUTDOWN sender.
2914 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
2915 SCTP_BE32(sdh->cum_tsn_ack));
2917 return SCTP_DISPOSITION_CONSUME;
2921 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2922 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2923 * transport addresses (either in the IP addresses or in the INIT chunk)
2924 * that belong to this association, it should discard the INIT chunk and
2925 * retransmit the SHUTDOWN ACK chunk.
2927 enum sctp_disposition sctp_sf_do_9_2_reshutack(
2929 const struct sctp_endpoint *ep,
2930 const struct sctp_association *asoc,
2931 const union sctp_subtype type,
2933 struct sctp_cmd_seq *commands)
2935 struct sctp_chunk *chunk = arg;
2936 struct sctp_chunk *reply;
2938 /* Make sure that the chunk has a valid length */
2939 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
2940 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
2943 /* Since we are not going to really process this INIT, there
2944 * is no point in verifying chunk boundries. Just generate
2947 reply = sctp_make_shutdown_ack(asoc, chunk);
2951 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2952 * the T2-SHUTDOWN timer.
2954 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
2956 /* and restart the T2-shutdown timer. */
2957 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2958 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2960 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2962 return SCTP_DISPOSITION_CONSUME;
2964 return SCTP_DISPOSITION_NOMEM;
2968 * sctp_sf_do_ecn_cwr
2970 * Section: Appendix A: Explicit Congestion Notification
2974 * RFC 2481 details a specific bit for a sender to send in the header of
2975 * its next outbound TCP segment to indicate to its peer that it has
2976 * reduced its congestion window. This is termed the CWR bit. For
2977 * SCTP the same indication is made by including the CWR chunk.
2978 * This chunk contains one data element, i.e. the TSN number that
2979 * was sent in the ECNE chunk. This element represents the lowest
2980 * TSN number in the datagram that was originally marked with the
2983 * Verification Tag: 8.5 Verification Tag [Normal verification]
2985 * (endpoint, asoc, chunk)
2988 * (asoc, reply_msg, msg_up, timers, counters)
2990 * The return value is the disposition of the chunk.
2992 enum sctp_disposition sctp_sf_do_ecn_cwr(struct net *net,
2993 const struct sctp_endpoint *ep,
2994 const struct sctp_association *asoc,
2995 const union sctp_subtype type,
2997 struct sctp_cmd_seq *commands)
2999 struct sctp_chunk *chunk = arg;
3000 struct sctp_cwrhdr *cwr;
3003 if (!sctp_vtag_verify(chunk, asoc))
3004 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3006 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_ecne_chunk)))
3007 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3010 cwr = (struct sctp_cwrhdr *)chunk->skb->data;
3011 skb_pull(chunk->skb, sizeof(*cwr));
3013 lowest_tsn = ntohl(cwr->lowest_tsn);
3015 /* Does this CWR ack the last sent congestion notification? */
3016 if (TSN_lte(asoc->last_ecne_tsn, lowest_tsn)) {
3017 /* Stop sending ECNE. */
3018 sctp_add_cmd_sf(commands,
3020 SCTP_U32(lowest_tsn));
3022 return SCTP_DISPOSITION_CONSUME;
3028 * Section: Appendix A: Explicit Congestion Notification
3032 * RFC 2481 details a specific bit for a receiver to send back in its
3033 * TCP acknowledgements to notify the sender of the Congestion
3034 * Experienced (CE) bit having arrived from the network. For SCTP this
3035 * same indication is made by including the ECNE chunk. This chunk
3036 * contains one data element, i.e. the lowest TSN associated with the IP
3037 * datagram marked with the CE bit.....
3039 * Verification Tag: 8.5 Verification Tag [Normal verification]
3041 * (endpoint, asoc, chunk)
3044 * (asoc, reply_msg, msg_up, timers, counters)
3046 * The return value is the disposition of the chunk.
3048 enum sctp_disposition sctp_sf_do_ecne(struct net *net,
3049 const struct sctp_endpoint *ep,
3050 const struct sctp_association *asoc,
3051 const union sctp_subtype type,
3052 void *arg, struct sctp_cmd_seq *commands)
3054 struct sctp_chunk *chunk = arg;
3055 struct sctp_ecnehdr *ecne;
3057 if (!sctp_vtag_verify(chunk, asoc))
3058 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3060 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_ecne_chunk)))
3061 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3064 ecne = (struct sctp_ecnehdr *)chunk->skb->data;
3065 skb_pull(chunk->skb, sizeof(*ecne));
3067 /* If this is a newer ECNE than the last CWR packet we sent out */
3068 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE,
3069 SCTP_U32(ntohl(ecne->lowest_tsn)));
3071 return SCTP_DISPOSITION_CONSUME;
3075 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
3077 * The SCTP endpoint MUST always acknowledge the reception of each valid
3080 * The guidelines on delayed acknowledgement algorithm specified in
3081 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
3082 * acknowledgement SHOULD be generated for at least every second packet
3083 * (not every second DATA chunk) received, and SHOULD be generated within
3084 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
3085 * situations it may be beneficial for an SCTP transmitter to be more
3086 * conservative than the algorithms detailed in this document allow.
3087 * However, an SCTP transmitter MUST NOT be more aggressive than the
3088 * following algorithms allow.
3090 * A SCTP receiver MUST NOT generate more than one SACK for every
3091 * incoming packet, other than to update the offered window as the
3092 * receiving application consumes new data.
3094 * Verification Tag: 8.5 Verification Tag [Normal verification]
3097 * (endpoint, asoc, chunk)
3100 * (asoc, reply_msg, msg_up, timers, counters)
3102 * The return value is the disposition of the chunk.
3104 enum sctp_disposition sctp_sf_eat_data_6_2(struct net *net,
3105 const struct sctp_endpoint *ep,
3106 const struct sctp_association *asoc,
3107 const union sctp_subtype type,
3109 struct sctp_cmd_seq *commands)
3111 union sctp_arg force = SCTP_NOFORCE();
3112 struct sctp_chunk *chunk = arg;
3115 if (!sctp_vtag_verify(chunk, asoc)) {
3116 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3118 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3121 if (!sctp_chunk_length_valid(chunk, sctp_datachk_len(&asoc->stream)))
3122 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3125 error = sctp_eat_data(asoc, chunk, commands);
3127 case SCTP_IERROR_NO_ERROR:
3129 case SCTP_IERROR_HIGH_TSN:
3130 case SCTP_IERROR_BAD_STREAM:
3131 SCTP_INC_STATS(net, SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
3132 goto discard_noforce;
3133 case SCTP_IERROR_DUP_TSN:
3134 case SCTP_IERROR_IGNORE_TSN:
3135 SCTP_INC_STATS(net, SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
3137 case SCTP_IERROR_NO_DATA:
3138 return SCTP_DISPOSITION_ABORT;
3139 case SCTP_IERROR_PROTO_VIOLATION:
3140 return sctp_sf_abort_violation(net, ep, asoc, chunk, commands,
3141 (u8 *)chunk->subh.data_hdr,
3142 sctp_datahdr_len(&asoc->stream));
3147 if (chunk->chunk_hdr->flags & SCTP_DATA_SACK_IMM)
3148 force = SCTP_FORCE();
3150 if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) {
3151 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3152 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
3155 /* If this is the last chunk in a packet, we need to count it
3156 * toward sack generation. Note that we need to SACK every
3157 * OTHER packet containing data chunks, EVEN IF WE DISCARD
3158 * THEM. We elect to NOT generate SACK's if the chunk fails
3159 * the verification tag test.
3161 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
3163 * The SCTP endpoint MUST always acknowledge the reception of
3164 * each valid DATA chunk.
3166 * The guidelines on delayed acknowledgement algorithm
3167 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
3168 * Specifically, an acknowledgement SHOULD be generated for at
3169 * least every second packet (not every second DATA chunk)
3170 * received, and SHOULD be generated within 200 ms of the
3171 * arrival of any unacknowledged DATA chunk. In some
3172 * situations it may be beneficial for an SCTP transmitter to
3173 * be more conservative than the algorithms detailed in this
3174 * document allow. However, an SCTP transmitter MUST NOT be
3175 * more aggressive than the following algorithms allow.
3177 if (chunk->end_of_packet)
3178 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, force);
3180 return SCTP_DISPOSITION_CONSUME;
3183 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
3185 * When a packet arrives with duplicate DATA chunk(s) and with
3186 * no new DATA chunk(s), the endpoint MUST immediately send a
3187 * SACK with no delay. If a packet arrives with duplicate
3188 * DATA chunk(s) bundled with new DATA chunks, the endpoint
3189 * MAY immediately send a SACK. Normally receipt of duplicate
3190 * DATA chunks will occur when the original SACK chunk was lost
3191 * and the peer's RTO has expired. The duplicate TSN number(s)
3192 * SHOULD be reported in the SACK as duplicate.
3194 /* In our case, we split the MAY SACK advice up whether or not
3195 * the last chunk is a duplicate.'
3197 if (chunk->end_of_packet)
3198 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
3199 return SCTP_DISPOSITION_DISCARD;
3202 if (chunk->end_of_packet)
3203 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, force);
3205 return SCTP_DISPOSITION_DISCARD;
3209 * sctp_sf_eat_data_fast_4_4
3212 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
3213 * DATA chunks without delay.
3215 * Verification Tag: 8.5 Verification Tag [Normal verification]
3217 * (endpoint, asoc, chunk)
3220 * (asoc, reply_msg, msg_up, timers, counters)
3222 * The return value is the disposition of the chunk.
3224 enum sctp_disposition sctp_sf_eat_data_fast_4_4(
3226 const struct sctp_endpoint *ep,
3227 const struct sctp_association *asoc,
3228 const union sctp_subtype type,
3230 struct sctp_cmd_seq *commands)
3232 struct sctp_chunk *chunk = arg;
3235 if (!sctp_vtag_verify(chunk, asoc)) {
3236 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3238 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3241 if (!sctp_chunk_length_valid(chunk, sctp_datachk_len(&asoc->stream)))
3242 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3245 error = sctp_eat_data(asoc, chunk, commands);
3247 case SCTP_IERROR_NO_ERROR:
3248 case SCTP_IERROR_HIGH_TSN:
3249 case SCTP_IERROR_DUP_TSN:
3250 case SCTP_IERROR_IGNORE_TSN:
3251 case SCTP_IERROR_BAD_STREAM:
3253 case SCTP_IERROR_NO_DATA:
3254 return SCTP_DISPOSITION_ABORT;
3255 case SCTP_IERROR_PROTO_VIOLATION:
3256 return sctp_sf_abort_violation(net, ep, asoc, chunk, commands,
3257 (u8 *)chunk->subh.data_hdr,
3258 sctp_datahdr_len(&asoc->stream));
3263 /* Go a head and force a SACK, since we are shutting down. */
3265 /* Implementor's Guide.
3267 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3268 * respond to each received packet containing one or more DATA chunk(s)
3269 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3271 if (chunk->end_of_packet) {
3272 /* We must delay the chunk creation since the cumulative
3273 * TSN has not been updated yet.
3275 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
3276 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
3277 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3278 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3281 return SCTP_DISPOSITION_CONSUME;
3285 * Section: 6.2 Processing a Received SACK
3286 * D) Any time a SACK arrives, the endpoint performs the following:
3288 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
3289 * then drop the SACK. Since Cumulative TSN Ack is monotonically
3290 * increasing, a SACK whose Cumulative TSN Ack is less than the
3291 * Cumulative TSN Ack Point indicates an out-of-order SACK.
3293 * ii) Set rwnd equal to the newly received a_rwnd minus the number
3294 * of bytes still outstanding after processing the Cumulative TSN Ack
3295 * and the Gap Ack Blocks.
3297 * iii) If the SACK is missing a TSN that was previously
3298 * acknowledged via a Gap Ack Block (e.g., the data receiver
3299 * reneged on the data), then mark the corresponding DATA chunk
3300 * as available for retransmit: Mark it as missing for fast
3301 * retransmit as described in Section 7.2.4 and if no retransmit
3302 * timer is running for the destination address to which the DATA
3303 * chunk was originally transmitted, then T3-rtx is started for
3304 * that destination address.
3306 * Verification Tag: 8.5 Verification Tag [Normal verification]
3309 * (endpoint, asoc, chunk)
3312 * (asoc, reply_msg, msg_up, timers, counters)
3314 * The return value is the disposition of the chunk.
3316 enum sctp_disposition sctp_sf_eat_sack_6_2(struct net *net,
3317 const struct sctp_endpoint *ep,
3318 const struct sctp_association *asoc,
3319 const union sctp_subtype type,
3321 struct sctp_cmd_seq *commands)
3323 struct sctp_chunk *chunk = arg;
3324 struct sctp_sackhdr *sackh;
3327 trace_sctp_probe(ep, asoc, chunk);
3329 if (!sctp_vtag_verify(chunk, asoc))
3330 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3332 /* Make sure that the SACK chunk has a valid length. */
3333 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_sack_chunk)))
3334 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3337 /* Pull the SACK chunk from the data buffer */
3338 sackh = sctp_sm_pull_sack(chunk);
3339 /* Was this a bogus SACK? */
3341 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3342 chunk->subh.sack_hdr = sackh;
3343 ctsn = ntohl(sackh->cum_tsn_ack);
3345 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
3346 * Ack Point, then drop the SACK. Since Cumulative TSN
3347 * Ack is monotonically increasing, a SACK whose
3348 * Cumulative TSN Ack is less than the Cumulative TSN Ack
3349 * Point indicates an out-of-order SACK.
3351 if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
3352 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__, ctsn,
3353 asoc->ctsn_ack_point);
3355 return SCTP_DISPOSITION_DISCARD;
3358 /* If Cumulative TSN Ack beyond the max tsn currently
3359 * send, terminating the association and respond to the
3360 * sender with an ABORT.
3362 if (!TSN_lt(ctsn, asoc->next_tsn))
3363 return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands);
3365 /* Return this SACK for further processing. */
3366 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_CHUNK(chunk));
3368 /* Note: We do the rest of the work on the PROCESS_SACK
3371 return SCTP_DISPOSITION_CONSUME;
3375 * Generate an ABORT in response to a packet.
3377 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
3379 * 8) The receiver should respond to the sender of the OOTB packet with
3380 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3381 * MUST fill in the Verification Tag field of the outbound packet
3382 * with the value found in the Verification Tag field of the OOTB
3383 * packet and set the T-bit in the Chunk Flags to indicate that the
3384 * Verification Tag is reflected. After sending this ABORT, the
3385 * receiver of the OOTB packet shall discard the OOTB packet and take
3386 * no further action.
3390 * The return value is the disposition of the chunk.
3392 static enum sctp_disposition sctp_sf_tabort_8_4_8(
3394 const struct sctp_endpoint *ep,
3395 const struct sctp_association *asoc,
3396 const union sctp_subtype type,
3398 struct sctp_cmd_seq *commands)
3400 struct sctp_packet *packet = NULL;
3401 struct sctp_chunk *chunk = arg;
3402 struct sctp_chunk *abort;
3404 packet = sctp_ootb_pkt_new(net, asoc, chunk);
3406 return SCTP_DISPOSITION_NOMEM;
3408 /* Make an ABORT. The T bit will be set if the asoc
3411 abort = sctp_make_abort(asoc, chunk, 0);
3413 sctp_ootb_pkt_free(packet);
3414 return SCTP_DISPOSITION_NOMEM;
3417 /* Reflect vtag if T-Bit is set */
3418 if (sctp_test_T_bit(abort))
3419 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
3421 /* Set the skb to the belonging sock for accounting. */
3422 abort->skb->sk = ep->base.sk;
3424 sctp_packet_append_chunk(packet, abort);
3426 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
3427 SCTP_PACKET(packet));
3429 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
3431 sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3432 return SCTP_DISPOSITION_CONSUME;
3436 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
3437 * event as ULP notification for each cause included in the chunk.
3439 * API 5.3.1.3 - SCTP_REMOTE_ERROR
3441 * The return value is the disposition of the chunk.
3443 enum sctp_disposition sctp_sf_operr_notify(struct net *net,
3444 const struct sctp_endpoint *ep,
3445 const struct sctp_association *asoc,
3446 const union sctp_subtype type,
3448 struct sctp_cmd_seq *commands)
3450 struct sctp_chunk *chunk = arg;
3451 struct sctp_errhdr *err;
3453 if (!sctp_vtag_verify(chunk, asoc))
3454 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3456 /* Make sure that the ERROR chunk has a valid length. */
3457 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_operr_chunk)))
3458 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3460 sctp_walk_errors(err, chunk->chunk_hdr);
3461 if ((void *)err != (void *)chunk->chunk_end)
3462 return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
3463 (void *)err, commands);
3465 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR,
3468 return SCTP_DISPOSITION_CONSUME;
3472 * Process an inbound SHUTDOWN ACK.
3475 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3476 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3477 * peer, and remove all record of the association.
3479 * The return value is the disposition.
3481 enum sctp_disposition sctp_sf_do_9_2_final(struct net *net,
3482 const struct sctp_endpoint *ep,
3483 const struct sctp_association *asoc,
3484 const union sctp_subtype type,
3486 struct sctp_cmd_seq *commands)
3488 struct sctp_chunk *chunk = arg;
3489 struct sctp_chunk *reply;
3490 struct sctp_ulpevent *ev;
3492 if (!sctp_vtag_verify(chunk, asoc))
3493 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3495 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3496 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
3497 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3499 /* 10.2 H) SHUTDOWN COMPLETE notification
3501 * When SCTP completes the shutdown procedures (section 9.2) this
3502 * notification is passed to the upper layer.
3504 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
3505 0, 0, 0, NULL, GFP_ATOMIC);
3509 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3510 reply = sctp_make_shutdown_complete(asoc, chunk);
3514 /* Do all the commands now (after allocation), so that we
3515 * have consistent state if memory allocation failes
3517 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
3519 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3520 * stop the T2-shutdown timer,
3522 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3523 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3525 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3526 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3528 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3529 SCTP_STATE(SCTP_STATE_CLOSED));
3530 SCTP_INC_STATS(net, SCTP_MIB_SHUTDOWNS);
3531 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
3532 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
3534 /* ...and remove all record of the association. */
3535 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
3536 return SCTP_DISPOSITION_DELETE_TCB;
3539 sctp_ulpevent_free(ev);
3541 return SCTP_DISPOSITION_NOMEM;
3545 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3547 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3548 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3549 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3550 * packet must fill in the Verification Tag field of the outbound
3551 * packet with the Verification Tag received in the SHUTDOWN ACK and
3552 * set the T-bit in the Chunk Flags to indicate that the Verification
3555 * 8) The receiver should respond to the sender of the OOTB packet with
3556 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3557 * MUST fill in the Verification Tag field of the outbound packet
3558 * with the value found in the Verification Tag field of the OOTB
3559 * packet and set the T-bit in the Chunk Flags to indicate that the
3560 * Verification Tag is reflected. After sending this ABORT, the
3561 * receiver of the OOTB packet shall discard the OOTB packet and take
3562 * no further action.
3564 enum sctp_disposition sctp_sf_ootb(struct net *net,
3565 const struct sctp_endpoint *ep,
3566 const struct sctp_association *asoc,
3567 const union sctp_subtype type,
3568 void *arg, struct sctp_cmd_seq *commands)
3570 struct sctp_chunk *chunk = arg;
3571 struct sk_buff *skb = chunk->skb;
3572 struct sctp_chunkhdr *ch;
3573 struct sctp_errhdr *err;
3574 int ootb_cookie_ack = 0;
3575 int ootb_shut_ack = 0;
3578 SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES);
3580 ch = (struct sctp_chunkhdr *)chunk->chunk_hdr;
3582 /* Report violation if the chunk is less then minimal */
3583 if (ntohs(ch->length) < sizeof(*ch))
3584 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3587 /* Report violation if chunk len overflows */
3588 ch_end = ((__u8 *)ch) + SCTP_PAD4(ntohs(ch->length));
3589 if (ch_end > skb_tail_pointer(skb))
3590 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3593 /* Now that we know we at least have a chunk header,
3594 * do things that are type appropriate.
3596 if (SCTP_CID_SHUTDOWN_ACK == ch->type)
3599 /* RFC 2960, Section 3.3.7
3600 * Moreover, under any circumstances, an endpoint that
3601 * receives an ABORT MUST NOT respond to that ABORT by
3602 * sending an ABORT of its own.
3604 if (SCTP_CID_ABORT == ch->type)
3605 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3607 /* RFC 8.4, 7) If the packet contains a "Stale cookie" ERROR
3608 * or a COOKIE ACK the SCTP Packet should be silently
3612 if (SCTP_CID_COOKIE_ACK == ch->type)
3613 ootb_cookie_ack = 1;
3615 if (SCTP_CID_ERROR == ch->type) {
3616 sctp_walk_errors(err, ch) {
3617 if (SCTP_ERROR_STALE_COOKIE == err->cause) {
3618 ootb_cookie_ack = 1;
3624 ch = (struct sctp_chunkhdr *)ch_end;
3625 } while (ch_end < skb_tail_pointer(skb));
3628 return sctp_sf_shut_8_4_5(net, ep, asoc, type, arg, commands);
3629 else if (ootb_cookie_ack)
3630 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3632 return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
3636 * Handle an "Out of the blue" SHUTDOWN ACK.
3638 * Section: 8.4 5, sctpimpguide 2.41.
3640 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3641 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3642 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3643 * packet must fill in the Verification Tag field of the outbound
3644 * packet with the Verification Tag received in the SHUTDOWN ACK and
3645 * set the T-bit in the Chunk Flags to indicate that the Verification
3649 * (endpoint, asoc, type, arg, commands)
3652 * (enum sctp_disposition)
3654 * The return value is the disposition of the chunk.
3656 static enum sctp_disposition sctp_sf_shut_8_4_5(
3658 const struct sctp_endpoint *ep,
3659 const struct sctp_association *asoc,
3660 const union sctp_subtype type,
3662 struct sctp_cmd_seq *commands)
3664 struct sctp_packet *packet = NULL;
3665 struct sctp_chunk *chunk = arg;
3666 struct sctp_chunk *shut;
3668 packet = sctp_ootb_pkt_new(net, asoc, chunk);
3670 return SCTP_DISPOSITION_NOMEM;
3672 /* Make an SHUTDOWN_COMPLETE.
3673 * The T bit will be set if the asoc is NULL.
3675 shut = sctp_make_shutdown_complete(asoc, chunk);
3677 sctp_ootb_pkt_free(packet);
3678 return SCTP_DISPOSITION_NOMEM;
3681 /* Reflect vtag if T-Bit is set */
3682 if (sctp_test_T_bit(shut))
3683 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
3685 /* Set the skb to the belonging sock for accounting. */
3686 shut->skb->sk = ep->base.sk;
3688 sctp_packet_append_chunk(packet, shut);
3690 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
3691 SCTP_PACKET(packet));
3693 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
3695 /* If the chunk length is invalid, we don't want to process
3696 * the reset of the packet.
3698 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
3699 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3701 /* We need to discard the rest of the packet to prevent
3702 * potential bomming attacks from additional bundled chunks.
3703 * This is documented in SCTP Threats ID.
3705 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3709 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3711 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3712 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3713 * procedures in section 8.4 SHOULD be followed, in other words it
3714 * should be treated as an Out Of The Blue packet.
3715 * [This means that we do NOT check the Verification Tag on these
3719 enum sctp_disposition sctp_sf_do_8_5_1_E_sa(struct net *net,
3720 const struct sctp_endpoint *ep,
3721 const struct sctp_association *asoc,
3722 const union sctp_subtype type,
3724 struct sctp_cmd_seq *commands)
3726 struct sctp_chunk *chunk = arg;
3728 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3729 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
3730 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3733 /* Although we do have an association in this case, it corresponds
3734 * to a restarted association. So the packet is treated as an OOTB
3735 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3736 * called with a NULL association.
3738 SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES);
3740 return sctp_sf_shut_8_4_5(net, ep, NULL, type, arg, commands);
3743 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3744 enum sctp_disposition sctp_sf_do_asconf(struct net *net,
3745 const struct sctp_endpoint *ep,
3746 const struct sctp_association *asoc,
3747 const union sctp_subtype type,
3749 struct sctp_cmd_seq *commands)
3751 struct sctp_paramhdr *err_param = NULL;
3752 struct sctp_chunk *asconf_ack = NULL;
3753 struct sctp_chunk *chunk = arg;
3754 struct sctp_addiphdr *hdr;
3757 if (!sctp_vtag_verify(chunk, asoc)) {
3758 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3760 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3763 /* ADD-IP: Section 4.1.1
3764 * This chunk MUST be sent in an authenticated way by using
3765 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3766 * is received unauthenticated it MUST be silently discarded as
3767 * described in [I-D.ietf-tsvwg-sctp-auth].
3769 if (!net->sctp.addip_noauth && !chunk->auth)
3770 return sctp_sf_discard_chunk(net, ep, asoc, type, arg,
3773 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3774 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_addip_chunk)))
3775 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3778 hdr = (struct sctp_addiphdr *)chunk->skb->data;
3779 serial = ntohl(hdr->serial);
3781 /* Verify the ASCONF chunk before processing it. */
3782 if (!sctp_verify_asconf(asoc, chunk, true, &err_param))
3783 return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
3784 (void *)err_param, commands);
3786 /* ADDIP 5.2 E1) Compare the value of the serial number to the value
3787 * the endpoint stored in a new association variable
3788 * 'Peer-Serial-Number'.
3790 if (serial == asoc->peer.addip_serial + 1) {
3791 /* If this is the first instance of ASCONF in the packet,
3792 * we can clean our old ASCONF-ACKs.
3794 if (!chunk->has_asconf)
3795 sctp_assoc_clean_asconf_ack_cache(asoc);
3797 /* ADDIP 5.2 E4) When the Sequence Number matches the next one
3798 * expected, process the ASCONF as described below and after
3799 * processing the ASCONF Chunk, append an ASCONF-ACK Chunk to
3800 * the response packet and cache a copy of it (in the event it
3801 * later needs to be retransmitted).
3803 * Essentially, do V1-V5.
3805 asconf_ack = sctp_process_asconf((struct sctp_association *)
3808 return SCTP_DISPOSITION_NOMEM;
3809 } else if (serial < asoc->peer.addip_serial + 1) {
3811 * If the value found in the Sequence Number is less than the
3812 * ('Peer- Sequence-Number' + 1), simply skip to the next
3813 * ASCONF, and include in the outbound response packet
3814 * any previously cached ASCONF-ACK response that was
3815 * sent and saved that matches the Sequence Number of the
3816 * ASCONF. Note: It is possible that no cached ASCONF-ACK
3817 * Chunk exists. This will occur when an older ASCONF
3818 * arrives out of order. In such a case, the receiver
3819 * should skip the ASCONF Chunk and not include ASCONF-ACK
3820 * Chunk for that chunk.
3822 asconf_ack = sctp_assoc_lookup_asconf_ack(asoc, hdr->serial);
3824 return SCTP_DISPOSITION_DISCARD;
3826 /* Reset the transport so that we select the correct one
3827 * this time around. This is to make sure that we don't
3828 * accidentally use a stale transport that's been removed.
3830 asconf_ack->transport = NULL;
3832 /* ADDIP 5.2 E5) Otherwise, the ASCONF Chunk is discarded since
3833 * it must be either a stale packet or from an attacker.
3835 return SCTP_DISPOSITION_DISCARD;
3838 /* ADDIP 5.2 E6) The destination address of the SCTP packet
3839 * containing the ASCONF-ACK Chunks MUST be the source address of
3840 * the SCTP packet that held the ASCONF Chunks.
3842 * To do this properly, we'll set the destination address of the chunk
3843 * and at the transmit time, will try look up the transport to use.
3844 * Since ASCONFs may be bundled, the correct transport may not be
3845 * created until we process the entire packet, thus this workaround.
3847 asconf_ack->dest = chunk->source;
3848 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack));
3849 if (asoc->new_transport) {
3850 sctp_sf_heartbeat(ep, asoc, type, asoc->new_transport, commands);
3851 ((struct sctp_association *)asoc)->new_transport = NULL;
3854 return SCTP_DISPOSITION_CONSUME;
3857 static enum sctp_disposition sctp_send_next_asconf(
3859 const struct sctp_endpoint *ep,
3860 struct sctp_association *asoc,
3861 const union sctp_subtype type,
3862 struct sctp_cmd_seq *commands)
3864 struct sctp_chunk *asconf;
3865 struct list_head *entry;
3867 if (list_empty(&asoc->addip_chunk_list))
3868 return SCTP_DISPOSITION_CONSUME;
3870 entry = asoc->addip_chunk_list.next;
3871 asconf = list_entry(entry, struct sctp_chunk, list);
3873 list_del_init(entry);
3874 sctp_chunk_hold(asconf);
3875 asoc->addip_last_asconf = asconf;
3877 return sctp_sf_do_prm_asconf(net, ep, asoc, type, asconf, commands);
3881 * ADDIP Section 4.3 General rules for address manipulation
3882 * When building TLV parameters for the ASCONF Chunk that will add or
3883 * delete IP addresses the D0 to D13 rules should be applied:
3885 enum sctp_disposition sctp_sf_do_asconf_ack(struct net *net,
3886 const struct sctp_endpoint *ep,
3887 const struct sctp_association *asoc,
3888 const union sctp_subtype type,
3890 struct sctp_cmd_seq *commands)
3892 struct sctp_chunk *last_asconf = asoc->addip_last_asconf;
3893 struct sctp_paramhdr *err_param = NULL;
3894 struct sctp_chunk *asconf_ack = arg;
3895 struct sctp_addiphdr *addip_hdr;
3896 __u32 sent_serial, rcvd_serial;
3897 struct sctp_chunk *abort;
3899 if (!sctp_vtag_verify(asconf_ack, asoc)) {
3900 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3902 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
3905 /* ADD-IP, Section 4.1.2:
3906 * This chunk MUST be sent in an authenticated way by using
3907 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3908 * is received unauthenticated it MUST be silently discarded as
3909 * described in [I-D.ietf-tsvwg-sctp-auth].
3911 if (!net->sctp.addip_noauth && !asconf_ack->auth)
3912 return sctp_sf_discard_chunk(net, ep, asoc, type, arg,
3915 /* Make sure that the ADDIP chunk has a valid length. */
3916 if (!sctp_chunk_length_valid(asconf_ack,
3917 sizeof(struct sctp_addip_chunk)))
3918 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3921 addip_hdr = (struct sctp_addiphdr *)asconf_ack->skb->data;
3922 rcvd_serial = ntohl(addip_hdr->serial);
3924 /* Verify the ASCONF-ACK chunk before processing it. */
3925 if (!sctp_verify_asconf(asoc, asconf_ack, false, &err_param))
3926 return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
3927 (void *)err_param, commands);
3930 addip_hdr = (struct sctp_addiphdr *)last_asconf->subh.addip_hdr;
3931 sent_serial = ntohl(addip_hdr->serial);
3933 sent_serial = asoc->addip_serial - 1;
3936 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3937 * equal to the next serial number to be used but no ASCONF chunk is
3938 * outstanding the endpoint MUST ABORT the association. Note that a
3939 * sequence number is greater than if it is no more than 2^^31-1
3940 * larger than the current sequence number (using serial arithmetic).
3942 if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) &&
3943 !(asoc->addip_last_asconf)) {
3944 abort = sctp_make_abort(asoc, asconf_ack,
3945 sizeof(struct sctp_errhdr));
3947 sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, 0);
3948 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3951 /* We are going to ABORT, so we might as well stop
3952 * processing the rest of the chunks in the packet.
3954 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3955 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3956 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
3957 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3958 SCTP_ERROR(ECONNABORTED));
3959 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3960 SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
3961 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
3962 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
3963 return SCTP_DISPOSITION_ABORT;
3966 if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) {
3967 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3968 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3970 if (!sctp_process_asconf_ack((struct sctp_association *)asoc,
3972 return sctp_send_next_asconf(net, ep,
3973 (struct sctp_association *)asoc,
3976 abort = sctp_make_abort(asoc, asconf_ack,
3977 sizeof(struct sctp_errhdr));
3979 sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, 0);
3980 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3983 /* We are going to ABORT, so we might as well stop
3984 * processing the rest of the chunks in the packet.
3986 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
3987 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3988 SCTP_ERROR(ECONNABORTED));
3989 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3990 SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
3991 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
3992 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
3993 return SCTP_DISPOSITION_ABORT;
3996 return SCTP_DISPOSITION_DISCARD;
3999 /* RE-CONFIG Section 5.2 Upon reception of an RECONF Chunk. */
4000 enum sctp_disposition sctp_sf_do_reconf(struct net *net,
4001 const struct sctp_endpoint *ep,
4002 const struct sctp_association *asoc,
4003 const union sctp_subtype type,
4005 struct sctp_cmd_seq *commands)
4007 struct sctp_paramhdr *err_param = NULL;
4008 struct sctp_chunk *chunk = arg;
4009 struct sctp_reconf_chunk *hdr;
4010 union sctp_params param;
4012 if (!sctp_vtag_verify(chunk, asoc)) {
4013 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
4015 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
4018 /* Make sure that the RECONF chunk has a valid length. */
4019 if (!sctp_chunk_length_valid(chunk, sizeof(*hdr)))
4020 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4023 if (!sctp_verify_reconf(asoc, chunk, &err_param))
4024 return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
4025 (void *)err_param, commands);
4027 hdr = (struct sctp_reconf_chunk *)chunk->chunk_hdr;
4028 sctp_walk_params(param, hdr, params) {
4029 struct sctp_chunk *reply = NULL;
4030 struct sctp_ulpevent *ev = NULL;
4032 if (param.p->type == SCTP_PARAM_RESET_OUT_REQUEST)
4033 reply = sctp_process_strreset_outreq(
4034 (struct sctp_association *)asoc, param, &ev);
4035 else if (param.p->type == SCTP_PARAM_RESET_IN_REQUEST)
4036 reply = sctp_process_strreset_inreq(
4037 (struct sctp_association *)asoc, param, &ev);
4038 else if (param.p->type == SCTP_PARAM_RESET_TSN_REQUEST)
4039 reply = sctp_process_strreset_tsnreq(
4040 (struct sctp_association *)asoc, param, &ev);
4041 else if (param.p->type == SCTP_PARAM_RESET_ADD_OUT_STREAMS)
4042 reply = sctp_process_strreset_addstrm_out(
4043 (struct sctp_association *)asoc, param, &ev);
4044 else if (param.p->type == SCTP_PARAM_RESET_ADD_IN_STREAMS)
4045 reply = sctp_process_strreset_addstrm_in(
4046 (struct sctp_association *)asoc, param, &ev);
4047 else if (param.p->type == SCTP_PARAM_RESET_RESPONSE)
4048 reply = sctp_process_strreset_resp(
4049 (struct sctp_association *)asoc, param, &ev);
4052 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
4056 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4060 return SCTP_DISPOSITION_CONSUME;
4064 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
4066 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
4067 * its cumulative TSN point to the value carried in the FORWARD TSN
4068 * chunk, and then MUST further advance its cumulative TSN point locally
4070 * After the above processing, the data receiver MUST stop reporting any
4071 * missing TSNs earlier than or equal to the new cumulative TSN point.
4073 * Verification Tag: 8.5 Verification Tag [Normal verification]
4075 * The return value is the disposition of the chunk.
4077 enum sctp_disposition sctp_sf_eat_fwd_tsn(struct net *net,
4078 const struct sctp_endpoint *ep,
4079 const struct sctp_association *asoc,
4080 const union sctp_subtype type,
4082 struct sctp_cmd_seq *commands)
4084 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
4085 struct sctp_chunk *chunk = arg;
4089 if (!sctp_vtag_verify(chunk, asoc)) {
4090 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
4092 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
4095 if (!asoc->peer.prsctp_capable)
4096 return sctp_sf_unk_chunk(net, ep, asoc, type, arg, commands);
4098 /* Make sure that the FORWARD_TSN chunk has valid length. */
4099 if (!sctp_chunk_length_valid(chunk, sctp_ftsnchk_len(&asoc->stream)))
4100 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4103 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
4104 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
4105 len = ntohs(chunk->chunk_hdr->length);
4106 len -= sizeof(struct sctp_chunkhdr);
4107 skb_pull(chunk->skb, len);
4109 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
4110 pr_debug("%s: TSN 0x%x\n", __func__, tsn);
4112 /* The TSN is too high--silently discard the chunk and count on it
4113 * getting retransmitted later.
4115 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
4116 goto discard_noforce;
4118 if (!asoc->stream.si->validate_ftsn(chunk))
4119 goto discard_noforce;
4121 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
4122 if (len > sctp_ftsnhdr_len(&asoc->stream))
4123 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
4126 /* Count this as receiving DATA. */
4127 if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) {
4128 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4129 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
4132 /* FIXME: For now send a SACK, but DATA processing may
4135 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
4137 return SCTP_DISPOSITION_CONSUME;
4140 return SCTP_DISPOSITION_DISCARD;
4143 enum sctp_disposition sctp_sf_eat_fwd_tsn_fast(
4145 const struct sctp_endpoint *ep,
4146 const struct sctp_association *asoc,
4147 const union sctp_subtype type,
4149 struct sctp_cmd_seq *commands)
4151 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
4152 struct sctp_chunk *chunk = arg;
4156 if (!sctp_vtag_verify(chunk, asoc)) {
4157 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
4159 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
4162 if (!asoc->peer.prsctp_capable)
4163 return sctp_sf_unk_chunk(net, ep, asoc, type, arg, commands);
4165 /* Make sure that the FORWARD_TSN chunk has a valid length. */
4166 if (!sctp_chunk_length_valid(chunk, sctp_ftsnchk_len(&asoc->stream)))
4167 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4170 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
4171 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
4172 len = ntohs(chunk->chunk_hdr->length);
4173 len -= sizeof(struct sctp_chunkhdr);
4174 skb_pull(chunk->skb, len);
4176 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
4177 pr_debug("%s: TSN 0x%x\n", __func__, tsn);
4179 /* The TSN is too high--silently discard the chunk and count on it
4180 * getting retransmitted later.
4182 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
4185 if (!asoc->stream.si->validate_ftsn(chunk))
4188 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
4189 if (len > sctp_ftsnhdr_len(&asoc->stream))
4190 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
4193 /* Go a head and force a SACK, since we are shutting down. */
4195 /* Implementor's Guide.
4197 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
4198 * respond to each received packet containing one or more DATA chunk(s)
4199 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
4201 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
4202 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
4203 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4204 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4206 return SCTP_DISPOSITION_CONSUME;
4210 * SCTP-AUTH Section 6.3 Receiving authenticated chukns
4212 * The receiver MUST use the HMAC algorithm indicated in the HMAC
4213 * Identifier field. If this algorithm was not specified by the
4214 * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk
4215 * during association setup, the AUTH chunk and all chunks after it MUST
4216 * be discarded and an ERROR chunk SHOULD be sent with the error cause
4217 * defined in Section 4.1.
4219 * If an endpoint with no shared key receives a Shared Key Identifier
4220 * other than 0, it MUST silently discard all authenticated chunks. If
4221 * the endpoint has at least one endpoint pair shared key for the peer,
4222 * it MUST use the key specified by the Shared Key Identifier if a
4223 * key has been configured for that Shared Key Identifier. If no
4224 * endpoint pair shared key has been configured for that Shared Key
4225 * Identifier, all authenticated chunks MUST be silently discarded.
4227 * Verification Tag: 8.5 Verification Tag [Normal verification]
4229 * The return value is the disposition of the chunk.
4231 static enum sctp_ierror sctp_sf_authenticate(
4232 const struct sctp_association *asoc,
4233 struct sctp_chunk *chunk)
4235 struct sctp_shared_key *sh_key = NULL;
4236 struct sctp_authhdr *auth_hdr;
4237 __u8 *save_digest, *digest;
4238 struct sctp_hmac *hmac;
4239 unsigned int sig_len;
4242 /* Pull in the auth header, so we can do some more verification */
4243 auth_hdr = (struct sctp_authhdr *)chunk->skb->data;
4244 chunk->subh.auth_hdr = auth_hdr;
4245 skb_pull(chunk->skb, sizeof(*auth_hdr));
4247 /* Make sure that we support the HMAC algorithm from the auth
4250 if (!sctp_auth_asoc_verify_hmac_id(asoc, auth_hdr->hmac_id))
4251 return SCTP_IERROR_AUTH_BAD_HMAC;
4253 /* Make sure that the provided shared key identifier has been
4256 key_id = ntohs(auth_hdr->shkey_id);
4257 if (key_id != asoc->active_key_id) {
4258 sh_key = sctp_auth_get_shkey(asoc, key_id);
4260 return SCTP_IERROR_AUTH_BAD_KEYID;
4263 /* Make sure that the length of the signature matches what
4266 sig_len = ntohs(chunk->chunk_hdr->length) -
4267 sizeof(struct sctp_auth_chunk);
4268 hmac = sctp_auth_get_hmac(ntohs(auth_hdr->hmac_id));
4269 if (sig_len != hmac->hmac_len)
4270 return SCTP_IERROR_PROTO_VIOLATION;
4272 /* Now that we've done validation checks, we can compute and
4273 * verify the hmac. The steps involved are:
4274 * 1. Save the digest from the chunk.
4275 * 2. Zero out the digest in the chunk.
4276 * 3. Compute the new digest
4277 * 4. Compare saved and new digests.
4279 digest = auth_hdr->hmac;
4280 skb_pull(chunk->skb, sig_len);
4282 save_digest = kmemdup(digest, sig_len, GFP_ATOMIC);
4286 memset(digest, 0, sig_len);
4288 sctp_auth_calculate_hmac(asoc, chunk->skb,
4289 (struct sctp_auth_chunk *)chunk->chunk_hdr,
4290 sh_key, GFP_ATOMIC);
4292 /* Discard the packet if the digests do not match */
4293 if (memcmp(save_digest, digest, sig_len)) {
4295 return SCTP_IERROR_BAD_SIG;
4301 return SCTP_IERROR_NO_ERROR;
4303 return SCTP_IERROR_NOMEM;
4306 enum sctp_disposition sctp_sf_eat_auth(struct net *net,
4307 const struct sctp_endpoint *ep,
4308 const struct sctp_association *asoc,
4309 const union sctp_subtype type,
4310 void *arg, struct sctp_cmd_seq *commands)
4312 struct sctp_chunk *chunk = arg;
4313 struct sctp_authhdr *auth_hdr;
4314 struct sctp_chunk *err_chunk;
4315 enum sctp_ierror error;
4317 /* Make sure that the peer has AUTH capable */
4318 if (!asoc->peer.auth_capable)
4319 return sctp_sf_unk_chunk(net, ep, asoc, type, arg, commands);
4321 if (!sctp_vtag_verify(chunk, asoc)) {
4322 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
4324 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
4327 /* Make sure that the AUTH chunk has valid length. */
4328 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_auth_chunk)))
4329 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4332 auth_hdr = (struct sctp_authhdr *)chunk->skb->data;
4333 error = sctp_sf_authenticate(asoc, chunk);
4335 case SCTP_IERROR_AUTH_BAD_HMAC:
4336 /* Generate the ERROR chunk and discard the rest
4339 err_chunk = sctp_make_op_error(asoc, chunk,
4340 SCTP_ERROR_UNSUP_HMAC,
4344 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4345 SCTP_CHUNK(err_chunk));
4348 case SCTP_IERROR_AUTH_BAD_KEYID:
4349 case SCTP_IERROR_BAD_SIG:
4350 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
4352 case SCTP_IERROR_PROTO_VIOLATION:
4353 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4356 case SCTP_IERROR_NOMEM:
4357 return SCTP_DISPOSITION_NOMEM;
4359 default: /* Prevent gcc warnings */
4363 if (asoc->active_key_id != ntohs(auth_hdr->shkey_id)) {
4364 struct sctp_ulpevent *ev;
4366 ev = sctp_ulpevent_make_authkey(asoc, ntohs(auth_hdr->shkey_id),
4367 SCTP_AUTH_NEW_KEY, GFP_ATOMIC);
4372 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
4376 return SCTP_DISPOSITION_CONSUME;
4380 * Process an unknown chunk.
4382 * Section: 3.2. Also, 2.1 in the implementor's guide.
4384 * Chunk Types are encoded such that the highest-order two bits specify
4385 * the action that must be taken if the processing endpoint does not
4386 * recognize the Chunk Type.
4388 * 00 - Stop processing this SCTP packet and discard it, do not process
4389 * any further chunks within it.
4391 * 01 - Stop processing this SCTP packet and discard it, do not process
4392 * any further chunks within it, and report the unrecognized
4393 * chunk in an 'Unrecognized Chunk Type'.
4395 * 10 - Skip this chunk and continue processing.
4397 * 11 - Skip this chunk and continue processing, but report in an ERROR
4398 * Chunk using the 'Unrecognized Chunk Type' cause of error.
4400 * The return value is the disposition of the chunk.
4402 enum sctp_disposition sctp_sf_unk_chunk(struct net *net,
4403 const struct sctp_endpoint *ep,
4404 const struct sctp_association *asoc,
4405 const union sctp_subtype type,
4407 struct sctp_cmd_seq *commands)
4409 struct sctp_chunk *unk_chunk = arg;
4410 struct sctp_chunk *err_chunk;
4411 struct sctp_chunkhdr *hdr;
4413 pr_debug("%s: processing unknown chunk id:%d\n", __func__, type.chunk);
4415 if (!sctp_vtag_verify(unk_chunk, asoc))
4416 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
4418 /* Make sure that the chunk has a valid length.
4419 * Since we don't know the chunk type, we use a general
4420 * chunkhdr structure to make a comparison.
4422 if (!sctp_chunk_length_valid(unk_chunk, sizeof(*hdr)))
4423 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4426 switch (type.chunk & SCTP_CID_ACTION_MASK) {
4427 case SCTP_CID_ACTION_DISCARD:
4428 /* Discard the packet. */
4429 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
4430 case SCTP_CID_ACTION_DISCARD_ERR:
4431 /* Generate an ERROR chunk as response. */
4432 hdr = unk_chunk->chunk_hdr;
4433 err_chunk = sctp_make_op_error(asoc, unk_chunk,
4434 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
4435 SCTP_PAD4(ntohs(hdr->length)),
4438 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4439 SCTP_CHUNK(err_chunk));
4442 /* Discard the packet. */
4443 sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
4444 return SCTP_DISPOSITION_CONSUME;
4445 case SCTP_CID_ACTION_SKIP:
4446 /* Skip the chunk. */
4447 return SCTP_DISPOSITION_DISCARD;
4448 case SCTP_CID_ACTION_SKIP_ERR:
4449 /* Generate an ERROR chunk as response. */
4450 hdr = unk_chunk->chunk_hdr;
4451 err_chunk = sctp_make_op_error(asoc, unk_chunk,
4452 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
4453 SCTP_PAD4(ntohs(hdr->length)),
4456 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4457 SCTP_CHUNK(err_chunk));
4459 /* Skip the chunk. */
4460 return SCTP_DISPOSITION_CONSUME;
4465 return SCTP_DISPOSITION_DISCARD;
4469 * Discard the chunk.
4471 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
4472 * [Too numerous to mention...]
4473 * Verification Tag: No verification needed.
4475 * (endpoint, asoc, chunk)
4478 * (asoc, reply_msg, msg_up, timers, counters)
4480 * The return value is the disposition of the chunk.
4482 enum sctp_disposition sctp_sf_discard_chunk(struct net *net,
4483 const struct sctp_endpoint *ep,
4484 const struct sctp_association *asoc,
4485 const union sctp_subtype type,
4487 struct sctp_cmd_seq *commands)
4489 struct sctp_chunk *chunk = arg;
4491 /* Make sure that the chunk has a valid length.
4492 * Since we don't know the chunk type, we use a general
4493 * chunkhdr structure to make a comparison.
4495 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
4496 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4499 pr_debug("%s: chunk:%d is discarded\n", __func__, type.chunk);
4501 return SCTP_DISPOSITION_DISCARD;
4505 * Discard the whole packet.
4509 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
4510 * silently discard the OOTB packet and take no further action.
4512 * Verification Tag: No verification necessary
4515 * (endpoint, asoc, chunk)
4518 * (asoc, reply_msg, msg_up, timers, counters)
4520 * The return value is the disposition of the chunk.
4522 enum sctp_disposition sctp_sf_pdiscard(struct net *net,
4523 const struct sctp_endpoint *ep,
4524 const struct sctp_association *asoc,
4525 const union sctp_subtype type,
4526 void *arg, struct sctp_cmd_seq *commands)
4528 SCTP_INC_STATS(net, SCTP_MIB_IN_PKT_DISCARDS);
4529 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
4531 return SCTP_DISPOSITION_CONSUME;
4536 * The other end is violating protocol.
4538 * Section: Not specified
4539 * Verification Tag: Not specified
4541 * (endpoint, asoc, chunk)
4544 * (asoc, reply_msg, msg_up, timers, counters)
4546 * We simply tag the chunk as a violation. The state machine will log
4547 * the violation and continue.
4549 enum sctp_disposition sctp_sf_violation(struct net *net,
4550 const struct sctp_endpoint *ep,
4551 const struct sctp_association *asoc,
4552 const union sctp_subtype type,
4554 struct sctp_cmd_seq *commands)
4556 struct sctp_chunk *chunk = arg;
4558 /* Make sure that the chunk has a valid length. */
4559 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
4560 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
4563 return SCTP_DISPOSITION_VIOLATION;
4567 * Common function to handle a protocol violation.
4569 static enum sctp_disposition sctp_sf_abort_violation(
4571 const struct sctp_endpoint *ep,
4572 const struct sctp_association *asoc,
4574 struct sctp_cmd_seq *commands,
4575 const __u8 *payload,
4576 const size_t paylen)
4578 struct sctp_packet *packet = NULL;
4579 struct sctp_chunk *chunk = arg;
4580 struct sctp_chunk *abort = NULL;
4582 /* SCTP-AUTH, Section 6.3:
4583 * It should be noted that if the receiver wants to tear
4584 * down an association in an authenticated way only, the
4585 * handling of malformed packets should not result in
4586 * tearing down the association.
4588 * This means that if we only want to abort associations
4589 * in an authenticated way (i.e AUTH+ABORT), then we
4590 * can't destroy this association just because the packet
4593 if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
4596 /* Make the abort chunk. */
4597 abort = sctp_make_abort_violation(asoc, chunk, payload, paylen);
4602 /* Treat INIT-ACK as a special case during COOKIE-WAIT. */
4603 if (chunk->chunk_hdr->type == SCTP_CID_INIT_ACK &&
4604 !asoc->peer.i.init_tag) {
4605 struct sctp_initack_chunk *initack;
4607 initack = (struct sctp_initack_chunk *)chunk->chunk_hdr;
4608 if (!sctp_chunk_length_valid(chunk, sizeof(*initack)))
4609 abort->chunk_hdr->flags |= SCTP_CHUNK_FLAG_T;
4611 unsigned int inittag;
4613 inittag = ntohl(initack->init_hdr.init_tag);
4614 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_INITTAG,
4619 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4620 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
4622 if (asoc->state <= SCTP_STATE_COOKIE_ECHOED) {
4623 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4624 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4625 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4626 SCTP_ERROR(ECONNREFUSED));
4627 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4628 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
4630 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4631 SCTP_ERROR(ECONNABORTED));
4632 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4633 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
4634 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
4637 packet = sctp_ootb_pkt_new(net, asoc, chunk);
4642 if (sctp_test_T_bit(abort))
4643 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
4645 abort->skb->sk = ep->base.sk;
4647 sctp_packet_append_chunk(packet, abort);
4649 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
4650 SCTP_PACKET(packet));
4652 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
4655 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
4658 sctp_sf_pdiscard(net, ep, asoc, SCTP_ST_CHUNK(0), arg, commands);
4659 return SCTP_DISPOSITION_ABORT;
4662 sctp_chunk_free(abort);
4664 return SCTP_DISPOSITION_NOMEM;
4668 * Handle a protocol violation when the chunk length is invalid.
4669 * "Invalid" length is identified as smaller than the minimal length a
4670 * given chunk can be. For example, a SACK chunk has invalid length
4671 * if its length is set to be smaller than the size of struct sctp_sack_chunk.
4673 * We inform the other end by sending an ABORT with a Protocol Violation
4676 * Section: Not specified
4677 * Verification Tag: Nothing to do
4679 * (endpoint, asoc, chunk)
4682 * (reply_msg, msg_up, counters)
4684 * Generate an ABORT chunk and terminate the association.
4686 static enum sctp_disposition sctp_sf_violation_chunklen(
4688 const struct sctp_endpoint *ep,
4689 const struct sctp_association *asoc,
4690 const union sctp_subtype type,
4692 struct sctp_cmd_seq *commands)
4694 static const char err_str[] = "The following chunk had invalid length:";
4696 return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str,
4701 * Handle a protocol violation when the parameter length is invalid.
4702 * If the length is smaller than the minimum length of a given parameter,
4703 * or accumulated length in multi parameters exceeds the end of the chunk,
4704 * the length is considered as invalid.
4706 static enum sctp_disposition sctp_sf_violation_paramlen(
4708 const struct sctp_endpoint *ep,
4709 const struct sctp_association *asoc,
4710 const union sctp_subtype type,
4711 void *arg, void *ext,
4712 struct sctp_cmd_seq *commands)
4714 struct sctp_paramhdr *param = ext;
4715 struct sctp_chunk *abort = NULL;
4716 struct sctp_chunk *chunk = arg;
4718 if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
4721 /* Make the abort chunk. */
4722 abort = sctp_make_violation_paramlen(asoc, chunk, param);
4726 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4727 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
4729 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4730 SCTP_ERROR(ECONNABORTED));
4731 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4732 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
4733 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
4734 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
4737 sctp_sf_pdiscard(net, ep, asoc, SCTP_ST_CHUNK(0), arg, commands);
4738 return SCTP_DISPOSITION_ABORT;
4740 return SCTP_DISPOSITION_NOMEM;
4743 /* Handle a protocol violation when the peer trying to advance the
4744 * cumulative tsn ack to a point beyond the max tsn currently sent.
4746 * We inform the other end by sending an ABORT with a Protocol Violation
4749 static enum sctp_disposition sctp_sf_violation_ctsn(
4751 const struct sctp_endpoint *ep,
4752 const struct sctp_association *asoc,
4753 const union sctp_subtype type,
4755 struct sctp_cmd_seq *commands)
4757 static const char err_str[] = "The cumulative tsn ack beyond the max tsn currently sent:";
4759 return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str,
4763 /* Handle protocol violation of an invalid chunk bundling. For example,
4764 * when we have an association and we receive bundled INIT-ACK, or
4765 * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle"
4766 * statement from the specs. Additionally, there might be an attacker
4767 * on the path and we may not want to continue this communication.
4769 static enum sctp_disposition sctp_sf_violation_chunk(
4771 const struct sctp_endpoint *ep,
4772 const struct sctp_association *asoc,
4773 const union sctp_subtype type,
4775 struct sctp_cmd_seq *commands)
4777 static const char err_str[] = "The following chunk violates protocol:";
4780 return sctp_sf_violation(net, ep, asoc, type, arg, commands);
4782 return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str,
4785 /***************************************************************************
4786 * These are the state functions for handling primitive (Section 10) events.
4787 ***************************************************************************/
4789 * sctp_sf_do_prm_asoc
4791 * Section: 10.1 ULP-to-SCTP
4794 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
4795 * outbound stream count)
4796 * -> association id [,destination transport addr list] [,outbound stream
4799 * This primitive allows the upper layer to initiate an association to a
4800 * specific peer endpoint.
4802 * The peer endpoint shall be specified by one of the transport addresses
4803 * which defines the endpoint (see Section 1.4). If the local SCTP
4804 * instance has not been initialized, the ASSOCIATE is considered an
4806 * [This is not relevant for the kernel implementation since we do all
4807 * initialization at boot time. It we hadn't initialized we wouldn't
4808 * get anywhere near this code.]
4810 * An association id, which is a local handle to the SCTP association,
4811 * will be returned on successful establishment of the association. If
4812 * SCTP is not able to open an SCTP association with the peer endpoint,
4813 * an error is returned.
4814 * [In the kernel implementation, the struct sctp_association needs to
4815 * be created BEFORE causing this primitive to run.]
4817 * Other association parameters may be returned, including the
4818 * complete destination transport addresses of the peer as well as the
4819 * outbound stream count of the local endpoint. One of the transport
4820 * address from the returned destination addresses will be selected by
4821 * the local endpoint as default primary path for sending SCTP packets
4822 * to this peer. The returned "destination transport addr list" can
4823 * be used by the ULP to change the default primary path or to force
4824 * sending a packet to a specific transport address. [All of this
4825 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
4828 * Mandatory attributes:
4830 * o local SCTP instance name - obtained from the INITIALIZE operation.
4831 * [This is the argument asoc.]
4832 * o destination transport addr - specified as one of the transport
4833 * addresses of the peer endpoint with which the association is to be
4835 * [This is asoc->peer.active_path.]
4836 * o outbound stream count - the number of outbound streams the ULP
4837 * would like to open towards this peer endpoint.
4838 * [BUG: This is not currently implemented.]
4839 * Optional attributes:
4843 * The return value is a disposition.
4845 enum sctp_disposition sctp_sf_do_prm_asoc(struct net *net,
4846 const struct sctp_endpoint *ep,
4847 const struct sctp_association *asoc,
4848 const union sctp_subtype type,
4850 struct sctp_cmd_seq *commands)
4852 struct sctp_association *my_asoc;
4853 struct sctp_chunk *repl;
4855 /* The comment below says that we enter COOKIE-WAIT AFTER
4856 * sending the INIT, but that doesn't actually work in our
4859 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4860 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
4862 /* RFC 2960 5.1 Normal Establishment of an Association
4864 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
4865 * must provide its Verification Tag (Tag_A) in the Initiate
4866 * Tag field. Tag_A SHOULD be a random number in the range of
4867 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
4870 repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0);
4874 /* Choose transport for INIT. */
4875 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
4878 /* Cast away the const modifier, as we want to just
4879 * rerun it through as a sideffect.
4881 my_asoc = (struct sctp_association *)asoc;
4882 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(my_asoc));
4884 /* After sending the INIT, "A" starts the T1-init timer and
4885 * enters the COOKIE-WAIT state.
4887 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4888 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4889 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
4890 return SCTP_DISPOSITION_CONSUME;
4893 return SCTP_DISPOSITION_NOMEM;
4897 * Process the SEND primitive.
4899 * Section: 10.1 ULP-to-SCTP
4902 * Format: SEND(association id, buffer address, byte count [,context]
4903 * [,stream id] [,life time] [,destination transport address]
4904 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
4907 * This is the main method to send user data via SCTP.
4909 * Mandatory attributes:
4911 * o association id - local handle to the SCTP association
4913 * o buffer address - the location where the user message to be
4914 * transmitted is stored;
4916 * o byte count - The size of the user data in number of bytes;
4918 * Optional attributes:
4920 * o context - an optional 32 bit integer that will be carried in the
4921 * sending failure notification to the ULP if the transportation of
4922 * this User Message fails.
4924 * o stream id - to indicate which stream to send the data on. If not
4925 * specified, stream 0 will be used.
4927 * o life time - specifies the life time of the user data. The user data
4928 * will not be sent by SCTP after the life time expires. This
4929 * parameter can be used to avoid efforts to transmit stale
4930 * user messages. SCTP notifies the ULP if the data cannot be
4931 * initiated to transport (i.e. sent to the destination via SCTP's
4932 * send primitive) within the life time variable. However, the
4933 * user data will be transmitted if SCTP has attempted to transmit a
4934 * chunk before the life time expired.
4936 * o destination transport address - specified as one of the destination
4937 * transport addresses of the peer endpoint to which this packet
4938 * should be sent. Whenever possible, SCTP should use this destination
4939 * transport address for sending the packets, instead of the current
4942 * o unorder flag - this flag, if present, indicates that the user
4943 * would like the data delivered in an unordered fashion to the peer
4944 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
4947 * o no-bundle flag - instructs SCTP not to bundle this user data with
4948 * other outbound DATA chunks. SCTP MAY still bundle even when
4949 * this flag is present, when faced with network congestion.
4951 * o payload protocol-id - A 32 bit unsigned integer that is to be
4952 * passed to the peer indicating the type of payload protocol data
4953 * being transmitted. This value is passed as opaque data by SCTP.
4955 * The return value is the disposition.
4957 enum sctp_disposition sctp_sf_do_prm_send(struct net *net,
4958 const struct sctp_endpoint *ep,
4959 const struct sctp_association *asoc,
4960 const union sctp_subtype type,
4962 struct sctp_cmd_seq *commands)
4964 struct sctp_datamsg *msg = arg;
4966 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_MSG, SCTP_DATAMSG(msg));
4967 return SCTP_DISPOSITION_CONSUME;
4971 * Process the SHUTDOWN primitive.
4976 * Format: SHUTDOWN(association id)
4979 * Gracefully closes an association. Any locally queued user data
4980 * will be delivered to the peer. The association will be terminated only
4981 * after the peer acknowledges all the SCTP packets sent. A success code
4982 * will be returned on successful termination of the association. If
4983 * attempting to terminate the association results in a failure, an error
4984 * code shall be returned.
4986 * Mandatory attributes:
4988 * o association id - local handle to the SCTP association
4990 * Optional attributes:
4994 * The return value is the disposition.
4996 enum sctp_disposition sctp_sf_do_9_2_prm_shutdown(
4998 const struct sctp_endpoint *ep,
4999 const struct sctp_association *asoc,
5000 const union sctp_subtype type,
5002 struct sctp_cmd_seq *commands)
5004 enum sctp_disposition disposition;
5006 /* From 9.2 Shutdown of an Association
5007 * Upon receipt of the SHUTDOWN primitive from its upper
5008 * layer, the endpoint enters SHUTDOWN-PENDING state and
5009 * remains there until all outstanding data has been
5010 * acknowledged by its peer. The endpoint accepts no new data
5011 * from its upper layer, but retransmits data to the far end
5012 * if necessary to fill gaps.
5014 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
5015 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
5017 disposition = SCTP_DISPOSITION_CONSUME;
5018 if (sctp_outq_is_empty(&asoc->outqueue)) {
5019 disposition = sctp_sf_do_9_2_start_shutdown(net, ep, asoc, type,
5027 * Process the ABORT primitive.
5032 * Format: Abort(association id [, cause code])
5035 * Ungracefully closes an association. Any locally queued user data
5036 * will be discarded and an ABORT chunk is sent to the peer. A success code
5037 * will be returned on successful abortion of the association. If
5038 * attempting to abort the association results in a failure, an error
5039 * code shall be returned.
5041 * Mandatory attributes:
5043 * o association id - local handle to the SCTP association
5045 * Optional attributes:
5047 * o cause code - reason of the abort to be passed to the peer
5051 * The return value is the disposition.
5053 enum sctp_disposition sctp_sf_do_9_1_prm_abort(
5055 const struct sctp_endpoint *ep,
5056 const struct sctp_association *asoc,
5057 const union sctp_subtype type,
5059 struct sctp_cmd_seq *commands)
5061 /* From 9.1 Abort of an Association
5062 * Upon receipt of the ABORT primitive from its upper
5063 * layer, the endpoint enters CLOSED state and
5064 * discard all outstanding data has been
5065 * acknowledged by its peer. The endpoint accepts no new data
5066 * from its upper layer, but retransmits data to the far end
5067 * if necessary to fill gaps.
5069 struct sctp_chunk *abort = arg;
5072 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
5074 /* Even if we can't send the ABORT due to low memory delete the
5075 * TCB. This is a departure from our typical NOMEM handling.
5078 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5079 SCTP_ERROR(ECONNABORTED));
5080 /* Delete the established association. */
5081 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5082 SCTP_PERR(SCTP_ERROR_USER_ABORT));
5084 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
5085 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
5087 return SCTP_DISPOSITION_ABORT;
5090 /* We tried an illegal operation on an association which is closed. */
5091 enum sctp_disposition sctp_sf_error_closed(struct net *net,
5092 const struct sctp_endpoint *ep,
5093 const struct sctp_association *asoc,
5094 const union sctp_subtype type,
5096 struct sctp_cmd_seq *commands)
5098 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL));
5099 return SCTP_DISPOSITION_CONSUME;
5102 /* We tried an illegal operation on an association which is shutting
5105 enum sctp_disposition sctp_sf_error_shutdown(
5107 const struct sctp_endpoint *ep,
5108 const struct sctp_association *asoc,
5109 const union sctp_subtype type,
5111 struct sctp_cmd_seq *commands)
5113 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR,
5114 SCTP_ERROR(-ESHUTDOWN));
5115 return SCTP_DISPOSITION_CONSUME;
5119 * sctp_cookie_wait_prm_shutdown
5121 * Section: 4 Note: 2
5126 * The RFC does not explicitly address this issue, but is the route through the
5127 * state table when someone issues a shutdown while in COOKIE_WAIT state.
5132 enum sctp_disposition sctp_sf_cookie_wait_prm_shutdown(
5134 const struct sctp_endpoint *ep,
5135 const struct sctp_association *asoc,
5136 const union sctp_subtype type,
5138 struct sctp_cmd_seq *commands)
5140 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5141 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
5143 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
5144 SCTP_STATE(SCTP_STATE_CLOSED));
5146 SCTP_INC_STATS(net, SCTP_MIB_SHUTDOWNS);
5148 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
5150 return SCTP_DISPOSITION_DELETE_TCB;
5154 * sctp_cookie_echoed_prm_shutdown
5156 * Section: 4 Note: 2
5161 * The RFC does not explcitly address this issue, but is the route through the
5162 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
5167 enum sctp_disposition sctp_sf_cookie_echoed_prm_shutdown(
5169 const struct sctp_endpoint *ep,
5170 const struct sctp_association *asoc,
5171 const union sctp_subtype type,
5173 struct sctp_cmd_seq *commands)
5175 /* There is a single T1 timer, so we should be able to use
5176 * common function with the COOKIE-WAIT state.
5178 return sctp_sf_cookie_wait_prm_shutdown(net, ep, asoc, type, arg, commands);
5182 * sctp_sf_cookie_wait_prm_abort
5184 * Section: 4 Note: 2
5189 * The RFC does not explicitly address this issue, but is the route through the
5190 * state table when someone issues an abort while in COOKIE_WAIT state.
5195 enum sctp_disposition sctp_sf_cookie_wait_prm_abort(
5197 const struct sctp_endpoint *ep,
5198 const struct sctp_association *asoc,
5199 const union sctp_subtype type,
5201 struct sctp_cmd_seq *commands)
5203 struct sctp_chunk *abort = arg;
5205 /* Stop T1-init timer */
5206 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5207 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
5210 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
5212 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
5213 SCTP_STATE(SCTP_STATE_CLOSED));
5215 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
5217 /* Even if we can't send the ABORT due to low memory delete the
5218 * TCB. This is a departure from our typical NOMEM handling.
5221 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5222 SCTP_ERROR(ECONNREFUSED));
5223 /* Delete the established association. */
5224 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
5225 SCTP_PERR(SCTP_ERROR_USER_ABORT));
5227 return SCTP_DISPOSITION_ABORT;
5231 * sctp_sf_cookie_echoed_prm_abort
5233 * Section: 4 Note: 3
5238 * The RFC does not explcitly address this issue, but is the route through the
5239 * state table when someone issues an abort while in COOKIE_ECHOED state.
5244 enum sctp_disposition sctp_sf_cookie_echoed_prm_abort(
5246 const struct sctp_endpoint *ep,
5247 const struct sctp_association *asoc,
5248 const union sctp_subtype type,
5250 struct sctp_cmd_seq *commands)
5252 /* There is a single T1 timer, so we should be able to use
5253 * common function with the COOKIE-WAIT state.
5255 return sctp_sf_cookie_wait_prm_abort(net, ep, asoc, type, arg, commands);
5259 * sctp_sf_shutdown_pending_prm_abort
5264 * The RFC does not explicitly address this issue, but is the route through the
5265 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
5270 enum sctp_disposition sctp_sf_shutdown_pending_prm_abort(
5272 const struct sctp_endpoint *ep,
5273 const struct sctp_association *asoc,
5274 const union sctp_subtype type,
5276 struct sctp_cmd_seq *commands)
5278 /* Stop the T5-shutdown guard timer. */
5279 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5280 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
5282 return sctp_sf_do_9_1_prm_abort(net, ep, asoc, type, arg, commands);
5286 * sctp_sf_shutdown_sent_prm_abort
5291 * The RFC does not explicitly address this issue, but is the route through the
5292 * state table when someone issues an abort while in SHUTDOWN-SENT state.
5297 enum sctp_disposition sctp_sf_shutdown_sent_prm_abort(
5299 const struct sctp_endpoint *ep,
5300 const struct sctp_association *asoc,
5301 const union sctp_subtype type,
5303 struct sctp_cmd_seq *commands)
5305 /* Stop the T2-shutdown timer. */
5306 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5307 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
5309 /* Stop the T5-shutdown guard timer. */
5310 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5311 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
5313 return sctp_sf_do_9_1_prm_abort(net, ep, asoc, type, arg, commands);
5317 * sctp_sf_cookie_echoed_prm_abort
5322 * The RFC does not explcitly address this issue, but is the route through the
5323 * state table when someone issues an abort while in COOKIE_ECHOED state.
5328 enum sctp_disposition sctp_sf_shutdown_ack_sent_prm_abort(
5330 const struct sctp_endpoint *ep,
5331 const struct sctp_association *asoc,
5332 const union sctp_subtype type,
5334 struct sctp_cmd_seq *commands)
5336 /* The same T2 timer, so we should be able to use
5337 * common function with the SHUTDOWN-SENT state.
5339 return sctp_sf_shutdown_sent_prm_abort(net, ep, asoc, type, arg, commands);
5343 * Process the REQUESTHEARTBEAT primitive
5346 * J) Request Heartbeat
5348 * Format: REQUESTHEARTBEAT(association id, destination transport address)
5352 * Instructs the local endpoint to perform a HeartBeat on the specified
5353 * destination transport address of the given association. The returned
5354 * result should indicate whether the transmission of the HEARTBEAT
5355 * chunk to the destination address is successful.
5357 * Mandatory attributes:
5359 * o association id - local handle to the SCTP association
5361 * o destination transport address - the transport address of the
5362 * association on which a heartbeat should be issued.
5364 enum sctp_disposition sctp_sf_do_prm_requestheartbeat(
5366 const struct sctp_endpoint *ep,
5367 const struct sctp_association *asoc,
5368 const union sctp_subtype type,
5370 struct sctp_cmd_seq *commands)
5372 if (SCTP_DISPOSITION_NOMEM == sctp_sf_heartbeat(ep, asoc, type,
5373 (struct sctp_transport *)arg, commands))
5374 return SCTP_DISPOSITION_NOMEM;
5377 * RFC 2960 (bis), section 8.3
5379 * D) Request an on-demand HEARTBEAT on a specific destination
5380 * transport address of a given association.
5382 * The endpoint should increment the respective error counter of
5383 * the destination transport address each time a HEARTBEAT is sent
5384 * to that address and not acknowledged within one RTO.
5387 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_HB_SENT,
5388 SCTP_TRANSPORT(arg));
5389 return SCTP_DISPOSITION_CONSUME;
5393 * ADDIP Section 4.1 ASCONF Chunk Procedures
5394 * When an endpoint has an ASCONF signaled change to be sent to the
5395 * remote endpoint it should do A1 to A9
5397 enum sctp_disposition sctp_sf_do_prm_asconf(struct net *net,
5398 const struct sctp_endpoint *ep,
5399 const struct sctp_association *asoc,
5400 const union sctp_subtype type,
5402 struct sctp_cmd_seq *commands)
5404 struct sctp_chunk *chunk = arg;
5406 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
5407 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
5408 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
5409 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
5410 return SCTP_DISPOSITION_CONSUME;
5413 /* RE-CONFIG Section 5.1 RECONF Chunk Procedures */
5414 enum sctp_disposition sctp_sf_do_prm_reconf(struct net *net,
5415 const struct sctp_endpoint *ep,
5416 const struct sctp_association *asoc,
5417 const union sctp_subtype type,
5419 struct sctp_cmd_seq *commands)
5421 struct sctp_chunk *chunk = arg;
5423 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
5424 return SCTP_DISPOSITION_CONSUME;
5428 * Ignore the primitive event
5430 * The return value is the disposition of the primitive.
5432 enum sctp_disposition sctp_sf_ignore_primitive(
5434 const struct sctp_endpoint *ep,
5435 const struct sctp_association *asoc,
5436 const union sctp_subtype type,
5438 struct sctp_cmd_seq *commands)
5440 pr_debug("%s: primitive type:%d is ignored\n", __func__,
5443 return SCTP_DISPOSITION_DISCARD;
5446 /***************************************************************************
5447 * These are the state functions for the OTHER events.
5448 ***************************************************************************/
5451 * When the SCTP stack has no more user data to send or retransmit, this
5452 * notification is given to the user. Also, at the time when a user app
5453 * subscribes to this event, if there is no data to be sent or
5454 * retransmit, the stack will immediately send up this notification.
5456 enum sctp_disposition sctp_sf_do_no_pending_tsn(
5458 const struct sctp_endpoint *ep,
5459 const struct sctp_association *asoc,
5460 const union sctp_subtype type,
5462 struct sctp_cmd_seq *commands)
5464 struct sctp_ulpevent *event;
5466 event = sctp_ulpevent_make_sender_dry_event(asoc, GFP_ATOMIC);
5468 return SCTP_DISPOSITION_NOMEM;
5470 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(event));
5472 return SCTP_DISPOSITION_CONSUME;
5476 * Start the shutdown negotiation.
5479 * Once all its outstanding data has been acknowledged, the endpoint
5480 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
5481 * TSN Ack field the last sequential TSN it has received from the peer.
5482 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
5483 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
5484 * with the updated last sequential TSN received from its peer.
5486 * The return value is the disposition.
5488 enum sctp_disposition sctp_sf_do_9_2_start_shutdown(
5490 const struct sctp_endpoint *ep,
5491 const struct sctp_association *asoc,
5492 const union sctp_subtype type,
5494 struct sctp_cmd_seq *commands)
5496 struct sctp_chunk *reply;
5498 /* Once all its outstanding data has been acknowledged, the
5499 * endpoint shall send a SHUTDOWN chunk to its peer including
5500 * in the Cumulative TSN Ack field the last sequential TSN it
5501 * has received from the peer.
5503 reply = sctp_make_shutdown(asoc, arg);
5507 /* Set the transport for the SHUTDOWN chunk and the timeout for the
5508 * T2-shutdown timer.
5510 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
5512 /* It shall then start the T2-shutdown timer */
5513 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
5514 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
5516 /* RFC 4960 Section 9.2
5517 * The sender of the SHUTDOWN MAY also start an overall guard timer
5518 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5520 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
5521 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
5523 if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE])
5524 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5525 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
5527 /* and enter the SHUTDOWN-SENT state. */
5528 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
5529 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT));
5531 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5533 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5536 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
5538 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
5540 return SCTP_DISPOSITION_CONSUME;
5543 return SCTP_DISPOSITION_NOMEM;
5547 * Generate a SHUTDOWN ACK now that everything is SACK'd.
5551 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5552 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
5553 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
5554 * endpoint must re-send the SHUTDOWN ACK.
5556 * The return value is the disposition.
5558 enum sctp_disposition sctp_sf_do_9_2_shutdown_ack(
5560 const struct sctp_endpoint *ep,
5561 const struct sctp_association *asoc,
5562 const union sctp_subtype type,
5564 struct sctp_cmd_seq *commands)
5566 struct sctp_chunk *chunk = arg;
5567 struct sctp_chunk *reply;
5569 /* There are 2 ways of getting here:
5570 * 1) called in response to a SHUTDOWN chunk
5571 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
5573 * For the case (2), the arg parameter is set to NULL. We need
5574 * to check that we have a chunk before accessing it's fields.
5577 if (!sctp_vtag_verify(chunk, asoc))
5578 return sctp_sf_pdiscard(net, ep, asoc, type, arg,
5581 /* Make sure that the SHUTDOWN chunk has a valid length. */
5582 if (!sctp_chunk_length_valid(
5583 chunk, sizeof(struct sctp_shutdown_chunk)))
5584 return sctp_sf_violation_chunklen(net, ep, asoc, type,
5588 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5589 * shall send a SHUTDOWN ACK ...
5591 reply = sctp_make_shutdown_ack(asoc, chunk);
5595 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
5596 * the T2-shutdown timer.
5598 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
5600 /* and start/restart a T2-shutdown timer of its own, */
5601 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
5602 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
5604 if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE])
5605 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5606 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
5608 /* Enter the SHUTDOWN-ACK-SENT state. */
5609 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
5610 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT));
5612 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5614 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5617 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
5619 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
5621 return SCTP_DISPOSITION_CONSUME;
5624 return SCTP_DISPOSITION_NOMEM;
5628 * Ignore the event defined as other
5630 * The return value is the disposition of the event.
5632 enum sctp_disposition sctp_sf_ignore_other(struct net *net,
5633 const struct sctp_endpoint *ep,
5634 const struct sctp_association *asoc,
5635 const union sctp_subtype type,
5637 struct sctp_cmd_seq *commands)
5639 pr_debug("%s: the event other type:%d is ignored\n",
5640 __func__, type.other);
5642 return SCTP_DISPOSITION_DISCARD;
5645 /************************************************************
5646 * These are the state functions for handling timeout events.
5647 ************************************************************/
5652 * Section: 6.3.3 Handle T3-rtx Expiration
5654 * Whenever the retransmission timer T3-rtx expires for a destination
5655 * address, do the following:
5658 * The return value is the disposition of the chunk.
5660 enum sctp_disposition sctp_sf_do_6_3_3_rtx(struct net *net,
5661 const struct sctp_endpoint *ep,
5662 const struct sctp_association *asoc,
5663 const union sctp_subtype type,
5665 struct sctp_cmd_seq *commands)
5667 struct sctp_transport *transport = arg;
5669 SCTP_INC_STATS(net, SCTP_MIB_T3_RTX_EXPIREDS);
5671 if (asoc->overall_error_count >= asoc->max_retrans) {
5672 if (asoc->peer.zero_window_announced &&
5673 asoc->state == SCTP_STATE_SHUTDOWN_PENDING) {
5675 * We are here likely because the receiver had its rwnd
5676 * closed for a while and we have not been able to
5677 * transmit the locally queued data within the maximum
5678 * retransmission attempts limit. Start the T5
5679 * shutdown guard timer to give the receiver one last
5680 * chance and some additional time to recover before
5683 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START_ONCE,
5684 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
5686 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5687 SCTP_ERROR(ETIMEDOUT));
5688 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5689 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5690 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5691 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
5692 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
5693 return SCTP_DISPOSITION_DELETE_TCB;
5697 /* E1) For the destination address for which the timer
5698 * expires, adjust its ssthresh with rules defined in Section
5699 * 7.2.3 and set the cwnd <- MTU.
5702 /* E2) For the destination address for which the timer
5703 * expires, set RTO <- RTO * 2 ("back off the timer"). The
5704 * maximum value discussed in rule C7 above (RTO.max) may be
5705 * used to provide an upper bound to this doubling operation.
5708 /* E3) Determine how many of the earliest (i.e., lowest TSN)
5709 * outstanding DATA chunks for the address for which the
5710 * T3-rtx has expired will fit into a single packet, subject
5711 * to the MTU constraint for the path corresponding to the
5712 * destination transport address to which the retransmission
5713 * is being sent (this may be different from the address for
5714 * which the timer expires [see Section 6.4]). Call this
5715 * value K. Bundle and retransmit those K DATA chunks in a
5716 * single packet to the destination endpoint.
5718 * Note: Any DATA chunks that were sent to the address for
5719 * which the T3-rtx timer expired but did not fit in one MTU
5720 * (rule E3 above), should be marked for retransmission and
5721 * sent as soon as cwnd allows (normally when a SACK arrives).
5724 /* Do some failure management (Section 8.2). */
5725 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
5727 /* NB: Rules E4 and F1 are implicit in R1. */
5728 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport));
5730 return SCTP_DISPOSITION_CONSUME;
5734 * Generate delayed SACK on timeout
5736 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
5738 * The guidelines on delayed acknowledgement algorithm specified in
5739 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
5740 * acknowledgement SHOULD be generated for at least every second packet
5741 * (not every second DATA chunk) received, and SHOULD be generated
5742 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
5743 * some situations it may be beneficial for an SCTP transmitter to be
5744 * more conservative than the algorithms detailed in this document
5745 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
5746 * the following algorithms allow.
5748 enum sctp_disposition sctp_sf_do_6_2_sack(struct net *net,
5749 const struct sctp_endpoint *ep,
5750 const struct sctp_association *asoc,
5751 const union sctp_subtype type,
5753 struct sctp_cmd_seq *commands)
5755 SCTP_INC_STATS(net, SCTP_MIB_DELAY_SACK_EXPIREDS);
5756 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
5757 return SCTP_DISPOSITION_CONSUME;
5761 * sctp_sf_t1_init_timer_expire
5763 * Section: 4 Note: 2
5768 * RFC 2960 Section 4 Notes
5769 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
5770 * and re-start the T1-init timer without changing state. This MUST
5771 * be repeated up to 'Max.Init.Retransmits' times. After that, the
5772 * endpoint MUST abort the initialization process and report the
5773 * error to SCTP user.
5779 enum sctp_disposition sctp_sf_t1_init_timer_expire(
5781 const struct sctp_endpoint *ep,
5782 const struct sctp_association *asoc,
5783 const union sctp_subtype type,
5785 struct sctp_cmd_seq *commands)
5787 int attempts = asoc->init_err_counter + 1;
5788 struct sctp_chunk *repl = NULL;
5789 struct sctp_bind_addr *bp;
5791 pr_debug("%s: timer T1 expired (INIT)\n", __func__);
5793 SCTP_INC_STATS(net, SCTP_MIB_T1_INIT_EXPIREDS);
5795 if (attempts <= asoc->max_init_attempts) {
5796 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
5797 repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0);
5799 return SCTP_DISPOSITION_NOMEM;
5801 /* Choose transport for INIT. */
5802 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
5805 /* Issue a sideeffect to do the needed accounting. */
5806 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART,
5807 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
5809 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
5811 pr_debug("%s: giving up on INIT, attempts:%d "
5812 "max_init_attempts:%d\n", __func__, attempts,
5813 asoc->max_init_attempts);
5815 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5816 SCTP_ERROR(ETIMEDOUT));
5817 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
5818 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5819 return SCTP_DISPOSITION_DELETE_TCB;
5822 return SCTP_DISPOSITION_CONSUME;
5826 * sctp_sf_t1_cookie_timer_expire
5828 * Section: 4 Note: 2
5833 * RFC 2960 Section 4 Notes
5834 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
5835 * COOKIE ECHO and re-start the T1-cookie timer without changing
5836 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
5837 * After that, the endpoint MUST abort the initialization process and
5838 * report the error to SCTP user.
5844 enum sctp_disposition sctp_sf_t1_cookie_timer_expire(
5846 const struct sctp_endpoint *ep,
5847 const struct sctp_association *asoc,
5848 const union sctp_subtype type,
5850 struct sctp_cmd_seq *commands)
5852 int attempts = asoc->init_err_counter + 1;
5853 struct sctp_chunk *repl = NULL;
5855 pr_debug("%s: timer T1 expired (COOKIE-ECHO)\n", __func__);
5857 SCTP_INC_STATS(net, SCTP_MIB_T1_COOKIE_EXPIREDS);
5859 if (attempts <= asoc->max_init_attempts) {
5860 repl = sctp_make_cookie_echo(asoc, NULL);
5862 return SCTP_DISPOSITION_NOMEM;
5864 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
5866 /* Issue a sideeffect to do the needed accounting. */
5867 sctp_add_cmd_sf(commands, SCTP_CMD_COOKIEECHO_RESTART,
5868 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
5870 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
5872 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5873 SCTP_ERROR(ETIMEDOUT));
5874 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
5875 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5876 return SCTP_DISPOSITION_DELETE_TCB;
5879 return SCTP_DISPOSITION_CONSUME;
5882 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
5883 * with the updated last sequential TSN received from its peer.
5885 * An endpoint should limit the number of retransmissions of the
5886 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
5887 * If this threshold is exceeded the endpoint should destroy the TCB and
5888 * MUST report the peer endpoint unreachable to the upper layer (and
5889 * thus the association enters the CLOSED state). The reception of any
5890 * packet from its peer (i.e. as the peer sends all of its queued DATA
5891 * chunks) should clear the endpoint's retransmission count and restart
5892 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
5893 * all of its queued DATA chunks that have not yet been sent.
5895 enum sctp_disposition sctp_sf_t2_timer_expire(
5897 const struct sctp_endpoint *ep,
5898 const struct sctp_association *asoc,
5899 const union sctp_subtype type,
5901 struct sctp_cmd_seq *commands)
5903 struct sctp_chunk *reply = NULL;
5905 pr_debug("%s: timer T2 expired\n", __func__);
5907 SCTP_INC_STATS(net, SCTP_MIB_T2_SHUTDOWN_EXPIREDS);
5909 ((struct sctp_association *)asoc)->shutdown_retries++;
5911 if (asoc->overall_error_count >= asoc->max_retrans) {
5912 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5913 SCTP_ERROR(ETIMEDOUT));
5914 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5915 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5916 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5917 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
5918 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
5919 return SCTP_DISPOSITION_DELETE_TCB;
5922 switch (asoc->state) {
5923 case SCTP_STATE_SHUTDOWN_SENT:
5924 reply = sctp_make_shutdown(asoc, NULL);
5927 case SCTP_STATE_SHUTDOWN_ACK_SENT:
5928 reply = sctp_make_shutdown_ack(asoc, NULL);
5939 /* Do some failure management (Section 8.2).
5940 * If we remove the transport an SHUTDOWN was last sent to, don't
5941 * do failure management.
5943 if (asoc->shutdown_last_sent_to)
5944 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
5945 SCTP_TRANSPORT(asoc->shutdown_last_sent_to));
5947 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
5948 * the T2-shutdown timer.
5950 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
5952 /* Restart the T2-shutdown timer. */
5953 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
5954 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
5955 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
5956 return SCTP_DISPOSITION_CONSUME;
5959 return SCTP_DISPOSITION_NOMEM;
5963 * ADDIP Section 4.1 ASCONF CHunk Procedures
5964 * If the T4 RTO timer expires the endpoint should do B1 to B5
5966 enum sctp_disposition sctp_sf_t4_timer_expire(
5968 const struct sctp_endpoint *ep,
5969 const struct sctp_association *asoc,
5970 const union sctp_subtype type,
5972 struct sctp_cmd_seq *commands)
5974 struct sctp_chunk *chunk = asoc->addip_last_asconf;
5975 struct sctp_transport *transport = chunk->transport;
5977 SCTP_INC_STATS(net, SCTP_MIB_T4_RTO_EXPIREDS);
5979 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
5980 * detection on the appropriate destination address as defined in
5981 * RFC2960 [5] section 8.1 and 8.2.
5984 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
5985 SCTP_TRANSPORT(transport));
5987 /* Reconfig T4 timer and transport. */
5988 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
5990 /* ADDIP 4.1 B2) Increment the association error counters and perform
5991 * endpoint failure detection on the association as defined in
5992 * RFC2960 [5] section 8.1 and 8.2.
5993 * association error counter is incremented in SCTP_CMD_STRIKE.
5995 if (asoc->overall_error_count >= asoc->max_retrans) {
5996 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5997 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
5998 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5999 SCTP_ERROR(ETIMEDOUT));
6000 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
6001 SCTP_PERR(SCTP_ERROR_NO_ERROR));
6002 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
6003 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
6004 return SCTP_DISPOSITION_ABORT;
6007 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
6008 * the ASCONF chunk was sent by doubling the RTO timer value.
6009 * This is done in SCTP_CMD_STRIKE.
6012 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
6013 * choose an alternate destination address (please refer to RFC2960
6014 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
6015 * chunk, it MUST be the same (including its serial number) as the last
6018 sctp_chunk_hold(asoc->addip_last_asconf);
6019 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
6020 SCTP_CHUNK(asoc->addip_last_asconf));
6022 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
6023 * destination is selected, then the RTO used will be that of the new
6024 * destination address.
6026 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
6027 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
6029 return SCTP_DISPOSITION_CONSUME;
6032 /* sctpimpguide-05 Section 2.12.2
6033 * The sender of the SHUTDOWN MAY also start an overall guard timer
6034 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
6035 * At the expiration of this timer the sender SHOULD abort the association
6036 * by sending an ABORT chunk.
6038 enum sctp_disposition sctp_sf_t5_timer_expire(
6040 const struct sctp_endpoint *ep,
6041 const struct sctp_association *asoc,
6042 const union sctp_subtype type,
6044 struct sctp_cmd_seq *commands)
6046 struct sctp_chunk *reply = NULL;
6048 pr_debug("%s: timer T5 expired\n", __func__);
6050 SCTP_INC_STATS(net, SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS);
6052 reply = sctp_make_abort(asoc, NULL, 0);
6056 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
6057 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
6058 SCTP_ERROR(ETIMEDOUT));
6059 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
6060 SCTP_PERR(SCTP_ERROR_NO_ERROR));
6062 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
6063 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
6065 return SCTP_DISPOSITION_DELETE_TCB;
6067 return SCTP_DISPOSITION_NOMEM;
6070 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
6071 * the association is automatically closed by starting the shutdown process.
6072 * The work that needs to be done is same as when SHUTDOWN is initiated by
6073 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
6075 enum sctp_disposition sctp_sf_autoclose_timer_expire(
6077 const struct sctp_endpoint *ep,
6078 const struct sctp_association *asoc,
6079 const union sctp_subtype type,
6081 struct sctp_cmd_seq *commands)
6083 enum sctp_disposition disposition;
6085 SCTP_INC_STATS(net, SCTP_MIB_AUTOCLOSE_EXPIREDS);
6087 /* From 9.2 Shutdown of an Association
6088 * Upon receipt of the SHUTDOWN primitive from its upper
6089 * layer, the endpoint enters SHUTDOWN-PENDING state and
6090 * remains there until all outstanding data has been
6091 * acknowledged by its peer. The endpoint accepts no new data
6092 * from its upper layer, but retransmits data to the far end
6093 * if necessary to fill gaps.
6095 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
6096 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
6098 disposition = SCTP_DISPOSITION_CONSUME;
6099 if (sctp_outq_is_empty(&asoc->outqueue)) {
6100 disposition = sctp_sf_do_9_2_start_shutdown(net, ep, asoc, type,
6107 /*****************************************************************************
6108 * These are sa state functions which could apply to all types of events.
6109 ****************************************************************************/
6112 * This table entry is not implemented.
6115 * (endpoint, asoc, chunk)
6117 * The return value is the disposition of the chunk.
6119 enum sctp_disposition sctp_sf_not_impl(struct net *net,
6120 const struct sctp_endpoint *ep,
6121 const struct sctp_association *asoc,
6122 const union sctp_subtype type,
6123 void *arg, struct sctp_cmd_seq *commands)
6125 return SCTP_DISPOSITION_NOT_IMPL;
6129 * This table entry represents a bug.
6132 * (endpoint, asoc, chunk)
6134 * The return value is the disposition of the chunk.
6136 enum sctp_disposition sctp_sf_bug(struct net *net,
6137 const struct sctp_endpoint *ep,
6138 const struct sctp_association *asoc,
6139 const union sctp_subtype type,
6140 void *arg, struct sctp_cmd_seq *commands)
6142 return SCTP_DISPOSITION_BUG;
6146 * This table entry represents the firing of a timer in the wrong state.
6147 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
6148 * when the association is in the wrong state. This event should
6149 * be ignored, so as to prevent any rearming of the timer.
6152 * (endpoint, asoc, chunk)
6154 * The return value is the disposition of the chunk.
6156 enum sctp_disposition sctp_sf_timer_ignore(struct net *net,
6157 const struct sctp_endpoint *ep,
6158 const struct sctp_association *asoc,
6159 const union sctp_subtype type,
6161 struct sctp_cmd_seq *commands)
6163 pr_debug("%s: timer %d ignored\n", __func__, type.chunk);
6165 return SCTP_DISPOSITION_CONSUME;
6168 /********************************************************************
6169 * 2nd Level Abstractions
6170 ********************************************************************/
6172 /* Pull the SACK chunk based on the SACK header. */
6173 static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk)
6175 struct sctp_sackhdr *sack;
6180 /* Protect ourselves from reading too far into
6181 * the skb from a bogus sender.
6183 sack = (struct sctp_sackhdr *) chunk->skb->data;
6185 num_blocks = ntohs(sack->num_gap_ack_blocks);
6186 num_dup_tsns = ntohs(sack->num_dup_tsns);
6187 len = sizeof(struct sctp_sackhdr);
6188 len += (num_blocks + num_dup_tsns) * sizeof(__u32);
6189 if (len > chunk->skb->len)
6192 skb_pull(chunk->skb, len);
6197 /* Create an ABORT packet to be sent as a response, with the specified
6200 static struct sctp_packet *sctp_abort_pkt_new(
6202 const struct sctp_endpoint *ep,
6203 const struct sctp_association *asoc,
6204 struct sctp_chunk *chunk,
6205 const void *payload, size_t paylen)
6207 struct sctp_packet *packet;
6208 struct sctp_chunk *abort;
6210 packet = sctp_ootb_pkt_new(net, asoc, chunk);
6214 * The T bit will be set if the asoc is NULL.
6216 abort = sctp_make_abort(asoc, chunk, paylen);
6218 sctp_ootb_pkt_free(packet);
6222 /* Reflect vtag if T-Bit is set */
6223 if (sctp_test_T_bit(abort))
6224 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
6226 /* Add specified error causes, i.e., payload, to the
6229 sctp_addto_chunk(abort, paylen, payload);
6231 /* Set the skb to the belonging sock for accounting. */
6232 abort->skb->sk = ep->base.sk;
6234 sctp_packet_append_chunk(packet, abort);
6241 /* Allocate a packet for responding in the OOTB conditions. */
6242 static struct sctp_packet *sctp_ootb_pkt_new(
6244 const struct sctp_association *asoc,
6245 const struct sctp_chunk *chunk)
6247 struct sctp_transport *transport;
6248 struct sctp_packet *packet;
6252 /* Get the source and destination port from the inbound packet. */
6253 sport = ntohs(chunk->sctp_hdr->dest);
6254 dport = ntohs(chunk->sctp_hdr->source);
6256 /* The V-tag is going to be the same as the inbound packet if no
6257 * association exists, otherwise, use the peer's vtag.
6260 /* Special case the INIT-ACK as there is no peer's vtag
6263 switch (chunk->chunk_hdr->type) {
6264 case SCTP_CID_INIT_ACK:
6266 struct sctp_initack_chunk *initack;
6268 initack = (struct sctp_initack_chunk *)chunk->chunk_hdr;
6269 vtag = ntohl(initack->init_hdr.init_tag);
6273 vtag = asoc->peer.i.init_tag;
6277 /* Special case the INIT and stale COOKIE_ECHO as there is no
6280 switch (chunk->chunk_hdr->type) {
6283 struct sctp_init_chunk *init;
6285 init = (struct sctp_init_chunk *)chunk->chunk_hdr;
6286 vtag = ntohl(init->init_hdr.init_tag);
6290 vtag = ntohl(chunk->sctp_hdr->vtag);
6295 /* Make a transport for the bucket, Eliza... */
6296 transport = sctp_transport_new(net, sctp_source(chunk), GFP_ATOMIC);
6300 /* Cache a route for the transport with the chunk's destination as
6301 * the source address.
6303 sctp_transport_route(transport, (union sctp_addr *)&chunk->dest,
6304 sctp_sk(net->sctp.ctl_sock));
6306 packet = &transport->packet;
6307 sctp_packet_init(packet, transport, sport, dport);
6308 sctp_packet_config(packet, vtag, 0);
6316 /* Free the packet allocated earlier for responding in the OOTB condition. */
6317 void sctp_ootb_pkt_free(struct sctp_packet *packet)
6319 sctp_transport_free(packet->transport);
6322 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
6323 static void sctp_send_stale_cookie_err(struct net *net,
6324 const struct sctp_endpoint *ep,
6325 const struct sctp_association *asoc,
6326 const struct sctp_chunk *chunk,
6327 struct sctp_cmd_seq *commands,
6328 struct sctp_chunk *err_chunk)
6330 struct sctp_packet *packet;
6333 packet = sctp_ootb_pkt_new(net, asoc, chunk);
6335 struct sctp_signed_cookie *cookie;
6337 /* Override the OOTB vtag from the cookie. */
6338 cookie = chunk->subh.cookie_hdr;
6339 packet->vtag = cookie->c.peer_vtag;
6341 /* Set the skb to the belonging sock for accounting. */
6342 err_chunk->skb->sk = ep->base.sk;
6343 sctp_packet_append_chunk(packet, err_chunk);
6344 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
6345 SCTP_PACKET(packet));
6346 SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
6348 sctp_chunk_free (err_chunk);
6353 /* Process a data chunk */
6354 static int sctp_eat_data(const struct sctp_association *asoc,
6355 struct sctp_chunk *chunk,
6356 struct sctp_cmd_seq *commands)
6358 struct sctp_tsnmap *map = (struct sctp_tsnmap *)&asoc->peer.tsn_map;
6359 struct sock *sk = asoc->base.sk;
6360 struct net *net = sock_net(sk);
6361 struct sctp_datahdr *data_hdr;
6362 struct sctp_chunk *err;
6363 enum sctp_verb deliver;
6368 data_hdr = (struct sctp_datahdr *)chunk->skb->data;
6369 chunk->subh.data_hdr = data_hdr;
6370 skb_pull(chunk->skb, sctp_datahdr_len(&asoc->stream));
6372 tsn = ntohl(data_hdr->tsn);
6373 pr_debug("%s: TSN 0x%x\n", __func__, tsn);
6375 /* ASSERT: Now skb->data is really the user data. */
6377 /* Process ECN based congestion.
6379 * Since the chunk structure is reused for all chunks within
6380 * a packet, we use ecn_ce_done to track if we've already
6381 * done CE processing for this packet.
6383 * We need to do ECN processing even if we plan to discard the
6387 if (asoc->peer.ecn_capable && !chunk->ecn_ce_done) {
6388 struct sctp_af *af = SCTP_INPUT_CB(chunk->skb)->af;
6389 chunk->ecn_ce_done = 1;
6391 if (af->is_ce(sctp_gso_headskb(chunk->skb))) {
6392 /* Do real work as sideffect. */
6393 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
6398 tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
6400 /* The TSN is too high--silently discard the chunk and
6401 * count on it getting retransmitted later.
6404 chunk->asoc->stats.outofseqtsns++;
6405 return SCTP_IERROR_HIGH_TSN;
6406 } else if (tmp > 0) {
6407 /* This is a duplicate. Record it. */
6408 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
6409 return SCTP_IERROR_DUP_TSN;
6412 /* This is a new TSN. */
6414 /* Discard if there is no room in the receive window.
6415 * Actually, allow a little bit of overflow (up to a MTU).
6417 datalen = ntohs(chunk->chunk_hdr->length);
6418 datalen -= sctp_datachk_len(&asoc->stream);
6420 deliver = SCTP_CMD_CHUNK_ULP;
6422 /* Think about partial delivery. */
6423 if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) {
6425 /* Even if we don't accept this chunk there is
6428 sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL());
6431 /* Spill over rwnd a little bit. Note: While allowed, this spill over
6432 * seems a bit troublesome in that frag_point varies based on
6433 * PMTU. In cases, such as loopback, this might be a rather
6436 if ((!chunk->data_accepted) && (!asoc->rwnd || asoc->rwnd_over ||
6437 (datalen > asoc->rwnd + asoc->frag_point))) {
6439 /* If this is the next TSN, consider reneging to make
6440 * room. Note: Playing nice with a confused sender. A
6441 * malicious sender can still eat up all our buffer
6442 * space and in the future we may want to detect and
6443 * do more drastic reneging.
6445 if (sctp_tsnmap_has_gap(map) &&
6446 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
6447 pr_debug("%s: reneging for tsn:%u\n", __func__, tsn);
6448 deliver = SCTP_CMD_RENEGE;
6450 pr_debug("%s: discard tsn:%u len:%zu, rwnd:%d\n",
6451 __func__, tsn, datalen, asoc->rwnd);
6453 return SCTP_IERROR_IGNORE_TSN;
6458 * Also try to renege to limit our memory usage in the event that
6459 * we are under memory pressure
6460 * If we can't renege, don't worry about it, the sk_rmem_schedule
6461 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
6462 * memory usage too much
6464 if (*sk->sk_prot_creator->memory_pressure) {
6465 if (sctp_tsnmap_has_gap(map) &&
6466 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
6467 pr_debug("%s: under pressure, reneging for tsn:%u\n",
6469 deliver = SCTP_CMD_RENEGE;
6474 * Section 3.3.10.9 No User Data (9)
6478 * No User Data: This error cause is returned to the originator of a
6479 * DATA chunk if a received DATA chunk has no user data.
6481 if (unlikely(0 == datalen)) {
6482 err = sctp_make_abort_no_data(asoc, chunk, tsn);
6484 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
6487 /* We are going to ABORT, so we might as well stop
6488 * processing the rest of the chunks in the packet.
6490 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
6491 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
6492 SCTP_ERROR(ECONNABORTED));
6493 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
6494 SCTP_PERR(SCTP_ERROR_NO_DATA));
6495 SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
6496 SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
6497 return SCTP_IERROR_NO_DATA;
6500 chunk->data_accepted = 1;
6502 /* Note: Some chunks may get overcounted (if we drop) or overcounted
6503 * if we renege and the chunk arrives again.
6505 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) {
6506 SCTP_INC_STATS(net, SCTP_MIB_INUNORDERCHUNKS);
6508 chunk->asoc->stats.iuodchunks++;
6510 SCTP_INC_STATS(net, SCTP_MIB_INORDERCHUNKS);
6512 chunk->asoc->stats.iodchunks++;
6515 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
6517 * If an endpoint receive a DATA chunk with an invalid stream
6518 * identifier, it shall acknowledge the reception of the DATA chunk
6519 * following the normal procedure, immediately send an ERROR chunk
6520 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
6521 * and discard the DATA chunk.
6523 if (ntohs(data_hdr->stream) >= asoc->stream.incnt) {
6524 /* Mark tsn as received even though we drop it */
6525 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
6527 err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
6529 sizeof(data_hdr->stream),
6532 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
6534 return SCTP_IERROR_BAD_STREAM;
6537 /* Check to see if the SSN is possible for this TSN.
6538 * The biggest gap we can record is 4K wide. Since SSNs wrap
6539 * at an unsigned short, there is no way that an SSN can
6540 * wrap and for a valid TSN. We can simply check if the current
6541 * SSN is smaller then the next expected one. If it is, it wrapped
6544 if (!asoc->stream.si->validate_data(chunk))
6545 return SCTP_IERROR_PROTO_VIOLATION;
6547 /* Send the data up to the user. Note: Schedule the
6548 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
6549 * chunk needs the updated rwnd.
6551 sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk));
6553 return SCTP_IERROR_NO_ERROR;