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 static struct sctp_packet
*sctp_abort_pkt_new(
64 const struct sctp_endpoint
*ep
,
65 const struct sctp_association
*asoc
,
66 struct sctp_chunk
*chunk
,
67 const void *payload
, size_t paylen
);
68 static int sctp_eat_data(const struct sctp_association
*asoc
,
69 struct sctp_chunk
*chunk
,
70 struct sctp_cmd_seq
*commands
);
71 static struct sctp_packet
*sctp_ootb_pkt_new(
73 const struct sctp_association
*asoc
,
74 const struct sctp_chunk
*chunk
);
75 static void sctp_send_stale_cookie_err(struct net
*net
,
76 const struct sctp_endpoint
*ep
,
77 const struct sctp_association
*asoc
,
78 const struct sctp_chunk
*chunk
,
79 struct sctp_cmd_seq
*commands
,
80 struct sctp_chunk
*err_chunk
);
81 static enum sctp_disposition
sctp_sf_do_5_2_6_stale(
83 const struct sctp_endpoint
*ep
,
84 const struct sctp_association
*asoc
,
85 const union sctp_subtype type
,
87 struct sctp_cmd_seq
*commands
);
88 static enum sctp_disposition
sctp_sf_shut_8_4_5(
90 const struct sctp_endpoint
*ep
,
91 const struct sctp_association
*asoc
,
92 const union sctp_subtype type
,
94 struct sctp_cmd_seq
*commands
);
95 static enum sctp_disposition
sctp_sf_tabort_8_4_8(
97 const struct sctp_endpoint
*ep
,
98 const struct sctp_association
*asoc
,
99 const union sctp_subtype type
,
101 struct sctp_cmd_seq
*commands
);
102 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
);
104 static enum sctp_disposition
sctp_stop_t1_and_abort(
106 struct sctp_cmd_seq
*commands
,
107 __be16 error
, int sk_err
,
108 const struct sctp_association
*asoc
,
109 struct sctp_transport
*transport
);
111 static enum sctp_disposition
sctp_sf_abort_violation(
113 const struct sctp_endpoint
*ep
,
114 const struct sctp_association
*asoc
,
116 struct sctp_cmd_seq
*commands
,
118 const size_t paylen
);
120 static enum sctp_disposition
sctp_sf_violation_chunklen(
122 const struct sctp_endpoint
*ep
,
123 const struct sctp_association
*asoc
,
124 const union sctp_subtype type
,
126 struct sctp_cmd_seq
*commands
);
128 static enum sctp_disposition
sctp_sf_violation_paramlen(
130 const struct sctp_endpoint
*ep
,
131 const struct sctp_association
*asoc
,
132 const union sctp_subtype type
,
133 void *arg
, void *ext
,
134 struct sctp_cmd_seq
*commands
);
136 static enum sctp_disposition
sctp_sf_violation_ctsn(
138 const struct sctp_endpoint
*ep
,
139 const struct sctp_association
*asoc
,
140 const union sctp_subtype type
,
142 struct sctp_cmd_seq
*commands
);
144 static enum sctp_disposition
sctp_sf_violation_chunk(
146 const struct sctp_endpoint
*ep
,
147 const struct sctp_association
*asoc
,
148 const union sctp_subtype type
,
150 struct sctp_cmd_seq
*commands
);
152 static enum sctp_ierror
sctp_sf_authenticate(
153 const struct sctp_association
*asoc
,
154 struct sctp_chunk
*chunk
);
156 static enum sctp_disposition
__sctp_sf_do_9_1_abort(
158 const struct sctp_endpoint
*ep
,
159 const struct sctp_association
*asoc
,
160 const union sctp_subtype type
,
162 struct sctp_cmd_seq
*commands
);
164 /* Small helper function that checks if the chunk length
165 * is of the appropriate length. The 'required_length' argument
166 * is set to be the size of a specific chunk we are testing.
167 * Return Values: true = Valid length
168 * false = Invalid length
171 static inline bool sctp_chunk_length_valid(struct sctp_chunk
*chunk
,
172 __u16 required_length
)
174 __u16 chunk_length
= ntohs(chunk
->chunk_hdr
->length
);
176 /* Previously already marked? */
177 if (unlikely(chunk
->pdiscard
))
179 if (unlikely(chunk_length
< required_length
))
185 /**********************************************************
186 * These are the state functions for handling chunk events.
187 **********************************************************/
190 * Process the final SHUTDOWN COMPLETE.
192 * Section: 4 (C) (diagram), 9.2
193 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
194 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
195 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
196 * should stop the T2-shutdown timer and remove all knowledge of the
197 * association (and thus the association enters the CLOSED state).
199 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
200 * C) Rules for packet carrying SHUTDOWN COMPLETE:
202 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
203 * if the Verification Tag field of the packet matches its own tag and
204 * the T bit is not set
206 * it is set to its peer's tag and the T bit is set in the Chunk
208 * Otherwise, the receiver MUST silently discard the packet
209 * and take no further action. An endpoint MUST ignore the
210 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
213 * (endpoint, asoc, chunk)
216 * (asoc, reply_msg, msg_up, timers, counters)
218 * The return value is the disposition of the chunk.
220 enum sctp_disposition
sctp_sf_do_4_C(struct net
*net
,
221 const struct sctp_endpoint
*ep
,
222 const struct sctp_association
*asoc
,
223 const union sctp_subtype type
,
224 void *arg
, struct sctp_cmd_seq
*commands
)
226 struct sctp_chunk
*chunk
= arg
;
227 struct sctp_ulpevent
*ev
;
229 if (!sctp_vtag_verify_either(chunk
, asoc
))
230 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
232 /* RFC 2960 6.10 Bundling
234 * An endpoint MUST NOT bundle INIT, INIT ACK or
235 * SHUTDOWN COMPLETE with any other chunks.
237 if (!chunk
->singleton
)
238 return sctp_sf_violation_chunk(net
, ep
, asoc
, type
, arg
, commands
);
240 /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */
241 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
242 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
245 /* RFC 2960 10.2 SCTP-to-ULP
247 * H) SHUTDOWN COMPLETE notification
249 * When SCTP completes the shutdown procedures (section 9.2) this
250 * notification is passed to the upper layer.
252 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
253 0, 0, 0, NULL
, GFP_ATOMIC
);
255 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
258 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
259 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
260 * not the chunk should be discarded. If the endpoint is in
261 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
262 * T2-shutdown timer and remove all knowledge of the
263 * association (and thus the association enters the CLOSED
266 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
267 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
269 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
270 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
272 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
273 SCTP_STATE(SCTP_STATE_CLOSED
));
275 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
276 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
278 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
280 return SCTP_DISPOSITION_DELETE_TCB
;
284 * Respond to a normal INIT chunk.
285 * We are the side that is being asked for an association.
287 * Section: 5.1 Normal Establishment of an Association, B
288 * B) "Z" shall respond immediately with an INIT ACK chunk. The
289 * destination IP address of the INIT ACK MUST be set to the source
290 * IP address of the INIT to which this INIT ACK is responding. In
291 * the response, besides filling in other parameters, "Z" must set the
292 * Verification Tag field to Tag_A, and also provide its own
293 * Verification Tag (Tag_Z) in the Initiate Tag field.
295 * Verification Tag: Must be 0.
298 * (endpoint, asoc, chunk)
301 * (asoc, reply_msg, msg_up, timers, counters)
303 * The return value is the disposition of the chunk.
305 enum sctp_disposition
sctp_sf_do_5_1B_init(struct net
*net
,
306 const struct sctp_endpoint
*ep
,
307 const struct sctp_association
*asoc
,
308 const union sctp_subtype type
,
310 struct sctp_cmd_seq
*commands
)
312 struct sctp_chunk
*chunk
= arg
, *repl
, *err_chunk
;
313 struct sctp_unrecognized_param
*unk_param
;
314 struct sctp_association
*new_asoc
;
315 struct sctp_packet
*packet
;
319 * An endpoint MUST NOT bundle INIT, INIT ACK or
320 * SHUTDOWN COMPLETE with any other chunks.
323 * Furthermore, we require that the receiver of an INIT chunk MUST
324 * enforce these rules by silently discarding an arriving packet
325 * with an INIT chunk that is bundled with other chunks.
327 if (!chunk
->singleton
)
328 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
330 /* If the packet is an OOTB packet which is temporarily on the
331 * control endpoint, respond with an ABORT.
333 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
) {
334 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
335 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
338 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
341 if (chunk
->sctp_hdr
->vtag
!= 0)
342 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
344 /* Make sure that the INIT chunk has a valid length.
345 * Normally, this would cause an ABORT with a Protocol Violation
346 * error, but since we don't have an association, we'll
347 * just discard the packet.
349 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_init_chunk
)))
350 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
352 /* If the INIT is coming toward a closing socket, we'll send back
353 * and ABORT. Essentially, this catches the race of INIT being
354 * backloged to the socket at the same time as the user isses close().
355 * Since the socket and all its associations are going away, we
356 * can treat this OOTB
358 if (sctp_sstate(ep
->base
.sk
, CLOSING
))
359 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
361 /* Verify the INIT chunk before processing it. */
363 if (!sctp_verify_init(net
, ep
, asoc
, chunk
->chunk_hdr
->type
,
364 (struct sctp_init_chunk
*)chunk
->chunk_hdr
, chunk
,
366 /* This chunk contains fatal error. It is to be discarded.
367 * Send an ABORT, with causes if there is any.
370 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
371 (__u8
*)(err_chunk
->chunk_hdr
) +
372 sizeof(struct sctp_chunkhdr
),
373 ntohs(err_chunk
->chunk_hdr
->length
) -
374 sizeof(struct sctp_chunkhdr
));
376 sctp_chunk_free(err_chunk
);
379 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
380 SCTP_PACKET(packet
));
381 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
382 return SCTP_DISPOSITION_CONSUME
;
384 return SCTP_DISPOSITION_NOMEM
;
387 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
,
392 /* Grab the INIT header. */
393 chunk
->subh
.init_hdr
= (struct sctp_inithdr
*)chunk
->skb
->data
;
395 /* Tag the variable length parameters. */
396 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(struct sctp_inithdr
));
398 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
402 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
,
403 sctp_scope(sctp_source(chunk
)),
407 /* The call, sctp_process_init(), can fail on memory allocation. */
408 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
),
409 (struct sctp_init_chunk
*)chunk
->chunk_hdr
,
413 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
415 /* If there are errors need to be reported for unknown parameters,
416 * make sure to reserve enough room in the INIT ACK for them.
420 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
421 sizeof(struct sctp_chunkhdr
);
423 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
427 /* If there are errors need to be reported for unknown parameters,
428 * include them in the outgoing INIT ACK as "Unrecognized parameter"
432 /* Get the "Unrecognized parameter" parameter(s) out of the
433 * ERROR chunk generated by sctp_verify_init(). Since the
434 * error cause code for "unknown parameter" and the
435 * "Unrecognized parameter" type is the same, we can
436 * construct the parameters in INIT ACK by copying the
439 unk_param
= (struct sctp_unrecognized_param
*)
440 ((__u8
*)(err_chunk
->chunk_hdr
) +
441 sizeof(struct sctp_chunkhdr
));
442 /* Replace the cause code with the "Unrecognized parameter"
445 sctp_addto_chunk(repl
, len
, unk_param
);
446 sctp_chunk_free(err_chunk
);
449 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
451 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
454 * Note: After sending out INIT ACK with the State Cookie parameter,
455 * "Z" MUST NOT allocate any resources, nor keep any states for the
456 * new association. Otherwise, "Z" will be vulnerable to resource
459 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
461 return SCTP_DISPOSITION_DELETE_TCB
;
464 sctp_association_free(new_asoc
);
467 sctp_chunk_free(err_chunk
);
468 return SCTP_DISPOSITION_NOMEM
;
472 * Respond to a normal INIT ACK chunk.
473 * We are the side that is initiating the association.
475 * Section: 5.1 Normal Establishment of an Association, C
476 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
477 * timer and leave COOKIE-WAIT state. "A" shall then send the State
478 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
479 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
481 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
482 * DATA chunks, but it MUST be the first chunk in the packet and
483 * until the COOKIE ACK is returned the sender MUST NOT send any
484 * other packets to the peer.
486 * Verification Tag: 3.3.3
487 * If the value of the Initiate Tag in a received INIT ACK chunk is
488 * found to be 0, the receiver MUST treat it as an error and close the
489 * association by transmitting an ABORT.
492 * (endpoint, asoc, chunk)
495 * (asoc, reply_msg, msg_up, timers, counters)
497 * The return value is the disposition of the chunk.
499 enum sctp_disposition
sctp_sf_do_5_1C_ack(struct net
*net
,
500 const struct sctp_endpoint
*ep
,
501 const struct sctp_association
*asoc
,
502 const union sctp_subtype type
,
504 struct sctp_cmd_seq
*commands
)
506 struct sctp_init_chunk
*initchunk
;
507 struct sctp_chunk
*chunk
= arg
;
508 struct sctp_chunk
*err_chunk
;
509 struct sctp_packet
*packet
;
511 if (!sctp_vtag_verify(chunk
, asoc
))
512 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
515 * An endpoint MUST NOT bundle INIT, INIT ACK or
516 * SHUTDOWN COMPLETE with any other chunks.
518 if (!chunk
->singleton
)
519 return sctp_sf_violation_chunk(net
, ep
, asoc
, type
, arg
, commands
);
521 /* Make sure that the INIT-ACK chunk has a valid length */
522 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_initack_chunk
)))
523 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
525 /* Grab the INIT header. */
526 chunk
->subh
.init_hdr
= (struct sctp_inithdr
*)chunk
->skb
->data
;
528 /* Verify the INIT chunk before processing it. */
530 if (!sctp_verify_init(net
, ep
, asoc
, chunk
->chunk_hdr
->type
,
531 (struct sctp_init_chunk
*)chunk
->chunk_hdr
, chunk
,
534 enum sctp_error error
= SCTP_ERROR_NO_RESOURCE
;
536 /* This chunk contains fatal error. It is to be discarded.
537 * Send an ABORT, with causes. If there are no causes,
538 * then there wasn't enough memory. Just terminate
542 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
543 (__u8
*)(err_chunk
->chunk_hdr
) +
544 sizeof(struct sctp_chunkhdr
),
545 ntohs(err_chunk
->chunk_hdr
->length
) -
546 sizeof(struct sctp_chunkhdr
));
548 sctp_chunk_free(err_chunk
);
551 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
552 SCTP_PACKET(packet
));
553 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
554 error
= SCTP_ERROR_INV_PARAM
;
558 /* SCTP-AUTH, Section 6.3:
559 * It should be noted that if the receiver wants to tear
560 * down an association in an authenticated way only, the
561 * handling of malformed packets should not result in
562 * tearing down the association.
564 * This means that if we only want to abort associations
565 * in an authenticated way (i.e AUTH+ABORT), then we
566 * can't destroy this association just because the packet
569 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
570 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
572 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
573 return sctp_stop_t1_and_abort(net
, commands
, error
, ECONNREFUSED
,
574 asoc
, chunk
->transport
);
577 /* Tag the variable length parameters. Note that we never
578 * convert the parameters in an INIT chunk.
580 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(struct sctp_inithdr
));
582 initchunk
= (struct sctp_init_chunk
*)chunk
->chunk_hdr
;
584 sctp_add_cmd_sf(commands
, SCTP_CMD_PEER_INIT
,
585 SCTP_PEER_INIT(initchunk
));
587 /* Reset init error count upon receipt of INIT-ACK. */
588 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
590 /* 5.1 C) "A" shall stop the T1-init timer and leave
591 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
592 * timer, and enter the COOKIE-ECHOED state.
594 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
595 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
596 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
597 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
598 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
599 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED
));
601 /* SCTP-AUTH: genereate the assocition shared keys so that
602 * we can potentially signe the COOKIE-ECHO.
604 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_SHKEY
, SCTP_NULL());
606 /* 5.1 C) "A" shall then send the State Cookie received in the
607 * INIT ACK chunk in a COOKIE ECHO chunk, ...
609 /* If there is any errors to report, send the ERROR chunk generated
610 * for unknown parameters as well.
612 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_COOKIE_ECHO
,
613 SCTP_CHUNK(err_chunk
));
615 return SCTP_DISPOSITION_CONSUME
;
618 static bool sctp_auth_chunk_verify(struct net
*net
, struct sctp_chunk
*chunk
,
619 const struct sctp_association
*asoc
)
621 struct sctp_chunk auth
;
623 if (!chunk
->auth_chunk
)
626 /* SCTP-AUTH: auth_chunk pointer is only set when the cookie-echo
627 * is supposed to be authenticated and we have to do delayed
628 * authentication. We've just recreated the association using
629 * the information in the cookie and now it's much easier to
630 * do the authentication.
633 /* Make sure that we and the peer are AUTH capable */
634 if (!net
->sctp
.auth_enable
|| !asoc
->peer
.auth_capable
)
637 /* set-up our fake chunk so that we can process it */
638 auth
.skb
= chunk
->auth_chunk
;
639 auth
.asoc
= chunk
->asoc
;
640 auth
.sctp_hdr
= chunk
->sctp_hdr
;
641 auth
.chunk_hdr
= (struct sctp_chunkhdr
*)
642 skb_push(chunk
->auth_chunk
,
643 sizeof(struct sctp_chunkhdr
));
644 skb_pull(chunk
->auth_chunk
, sizeof(struct sctp_chunkhdr
));
645 auth
.transport
= chunk
->transport
;
647 return sctp_sf_authenticate(asoc
, &auth
) == SCTP_IERROR_NO_ERROR
;
651 * Respond to a normal COOKIE ECHO chunk.
652 * We are the side that is being asked for an association.
654 * Section: 5.1 Normal Establishment of an Association, D
655 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
656 * with a COOKIE ACK chunk after building a TCB and moving to
657 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
658 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
659 * chunk MUST be the first chunk in the packet.
661 * IMPLEMENTATION NOTE: An implementation may choose to send the
662 * Communication Up notification to the SCTP user upon reception
663 * of a valid COOKIE ECHO chunk.
665 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
666 * D) Rules for packet carrying a COOKIE ECHO
668 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
669 * Initial Tag received in the INIT ACK.
671 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
674 * (endpoint, asoc, chunk)
677 * (asoc, reply_msg, msg_up, timers, counters)
679 * The return value is the disposition of the chunk.
681 enum sctp_disposition
sctp_sf_do_5_1D_ce(struct net
*net
,
682 const struct sctp_endpoint
*ep
,
683 const struct sctp_association
*asoc
,
684 const union sctp_subtype type
,
686 struct sctp_cmd_seq
*commands
)
688 struct sctp_ulpevent
*ev
, *ai_ev
= NULL
;
689 struct sctp_association
*new_asoc
;
690 struct sctp_init_chunk
*peer_init
;
691 struct sctp_chunk
*chunk
= arg
;
692 struct sctp_chunk
*err_chk_p
;
693 struct sctp_chunk
*repl
;
697 /* If the packet is an OOTB packet which is temporarily on the
698 * control endpoint, respond with an ABORT.
700 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
) {
701 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
702 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
705 /* Make sure that the COOKIE_ECHO chunk has a valid length.
706 * In this case, we check that we have enough for at least a
707 * chunk header. More detailed verification is done
708 * in sctp_unpack_cookie().
710 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
711 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
713 /* If the endpoint is not listening or if the number of associations
714 * on the TCP-style socket exceed the max backlog, respond with an
718 if (!sctp_sstate(sk
, LISTENING
) ||
719 (sctp_style(sk
, TCP
) && sk_acceptq_is_full(sk
)))
720 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
722 /* "Decode" the chunk. We have no optional parameters so we
725 chunk
->subh
.cookie_hdr
=
726 (struct sctp_signed_cookie
*)chunk
->skb
->data
;
727 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
728 sizeof(struct sctp_chunkhdr
)))
731 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
732 * "Z" will reply with a COOKIE ACK chunk after building a TCB
733 * and moving to the ESTABLISHED state.
735 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
739 * If the re-build failed, what is the proper error path
742 * [We should abort the association. --piggy]
745 /* FIXME: Several errors are possible. A bad cookie should
746 * be silently discarded, but think about logging it too.
749 case -SCTP_IERROR_NOMEM
:
752 case -SCTP_IERROR_STALE_COOKIE
:
753 sctp_send_stale_cookie_err(net
, ep
, asoc
, chunk
, commands
,
755 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
757 case -SCTP_IERROR_BAD_SIG
:
759 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
764 /* Delay state machine commands until later.
766 * Re-build the bind address for the association is done in
767 * the sctp_unpack_cookie() already.
769 /* This is a brand-new association, so these are not yet side
770 * effects--it is safe to run them here.
772 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
774 if (!sctp_process_init(new_asoc
, chunk
,
775 &chunk
->subh
.cookie_hdr
->c
.peer_addr
,
776 peer_init
, GFP_ATOMIC
))
779 /* SCTP-AUTH: Now that we've populate required fields in
780 * sctp_process_init, set up the assocaition shared keys as
781 * necessary so that we can potentially authenticate the ACK
783 error
= sctp_auth_asoc_init_active_key(new_asoc
, GFP_ATOMIC
);
787 if (!sctp_auth_chunk_verify(net
, chunk
, new_asoc
)) {
788 sctp_association_free(new_asoc
);
789 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
792 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
796 /* RFC 2960 5.1 Normal Establishment of an Association
798 * D) IMPLEMENTATION NOTE: An implementation may choose to
799 * send the Communication Up notification to the SCTP user
800 * upon reception of a valid COOKIE ECHO chunk.
802 ev
= sctp_ulpevent_make_assoc_change(new_asoc
, 0, SCTP_COMM_UP
, 0,
803 new_asoc
->c
.sinit_num_ostreams
,
804 new_asoc
->c
.sinit_max_instreams
,
809 /* Sockets API Draft Section 5.3.1.6
810 * When a peer sends a Adaptation Layer Indication parameter , SCTP
811 * delivers this notification to inform the application that of the
812 * peers requested adaptation layer.
814 if (new_asoc
->peer
.adaptation_ind
) {
815 ai_ev
= sctp_ulpevent_make_adaptation_indication(new_asoc
,
821 /* Add all the state machine commands now since we've created
822 * everything. This way we don't introduce memory corruptions
823 * during side-effect processing and correclty count established
826 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
827 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
828 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
829 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
830 SCTP_INC_STATS(net
, SCTP_MIB_PASSIVEESTABS
);
831 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
833 if (new_asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
834 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
835 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
837 /* This will send the COOKIE ACK */
838 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
840 /* Queue the ASSOC_CHANGE event */
841 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
843 /* Send up the Adaptation Layer Indication event */
845 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
846 SCTP_ULPEVENT(ai_ev
));
848 return SCTP_DISPOSITION_CONSUME
;
851 sctp_ulpevent_free(ev
);
853 sctp_chunk_free(repl
);
855 sctp_association_free(new_asoc
);
857 return SCTP_DISPOSITION_NOMEM
;
861 * Respond to a normal COOKIE ACK chunk.
862 * We are the side that is asking for an association.
864 * RFC 2960 5.1 Normal Establishment of an Association
866 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
867 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
868 * timer. It may also notify its ULP about the successful
869 * establishment of the association with a Communication Up
870 * notification (see Section 10).
874 * (endpoint, asoc, chunk)
877 * (asoc, reply_msg, msg_up, timers, counters)
879 * The return value is the disposition of the chunk.
881 enum sctp_disposition
sctp_sf_do_5_1E_ca(struct net
*net
,
882 const struct sctp_endpoint
*ep
,
883 const struct sctp_association
*asoc
,
884 const union sctp_subtype type
,
886 struct sctp_cmd_seq
*commands
)
888 struct sctp_chunk
*chunk
= arg
;
889 struct sctp_ulpevent
*ev
;
891 if (!sctp_vtag_verify(chunk
, asoc
))
892 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
894 /* Verify that the chunk length for the COOKIE-ACK is OK.
895 * If we don't do this, any bundled chunks may be junked.
897 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
898 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
901 /* Reset init error count upon receipt of COOKIE-ACK,
902 * to avoid problems with the managemement of this
903 * counter in stale cookie situations when a transition back
904 * from the COOKIE-ECHOED state to the COOKIE-WAIT
905 * state is performed.
907 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
909 /* RFC 2960 5.1 Normal Establishment of an Association
911 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
912 * from the COOKIE-ECHOED state to the ESTABLISHED state,
913 * stopping the T1-cookie timer.
915 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
916 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
917 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
918 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
919 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
920 SCTP_INC_STATS(net
, SCTP_MIB_ACTIVEESTABS
);
921 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
922 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
923 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
924 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
926 /* It may also notify its ULP about the successful
927 * establishment of the association with a Communication Up
928 * notification (see Section 10).
930 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_COMM_UP
,
931 0, asoc
->c
.sinit_num_ostreams
,
932 asoc
->c
.sinit_max_instreams
,
938 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
940 /* Sockets API Draft Section 5.3.1.6
941 * When a peer sends a Adaptation Layer Indication parameter , SCTP
942 * delivers this notification to inform the application that of the
943 * peers requested adaptation layer.
945 if (asoc
->peer
.adaptation_ind
) {
946 ev
= sctp_ulpevent_make_adaptation_indication(asoc
, GFP_ATOMIC
);
950 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
954 return SCTP_DISPOSITION_CONSUME
;
956 return SCTP_DISPOSITION_NOMEM
;
959 /* Generate and sendout a heartbeat packet. */
960 static enum sctp_disposition
sctp_sf_heartbeat(
961 const struct sctp_endpoint
*ep
,
962 const struct sctp_association
*asoc
,
963 const union sctp_subtype type
,
965 struct sctp_cmd_seq
*commands
)
967 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
968 struct sctp_chunk
*reply
;
970 /* Send a heartbeat to our peer. */
971 reply
= sctp_make_heartbeat(asoc
, transport
);
973 return SCTP_DISPOSITION_NOMEM
;
975 /* Set rto_pending indicating that an RTT measurement
976 * is started with this heartbeat chunk.
978 sctp_add_cmd_sf(commands
, SCTP_CMD_RTO_PENDING
,
979 SCTP_TRANSPORT(transport
));
981 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
982 return SCTP_DISPOSITION_CONSUME
;
985 /* Generate a HEARTBEAT packet on the given transport. */
986 enum sctp_disposition
sctp_sf_sendbeat_8_3(struct net
*net
,
987 const struct sctp_endpoint
*ep
,
988 const struct sctp_association
*asoc
,
989 const union sctp_subtype type
,
991 struct sctp_cmd_seq
*commands
)
993 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
995 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
996 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
997 SCTP_ERROR(ETIMEDOUT
));
998 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
999 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
1000 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
1001 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
1002 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
1003 return SCTP_DISPOSITION_DELETE_TCB
;
1007 * The Sender-specific Heartbeat Info field should normally include
1008 * information about the sender's current time when this HEARTBEAT
1009 * chunk is sent and the destination transport address to which this
1010 * HEARTBEAT is sent (see Section 8.3).
1013 if (transport
->param_flags
& SPP_HB_ENABLE
) {
1014 if (SCTP_DISPOSITION_NOMEM
==
1015 sctp_sf_heartbeat(ep
, asoc
, type
, arg
,
1017 return SCTP_DISPOSITION_NOMEM
;
1019 /* Set transport error counter and association error counter
1020 * when sending heartbeat.
1022 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
1023 SCTP_TRANSPORT(transport
));
1025 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_IDLE
,
1026 SCTP_TRANSPORT(transport
));
1027 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMER_UPDATE
,
1028 SCTP_TRANSPORT(transport
));
1030 return SCTP_DISPOSITION_CONSUME
;
1033 /* resend asoc strreset_chunk. */
1034 enum sctp_disposition
sctp_sf_send_reconf(struct net
*net
,
1035 const struct sctp_endpoint
*ep
,
1036 const struct sctp_association
*asoc
,
1037 const union sctp_subtype type
,
1039 struct sctp_cmd_seq
*commands
)
1041 struct sctp_transport
*transport
= arg
;
1043 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
1044 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
1045 SCTP_ERROR(ETIMEDOUT
));
1046 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
1047 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
1048 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
1049 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
1050 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
1051 return SCTP_DISPOSITION_DELETE_TCB
;
1054 sctp_chunk_hold(asoc
->strreset_chunk
);
1055 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1056 SCTP_CHUNK(asoc
->strreset_chunk
));
1057 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
1059 return SCTP_DISPOSITION_CONSUME
;
1063 * Process an heartbeat request.
1065 * Section: 8.3 Path Heartbeat
1066 * The receiver of the HEARTBEAT should immediately respond with a
1067 * HEARTBEAT ACK that contains the Heartbeat Information field copied
1068 * from the received HEARTBEAT chunk.
1070 * Verification Tag: 8.5 Verification Tag [Normal verification]
1071 * When receiving an SCTP packet, the endpoint MUST ensure that the
1072 * value in the Verification Tag field of the received SCTP packet
1073 * matches its own Tag. If the received Verification Tag value does not
1074 * match the receiver's own tag value, the receiver shall silently
1075 * discard the packet and shall not process it any further except for
1076 * those cases listed in Section 8.5.1 below.
1079 * (endpoint, asoc, chunk)
1082 * (asoc, reply_msg, msg_up, timers, counters)
1084 * The return value is the disposition of the chunk.
1086 enum sctp_disposition
sctp_sf_beat_8_3(struct net
*net
,
1087 const struct sctp_endpoint
*ep
,
1088 const struct sctp_association
*asoc
,
1089 const union sctp_subtype type
,
1090 void *arg
, struct sctp_cmd_seq
*commands
)
1092 struct sctp_paramhdr
*param_hdr
;
1093 struct sctp_chunk
*chunk
= arg
;
1094 struct sctp_chunk
*reply
;
1097 if (!sctp_vtag_verify(chunk
, asoc
))
1098 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1100 /* Make sure that the HEARTBEAT chunk has a valid length. */
1101 if (!sctp_chunk_length_valid(chunk
,
1102 sizeof(struct sctp_heartbeat_chunk
)))
1103 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1106 /* 8.3 The receiver of the HEARTBEAT should immediately
1107 * respond with a HEARTBEAT ACK that contains the Heartbeat
1108 * Information field copied from the received HEARTBEAT chunk.
1110 chunk
->subh
.hb_hdr
= (struct sctp_heartbeathdr
*)chunk
->skb
->data
;
1111 param_hdr
= (struct sctp_paramhdr
*)chunk
->subh
.hb_hdr
;
1112 paylen
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(struct sctp_chunkhdr
);
1114 if (ntohs(param_hdr
->length
) > paylen
)
1115 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
1116 param_hdr
, commands
);
1118 if (!pskb_pull(chunk
->skb
, paylen
))
1121 reply
= sctp_make_heartbeat_ack(asoc
, chunk
, param_hdr
, paylen
);
1125 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
1126 return SCTP_DISPOSITION_CONSUME
;
1129 return SCTP_DISPOSITION_NOMEM
;
1133 * Process the returning HEARTBEAT ACK.
1135 * Section: 8.3 Path Heartbeat
1136 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
1137 * should clear the error counter of the destination transport
1138 * address to which the HEARTBEAT was sent, and mark the destination
1139 * transport address as active if it is not so marked. The endpoint may
1140 * optionally report to the upper layer when an inactive destination
1141 * address is marked as active due to the reception of the latest
1142 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
1143 * clear the association overall error count as well (as defined
1146 * The receiver of the HEARTBEAT ACK should also perform an RTT
1147 * measurement for that destination transport address using the time
1148 * value carried in the HEARTBEAT ACK chunk.
1150 * Verification Tag: 8.5 Verification Tag [Normal verification]
1153 * (endpoint, asoc, chunk)
1156 * (asoc, reply_msg, msg_up, timers, counters)
1158 * The return value is the disposition of the chunk.
1160 enum sctp_disposition
sctp_sf_backbeat_8_3(struct net
*net
,
1161 const struct sctp_endpoint
*ep
,
1162 const struct sctp_association
*asoc
,
1163 const union sctp_subtype type
,
1165 struct sctp_cmd_seq
*commands
)
1167 struct sctp_sender_hb_info
*hbinfo
;
1168 struct sctp_chunk
*chunk
= arg
;
1169 struct sctp_transport
*link
;
1170 unsigned long max_interval
;
1171 union sctp_addr from_addr
;
1173 if (!sctp_vtag_verify(chunk
, asoc
))
1174 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1176 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1177 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
) +
1179 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1182 hbinfo
= (struct sctp_sender_hb_info
*)chunk
->skb
->data
;
1183 /* Make sure that the length of the parameter is what we expect */
1184 if (ntohs(hbinfo
->param_hdr
.length
) != sizeof(*hbinfo
))
1185 return SCTP_DISPOSITION_DISCARD
;
1187 from_addr
= hbinfo
->daddr
;
1188 link
= sctp_assoc_lookup_paddr(asoc
, &from_addr
);
1190 /* This should never happen, but lets log it if so. */
1191 if (unlikely(!link
)) {
1192 if (from_addr
.sa
.sa_family
== AF_INET6
) {
1193 net_warn_ratelimited("%s association %p could not find address %pI6\n",
1196 &from_addr
.v6
.sin6_addr
);
1198 net_warn_ratelimited("%s association %p could not find address %pI4\n",
1201 &from_addr
.v4
.sin_addr
.s_addr
);
1203 return SCTP_DISPOSITION_DISCARD
;
1206 /* Validate the 64-bit random nonce. */
1207 if (hbinfo
->hb_nonce
!= link
->hb_nonce
)
1208 return SCTP_DISPOSITION_DISCARD
;
1210 max_interval
= link
->hbinterval
+ link
->rto
;
1212 /* Check if the timestamp looks valid. */
1213 if (time_after(hbinfo
->sent_at
, jiffies
) ||
1214 time_after(jiffies
, hbinfo
->sent_at
+ max_interval
)) {
1215 pr_debug("%s: HEARTBEAT ACK with invalid timestamp received "
1216 "for transport:%p\n", __func__
, link
);
1218 return SCTP_DISPOSITION_DISCARD
;
1221 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1222 * the HEARTBEAT should clear the error counter of the
1223 * destination transport address to which the HEARTBEAT was
1224 * sent and mark the destination transport address as active if
1225 * it is not so marked.
1227 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_ON
, SCTP_TRANSPORT(link
));
1229 return SCTP_DISPOSITION_CONSUME
;
1232 /* Helper function to send out an abort for the restart
1235 static int sctp_sf_send_restart_abort(struct net
*net
, union sctp_addr
*ssa
,
1236 struct sctp_chunk
*init
,
1237 struct sctp_cmd_seq
*commands
)
1239 struct sctp_af
*af
= sctp_get_af_specific(ssa
->v4
.sin_family
);
1240 union sctp_addr_param
*addrparm
;
1241 struct sctp_errhdr
*errhdr
;
1242 char buffer
[sizeof(*errhdr
) + sizeof(*addrparm
)];
1243 struct sctp_endpoint
*ep
;
1244 struct sctp_packet
*pkt
;
1247 /* Build the error on the stack. We are way to malloc crazy
1248 * throughout the code today.
1250 errhdr
= (struct sctp_errhdr
*)buffer
;
1251 addrparm
= (union sctp_addr_param
*)errhdr
->variable
;
1253 /* Copy into a parm format. */
1254 len
= af
->to_addr_param(ssa
, addrparm
);
1255 len
+= sizeof(*errhdr
);
1257 errhdr
->cause
= SCTP_ERROR_RESTART
;
1258 errhdr
->length
= htons(len
);
1260 /* Assign to the control socket. */
1261 ep
= sctp_sk(net
->sctp
.ctl_sock
)->ep
;
1263 /* Association is NULL since this may be a restart attack and we
1264 * want to send back the attacker's vtag.
1266 pkt
= sctp_abort_pkt_new(net
, ep
, NULL
, init
, errhdr
, len
);
1270 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
, SCTP_PACKET(pkt
));
1272 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
1274 /* Discard the rest of the inbound packet. */
1275 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
1278 /* Even if there is no memory, treat as a failure so
1279 * the packet will get dropped.
1284 static bool list_has_sctp_addr(const struct list_head
*list
,
1285 union sctp_addr
*ipaddr
)
1287 struct sctp_transport
*addr
;
1289 list_for_each_entry(addr
, list
, transports
) {
1290 if (sctp_cmp_addr_exact(ipaddr
, &addr
->ipaddr
))
1296 /* A restart is occurring, check to make sure no new addresses
1297 * are being added as we may be under a takeover attack.
1299 static int sctp_sf_check_restart_addrs(const struct sctp_association
*new_asoc
,
1300 const struct sctp_association
*asoc
,
1301 struct sctp_chunk
*init
,
1302 struct sctp_cmd_seq
*commands
)
1304 struct net
*net
= sock_net(new_asoc
->base
.sk
);
1305 struct sctp_transport
*new_addr
;
1308 /* Implementor's Guide - Section 5.2.2
1310 * Before responding the endpoint MUST check to see if the
1311 * unexpected INIT adds new addresses to the association. If new
1312 * addresses are added to the association, the endpoint MUST respond
1316 /* Search through all current addresses and make sure
1317 * we aren't adding any new ones.
1319 list_for_each_entry(new_addr
, &new_asoc
->peer
.transport_addr_list
,
1321 if (!list_has_sctp_addr(&asoc
->peer
.transport_addr_list
,
1322 &new_addr
->ipaddr
)) {
1323 sctp_sf_send_restart_abort(net
, &new_addr
->ipaddr
, init
,
1330 /* Return success if all addresses were found. */
1334 /* Populate the verification/tie tags based on overlapping INIT
1337 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1339 static void sctp_tietags_populate(struct sctp_association
*new_asoc
,
1340 const struct sctp_association
*asoc
)
1342 switch (asoc
->state
) {
1344 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1346 case SCTP_STATE_COOKIE_WAIT
:
1347 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1348 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1349 new_asoc
->c
.peer_ttag
= 0;
1352 case SCTP_STATE_COOKIE_ECHOED
:
1353 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1354 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1355 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1358 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1359 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1362 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1363 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1367 /* Other parameters for the endpoint SHOULD be copied from the
1368 * existing parameters of the association (e.g. number of
1369 * outbound streams) into the INIT ACK and cookie.
1371 new_asoc
->rwnd
= asoc
->rwnd
;
1372 new_asoc
->c
.sinit_num_ostreams
= asoc
->c
.sinit_num_ostreams
;
1373 new_asoc
->c
.sinit_max_instreams
= asoc
->c
.sinit_max_instreams
;
1374 new_asoc
->c
.initial_tsn
= asoc
->c
.initial_tsn
;
1378 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1381 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1383 * Returns value representing action to be taken. These action values
1384 * correspond to Action/Description values in RFC 2960, Table 2.
1386 static char sctp_tietags_compare(struct sctp_association
*new_asoc
,
1387 const struct sctp_association
*asoc
)
1389 /* In this case, the peer may have restarted. */
1390 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1391 (asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) &&
1392 (asoc
->c
.my_vtag
== new_asoc
->c
.my_ttag
) &&
1393 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_ttag
))
1396 /* Collision case B. */
1397 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1398 ((asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) ||
1399 (0 == asoc
->c
.peer_vtag
))) {
1403 /* Collision case D. */
1404 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1405 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
))
1408 /* Collision case C. */
1409 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1410 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
) &&
1411 (0 == new_asoc
->c
.my_ttag
) &&
1412 (0 == new_asoc
->c
.peer_ttag
))
1415 /* No match to any of the special cases; discard this packet. */
1419 /* Common helper routine for both duplicate and simulataneous INIT
1422 static enum sctp_disposition
sctp_sf_do_unexpected_init(
1424 const struct sctp_endpoint
*ep
,
1425 const struct sctp_association
*asoc
,
1426 const union sctp_subtype type
,
1428 struct sctp_cmd_seq
*commands
)
1430 struct sctp_chunk
*chunk
= arg
, *repl
, *err_chunk
;
1431 struct sctp_unrecognized_param
*unk_param
;
1432 struct sctp_association
*new_asoc
;
1433 enum sctp_disposition retval
;
1434 struct sctp_packet
*packet
;
1438 * An endpoint MUST NOT bundle INIT, INIT ACK or
1439 * SHUTDOWN COMPLETE with any other chunks.
1442 * Furthermore, we require that the receiver of an INIT chunk MUST
1443 * enforce these rules by silently discarding an arriving packet
1444 * with an INIT chunk that is bundled with other chunks.
1446 if (!chunk
->singleton
)
1447 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1449 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1452 if (chunk
->sctp_hdr
->vtag
!= 0)
1453 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
1455 /* Make sure that the INIT chunk has a valid length.
1456 * In this case, we generate a protocol violation since we have
1457 * an association established.
1459 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_init_chunk
)))
1460 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1462 /* Grab the INIT header. */
1463 chunk
->subh
.init_hdr
= (struct sctp_inithdr
*)chunk
->skb
->data
;
1465 /* Tag the variable length parameters. */
1466 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(struct sctp_inithdr
));
1468 /* Verify the INIT chunk before processing it. */
1470 if (!sctp_verify_init(net
, ep
, asoc
, chunk
->chunk_hdr
->type
,
1471 (struct sctp_init_chunk
*)chunk
->chunk_hdr
, chunk
,
1473 /* This chunk contains fatal error. It is to be discarded.
1474 * Send an ABORT, with causes if there is any.
1477 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
1478 (__u8
*)(err_chunk
->chunk_hdr
) +
1479 sizeof(struct sctp_chunkhdr
),
1480 ntohs(err_chunk
->chunk_hdr
->length
) -
1481 sizeof(struct sctp_chunkhdr
));
1484 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
1485 SCTP_PACKET(packet
));
1486 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
1487 retval
= SCTP_DISPOSITION_CONSUME
;
1489 retval
= SCTP_DISPOSITION_NOMEM
;
1493 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
,
1499 * Other parameters for the endpoint SHOULD be copied from the
1500 * existing parameters of the association (e.g. number of
1501 * outbound streams) into the INIT ACK and cookie.
1502 * FIXME: We are copying parameters from the endpoint not the
1505 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
1509 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
,
1510 sctp_scope(sctp_source(chunk
)), GFP_ATOMIC
) < 0)
1513 /* In the outbound INIT ACK the endpoint MUST copy its current
1514 * Verification Tag and Peers Verification tag into a reserved
1515 * place (local tie-tag and per tie-tag) within the state cookie.
1517 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
),
1518 (struct sctp_init_chunk
*)chunk
->chunk_hdr
,
1522 /* Make sure no new addresses are being added during the
1523 * restart. Do not do this check for COOKIE-WAIT state,
1524 * since there are no peer addresses to check against.
1525 * Upon return an ABORT will have been sent if needed.
1527 if (!sctp_state(asoc
, COOKIE_WAIT
)) {
1528 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
,
1530 retval
= SCTP_DISPOSITION_CONSUME
;
1535 sctp_tietags_populate(new_asoc
, asoc
);
1537 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1539 /* If there are errors need to be reported for unknown parameters,
1540 * make sure to reserve enough room in the INIT ACK for them.
1544 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
1545 sizeof(struct sctp_chunkhdr
);
1548 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
1552 /* If there are errors need to be reported for unknown parameters,
1553 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1557 /* Get the "Unrecognized parameter" parameter(s) out of the
1558 * ERROR chunk generated by sctp_verify_init(). Since the
1559 * error cause code for "unknown parameter" and the
1560 * "Unrecognized parameter" type is the same, we can
1561 * construct the parameters in INIT ACK by copying the
1562 * ERROR causes over.
1564 unk_param
= (struct sctp_unrecognized_param
*)
1565 ((__u8
*)(err_chunk
->chunk_hdr
) +
1566 sizeof(struct sctp_chunkhdr
));
1567 /* Replace the cause code with the "Unrecognized parameter"
1570 sctp_addto_chunk(repl
, len
, unk_param
);
1573 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
1574 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1577 * Note: After sending out INIT ACK with the State Cookie parameter,
1578 * "Z" MUST NOT allocate any resources for this new association.
1579 * Otherwise, "Z" will be vulnerable to resource attacks.
1581 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
1582 retval
= SCTP_DISPOSITION_CONSUME
;
1587 retval
= SCTP_DISPOSITION_NOMEM
;
1590 sctp_association_free(new_asoc
);
1593 sctp_chunk_free(err_chunk
);
1598 * Handle simultaneous INIT.
1599 * This means we started an INIT and then we got an INIT request from
1602 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1603 * This usually indicates an initialization collision, i.e., each
1604 * endpoint is attempting, at about the same time, to establish an
1605 * association with the other endpoint.
1607 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1608 * endpoint MUST respond with an INIT ACK using the same parameters it
1609 * sent in its original INIT chunk (including its Verification Tag,
1610 * unchanged). These original parameters are combined with those from the
1611 * newly received INIT chunk. The endpoint shall also generate a State
1612 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1613 * INIT to calculate the State Cookie.
1615 * After that, the endpoint MUST NOT change its state, the T1-init
1616 * timer shall be left running and the corresponding TCB MUST NOT be
1617 * destroyed. The normal procedures for handling State Cookies when
1618 * a TCB exists will resolve the duplicate INITs to a single association.
1620 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1621 * its Tie-Tags with the Tag information of itself and its peer (see
1622 * section 5.2.2 for a description of the Tie-Tags).
1624 * Verification Tag: Not explicit, but an INIT can not have a valid
1625 * verification tag, so we skip the check.
1628 * (endpoint, asoc, chunk)
1631 * (asoc, reply_msg, msg_up, timers, counters)
1633 * The return value is the disposition of the chunk.
1635 enum sctp_disposition
sctp_sf_do_5_2_1_siminit(
1637 const struct sctp_endpoint
*ep
,
1638 const struct sctp_association
*asoc
,
1639 const union sctp_subtype type
,
1641 struct sctp_cmd_seq
*commands
)
1643 /* Call helper to do the real work for both simulataneous and
1644 * duplicate INIT chunk handling.
1646 return sctp_sf_do_unexpected_init(net
, ep
, asoc
, type
, arg
, commands
);
1650 * Handle duplicated INIT messages. These are usually delayed
1653 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1654 * COOKIE-ECHOED and COOKIE-WAIT
1656 * Unless otherwise stated, upon reception of an unexpected INIT for
1657 * this association, the endpoint shall generate an INIT ACK with a
1658 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1659 * current Verification Tag and peer's Verification Tag into a reserved
1660 * place within the state cookie. We shall refer to these locations as
1661 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1662 * containing this INIT ACK MUST carry a Verification Tag value equal to
1663 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1664 * MUST contain a new Initiation Tag (randomly generated see Section
1665 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1666 * existing parameters of the association (e.g. number of outbound
1667 * streams) into the INIT ACK and cookie.
1669 * After sending out the INIT ACK, the endpoint shall take no further
1670 * actions, i.e., the existing association, including its current state,
1671 * and the corresponding TCB MUST NOT be changed.
1673 * Note: Only when a TCB exists and the association is not in a COOKIE-
1674 * WAIT state are the Tie-Tags populated. For a normal association INIT
1675 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1676 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1677 * State Cookie are populated as specified in section 5.2.1.
1679 * Verification Tag: Not specified, but an INIT has no way of knowing
1680 * what the verification tag could be, so we ignore it.
1683 * (endpoint, asoc, chunk)
1686 * (asoc, reply_msg, msg_up, timers, counters)
1688 * The return value is the disposition of the chunk.
1690 enum sctp_disposition
sctp_sf_do_5_2_2_dupinit(
1692 const struct sctp_endpoint
*ep
,
1693 const struct sctp_association
*asoc
,
1694 const union sctp_subtype type
,
1696 struct sctp_cmd_seq
*commands
)
1698 /* Call helper to do the real work for both simulataneous and
1699 * duplicate INIT chunk handling.
1701 return sctp_sf_do_unexpected_init(net
, ep
, asoc
, type
, arg
, commands
);
1706 * Unexpected INIT-ACK handler.
1709 * If an INIT ACK received by an endpoint in any state other than the
1710 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1711 * An unexpected INIT ACK usually indicates the processing of an old or
1712 * duplicated INIT chunk.
1714 enum sctp_disposition
sctp_sf_do_5_2_3_initack(
1716 const struct sctp_endpoint
*ep
,
1717 const struct sctp_association
*asoc
,
1718 const union sctp_subtype type
,
1720 struct sctp_cmd_seq
*commands
)
1722 /* Per the above section, we'll discard the chunk if we have an
1723 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1725 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
)
1726 return sctp_sf_ootb(net
, ep
, asoc
, type
, arg
, commands
);
1728 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
1731 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1734 * A) In this case, the peer may have restarted.
1736 static enum sctp_disposition
sctp_sf_do_dupcook_a(
1738 const struct sctp_endpoint
*ep
,
1739 const struct sctp_association
*asoc
,
1740 struct sctp_chunk
*chunk
,
1741 struct sctp_cmd_seq
*commands
,
1742 struct sctp_association
*new_asoc
)
1744 struct sctp_init_chunk
*peer_init
;
1745 enum sctp_disposition disposition
;
1746 struct sctp_ulpevent
*ev
;
1747 struct sctp_chunk
*repl
;
1748 struct sctp_chunk
*err
;
1750 /* new_asoc is a brand-new association, so these are not yet
1751 * side effects--it is safe to run them here.
1753 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1755 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
), peer_init
,
1759 if (!sctp_auth_chunk_verify(net
, chunk
, new_asoc
))
1760 return SCTP_DISPOSITION_DISCARD
;
1762 /* Make sure no new addresses are being added during the
1763 * restart. Though this is a pretty complicated attack
1764 * since you'd have to get inside the cookie.
1766 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
, commands
))
1767 return SCTP_DISPOSITION_CONSUME
;
1769 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1770 * the peer has restarted (Action A), it MUST NOT setup a new
1771 * association but instead resend the SHUTDOWN ACK and send an ERROR
1772 * chunk with a "Cookie Received while Shutting Down" error cause to
1775 if (sctp_state(asoc
, SHUTDOWN_ACK_SENT
)) {
1776 disposition
= sctp_sf_do_9_2_reshutack(net
, ep
, asoc
,
1777 SCTP_ST_CHUNK(chunk
->chunk_hdr
->type
),
1779 if (SCTP_DISPOSITION_NOMEM
== disposition
)
1782 err
= sctp_make_op_error(asoc
, chunk
,
1783 SCTP_ERROR_COOKIE_IN_SHUTDOWN
,
1786 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1789 return SCTP_DISPOSITION_CONSUME
;
1792 /* For now, stop pending T3-rtx and SACK timers, fail any unsent/unacked
1793 * data. Consider the optional choice of resending of this data.
1795 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
1796 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1797 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK
));
1798 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_OUTQUEUE
, SCTP_NULL());
1800 /* Stop pending T4-rto timer, teardown ASCONF queue, ASCONF-ACK queue
1801 * and ASCONF-ACK cache.
1803 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1804 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
1805 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_ASCONF_QUEUE
, SCTP_NULL());
1807 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1811 /* Report association restart to upper layer. */
1812 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_RESTART
, 0,
1813 new_asoc
->c
.sinit_num_ostreams
,
1814 new_asoc
->c
.sinit_max_instreams
,
1819 /* Update the content of current association. */
1820 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1821 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
1822 if (sctp_state(asoc
, SHUTDOWN_PENDING
) &&
1823 (sctp_sstate(asoc
->base
.sk
, CLOSING
) ||
1824 sock_flag(asoc
->base
.sk
, SOCK_DEAD
))) {
1825 /* if were currently in SHUTDOWN_PENDING, but the socket
1826 * has been closed by user, don't transition to ESTABLISHED.
1827 * Instead trigger SHUTDOWN bundled with COOKIE_ACK.
1829 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1830 return sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
,
1831 SCTP_ST_CHUNK(0), NULL
,
1834 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1835 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1836 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1838 return SCTP_DISPOSITION_CONSUME
;
1841 sctp_chunk_free(repl
);
1843 return SCTP_DISPOSITION_NOMEM
;
1846 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1849 * B) In this case, both sides may be attempting to start an association
1850 * at about the same time but the peer endpoint started its INIT
1851 * after responding to the local endpoint's INIT
1853 /* This case represents an initialization collision. */
1854 static enum sctp_disposition
sctp_sf_do_dupcook_b(
1856 const struct sctp_endpoint
*ep
,
1857 const struct sctp_association
*asoc
,
1858 struct sctp_chunk
*chunk
,
1859 struct sctp_cmd_seq
*commands
,
1860 struct sctp_association
*new_asoc
)
1862 struct sctp_init_chunk
*peer_init
;
1863 struct sctp_chunk
*repl
;
1865 /* new_asoc is a brand-new association, so these are not yet
1866 * side effects--it is safe to run them here.
1868 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1869 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
), peer_init
,
1873 if (!sctp_auth_chunk_verify(net
, chunk
, new_asoc
))
1874 return SCTP_DISPOSITION_DISCARD
;
1876 /* Update the content of current association. */
1877 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1878 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1879 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1880 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
1881 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
1883 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1887 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1889 /* RFC 2960 5.1 Normal Establishment of an Association
1891 * D) IMPLEMENTATION NOTE: An implementation may choose to
1892 * send the Communication Up notification to the SCTP user
1893 * upon reception of a valid COOKIE ECHO chunk.
1895 * Sadly, this needs to be implemented as a side-effect, because
1896 * we are not guaranteed to have set the association id of the real
1897 * association and so these notifications need to be delayed until
1898 * the association id is allocated.
1901 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_CHANGE
, SCTP_U8(SCTP_COMM_UP
));
1903 /* Sockets API Draft Section 5.3.1.6
1904 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1905 * delivers this notification to inform the application that of the
1906 * peers requested adaptation layer.
1908 * This also needs to be done as a side effect for the same reason as
1911 if (asoc
->peer
.adaptation_ind
)
1912 sctp_add_cmd_sf(commands
, SCTP_CMD_ADAPTATION_IND
, SCTP_NULL());
1914 return SCTP_DISPOSITION_CONSUME
;
1917 return SCTP_DISPOSITION_NOMEM
;
1920 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1923 * C) In this case, the local endpoint's cookie has arrived late.
1924 * Before it arrived, the local endpoint sent an INIT and received an
1925 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1926 * but a new tag of its own.
1928 /* This case represents an initialization collision. */
1929 static enum sctp_disposition
sctp_sf_do_dupcook_c(
1931 const struct sctp_endpoint
*ep
,
1932 const struct sctp_association
*asoc
,
1933 struct sctp_chunk
*chunk
,
1934 struct sctp_cmd_seq
*commands
,
1935 struct sctp_association
*new_asoc
)
1937 /* The cookie should be silently discarded.
1938 * The endpoint SHOULD NOT change states and should leave
1939 * any timers running.
1941 return SCTP_DISPOSITION_DISCARD
;
1944 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1948 * D) When both local and remote tags match the endpoint should always
1949 * enter the ESTABLISHED state, if it has not already done so.
1951 /* This case represents an initialization collision. */
1952 static enum sctp_disposition
sctp_sf_do_dupcook_d(
1954 const struct sctp_endpoint
*ep
,
1955 const struct sctp_association
*asoc
,
1956 struct sctp_chunk
*chunk
,
1957 struct sctp_cmd_seq
*commands
,
1958 struct sctp_association
*new_asoc
)
1960 struct sctp_ulpevent
*ev
= NULL
, *ai_ev
= NULL
;
1961 struct sctp_chunk
*repl
;
1963 /* Clarification from Implementor's Guide:
1964 * D) When both local and remote tags match the endpoint should
1965 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1966 * It should stop any cookie timer that may be running and send
1970 if (!sctp_auth_chunk_verify(net
, chunk
, asoc
))
1971 return SCTP_DISPOSITION_DISCARD
;
1973 /* Don't accidentally move back into established state. */
1974 if (asoc
->state
< SCTP_STATE_ESTABLISHED
) {
1975 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1976 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
1977 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1978 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1979 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
1980 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
,
1983 /* RFC 2960 5.1 Normal Establishment of an Association
1985 * D) IMPLEMENTATION NOTE: An implementation may choose
1986 * to send the Communication Up notification to the
1987 * SCTP user upon reception of a valid COOKIE
1990 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0,
1992 asoc
->c
.sinit_num_ostreams
,
1993 asoc
->c
.sinit_max_instreams
,
1998 /* Sockets API Draft Section 5.3.1.6
1999 * When a peer sends a Adaptation Layer Indication parameter,
2000 * SCTP delivers this notification to inform the application
2001 * that of the peers requested adaptation layer.
2003 if (asoc
->peer
.adaptation_ind
) {
2004 ai_ev
= sctp_ulpevent_make_adaptation_indication(asoc
,
2012 repl
= sctp_make_cookie_ack(asoc
, chunk
);
2016 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
2019 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
2022 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
2023 SCTP_ULPEVENT(ai_ev
));
2025 return SCTP_DISPOSITION_CONSUME
;
2029 sctp_ulpevent_free(ai_ev
);
2031 sctp_ulpevent_free(ev
);
2032 return SCTP_DISPOSITION_NOMEM
;
2036 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
2037 * chunk was retransmitted and then delayed in the network.
2039 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
2041 * Verification Tag: None. Do cookie validation.
2044 * (endpoint, asoc, chunk)
2047 * (asoc, reply_msg, msg_up, timers, counters)
2049 * The return value is the disposition of the chunk.
2051 enum sctp_disposition
sctp_sf_do_5_2_4_dupcook(
2053 const struct sctp_endpoint
*ep
,
2054 const struct sctp_association
*asoc
,
2055 const union sctp_subtype type
,
2057 struct sctp_cmd_seq
*commands
)
2059 struct sctp_association
*new_asoc
;
2060 struct sctp_chunk
*chunk
= arg
;
2061 enum sctp_disposition retval
;
2062 struct sctp_chunk
*err_chk_p
;
2066 /* Make sure that the chunk has a valid length from the protocol
2067 * perspective. In this case check to make sure we have at least
2068 * enough for the chunk header. Cookie length verification is
2071 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
2072 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2075 /* "Decode" the chunk. We have no optional parameters so we
2076 * are in good shape.
2078 chunk
->subh
.cookie_hdr
= (struct sctp_signed_cookie
*)chunk
->skb
->data
;
2079 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
2080 sizeof(struct sctp_chunkhdr
)))
2083 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
2084 * of a duplicate COOKIE ECHO match the Verification Tags of the
2085 * current association, consider the State Cookie valid even if
2086 * the lifespan is exceeded.
2088 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
2092 * If the re-build failed, what is the proper error path
2095 * [We should abort the association. --piggy]
2098 /* FIXME: Several errors are possible. A bad cookie should
2099 * be silently discarded, but think about logging it too.
2102 case -SCTP_IERROR_NOMEM
:
2105 case -SCTP_IERROR_STALE_COOKIE
:
2106 sctp_send_stale_cookie_err(net
, ep
, asoc
, chunk
, commands
,
2108 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2109 case -SCTP_IERROR_BAD_SIG
:
2111 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2115 /* Set temp so that it won't be added into hashtable */
2118 /* Compare the tie_tag in cookie with the verification tag of
2119 * current association.
2121 action
= sctp_tietags_compare(new_asoc
, asoc
);
2124 case 'A': /* Association restart. */
2125 retval
= sctp_sf_do_dupcook_a(net
, ep
, asoc
, chunk
, commands
,
2129 case 'B': /* Collision case B. */
2130 retval
= sctp_sf_do_dupcook_b(net
, ep
, asoc
, chunk
, commands
,
2134 case 'C': /* Collision case C. */
2135 retval
= sctp_sf_do_dupcook_c(net
, ep
, asoc
, chunk
, commands
,
2139 case 'D': /* Collision case D. */
2140 retval
= sctp_sf_do_dupcook_d(net
, ep
, asoc
, chunk
, commands
,
2144 default: /* Discard packet for all others. */
2145 retval
= sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2149 /* Delete the tempory new association. */
2150 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_ASOC
, SCTP_ASOC(new_asoc
));
2151 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
2153 /* Restore association pointer to provide SCTP command interpeter
2154 * with a valid context in case it needs to manipulate
2156 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_ASOC
,
2157 SCTP_ASOC((struct sctp_association
*)asoc
));
2162 return SCTP_DISPOSITION_NOMEM
;
2166 * Process an ABORT. (SHUTDOWN-PENDING state)
2168 * See sctp_sf_do_9_1_abort().
2170 enum sctp_disposition
sctp_sf_shutdown_pending_abort(
2172 const struct sctp_endpoint
*ep
,
2173 const struct sctp_association
*asoc
,
2174 const union sctp_subtype type
,
2176 struct sctp_cmd_seq
*commands
)
2178 struct sctp_chunk
*chunk
= arg
;
2180 if (!sctp_vtag_verify_either(chunk
, asoc
))
2181 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2183 /* Make sure that the ABORT chunk has a valid length.
2184 * Since this is an ABORT chunk, we have to discard it
2185 * because of the following text:
2186 * RFC 2960, Section 3.3.7
2187 * If an endpoint receives an ABORT with a format error or for an
2188 * association that doesn't exist, it MUST silently discard it.
2189 * Because the length is "invalid", we can't really discard just
2190 * as we do not know its true length. So, to be safe, discard the
2193 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_abort_chunk
)))
2194 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2196 /* ADD-IP: Special case for ABORT chunks
2197 * F4) One special consideration is that ABORT Chunks arriving
2198 * destined to the IP address being deleted MUST be
2199 * ignored (see Section 5.3.1 for further details).
2201 if (SCTP_ADDR_DEL
==
2202 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2203 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2205 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2209 * Process an ABORT. (SHUTDOWN-SENT state)
2211 * See sctp_sf_do_9_1_abort().
2213 enum sctp_disposition
sctp_sf_shutdown_sent_abort(
2215 const struct sctp_endpoint
*ep
,
2216 const struct sctp_association
*asoc
,
2217 const union sctp_subtype type
,
2219 struct sctp_cmd_seq
*commands
)
2221 struct sctp_chunk
*chunk
= arg
;
2223 if (!sctp_vtag_verify_either(chunk
, asoc
))
2224 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2226 /* Make sure that the ABORT chunk has a valid length.
2227 * Since this is an ABORT chunk, we have to discard it
2228 * because of the following text:
2229 * RFC 2960, Section 3.3.7
2230 * If an endpoint receives an ABORT with a format error or for an
2231 * association that doesn't exist, it MUST silently discard it.
2232 * Because the length is "invalid", we can't really discard just
2233 * as we do not know its true length. So, to be safe, discard the
2236 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_abort_chunk
)))
2237 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2239 /* ADD-IP: Special case for ABORT chunks
2240 * F4) One special consideration is that ABORT Chunks arriving
2241 * destined to the IP address being deleted MUST be
2242 * ignored (see Section 5.3.1 for further details).
2244 if (SCTP_ADDR_DEL
==
2245 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2246 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2248 /* Stop the T2-shutdown timer. */
2249 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2250 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2252 /* Stop the T5-shutdown guard timer. */
2253 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2254 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
2256 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2260 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2262 * See sctp_sf_do_9_1_abort().
2264 enum sctp_disposition
sctp_sf_shutdown_ack_sent_abort(
2266 const struct sctp_endpoint
*ep
,
2267 const struct sctp_association
*asoc
,
2268 const union sctp_subtype type
,
2270 struct sctp_cmd_seq
*commands
)
2272 /* The same T2 timer, so we should be able to use
2273 * common function with the SHUTDOWN-SENT state.
2275 return sctp_sf_shutdown_sent_abort(net
, ep
, asoc
, type
, arg
, commands
);
2279 * Handle an Error received in COOKIE_ECHOED state.
2281 * Only handle the error type of stale COOKIE Error, the other errors will
2285 * (endpoint, asoc, chunk)
2288 * (asoc, reply_msg, msg_up, timers, counters)
2290 * The return value is the disposition of the chunk.
2292 enum sctp_disposition
sctp_sf_cookie_echoed_err(
2294 const struct sctp_endpoint
*ep
,
2295 const struct sctp_association
*asoc
,
2296 const union sctp_subtype type
,
2298 struct sctp_cmd_seq
*commands
)
2300 struct sctp_chunk
*chunk
= arg
;
2301 struct sctp_errhdr
*err
;
2303 if (!sctp_vtag_verify(chunk
, asoc
))
2304 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2306 /* Make sure that the ERROR chunk has a valid length.
2307 * The parameter walking depends on this as well.
2309 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_operr_chunk
)))
2310 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2313 /* Process the error here */
2314 /* FUTURE FIXME: When PR-SCTP related and other optional
2315 * parms are emitted, this will have to change to handle multiple
2318 sctp_walk_errors(err
, chunk
->chunk_hdr
) {
2319 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
)
2320 return sctp_sf_do_5_2_6_stale(net
, ep
, asoc
, type
,
2324 /* It is possible to have malformed error causes, and that
2325 * will cause us to end the walk early. However, since
2326 * we are discarding the packet, there should be no adverse
2329 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2333 * Handle a Stale COOKIE Error
2335 * Section: 5.2.6 Handle Stale COOKIE Error
2336 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2337 * one of the following three alternatives.
2339 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2340 * Preservative parameter requesting an extension to the lifetime of
2341 * the State Cookie. When calculating the time extension, an
2342 * implementation SHOULD use the RTT information measured based on the
2343 * previous COOKIE ECHO / ERROR exchange, and should add no more
2344 * than 1 second beyond the measured RTT, due to long State Cookie
2345 * lifetimes making the endpoint more subject to a replay attack.
2347 * Verification Tag: Not explicit, but safe to ignore.
2350 * (endpoint, asoc, chunk)
2353 * (asoc, reply_msg, msg_up, timers, counters)
2355 * The return value is the disposition of the chunk.
2357 static enum sctp_disposition
sctp_sf_do_5_2_6_stale(
2359 const struct sctp_endpoint
*ep
,
2360 const struct sctp_association
*asoc
,
2361 const union sctp_subtype type
,
2363 struct sctp_cmd_seq
*commands
)
2365 int attempts
= asoc
->init_err_counter
+ 1;
2366 struct sctp_chunk
*chunk
= arg
, *reply
;
2367 struct sctp_cookie_preserve_param bht
;
2368 struct sctp_bind_addr
*bp
;
2369 struct sctp_errhdr
*err
;
2372 if (attempts
> asoc
->max_init_attempts
) {
2373 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
2374 SCTP_ERROR(ETIMEDOUT
));
2375 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2376 SCTP_PERR(SCTP_ERROR_STALE_COOKIE
));
2377 return SCTP_DISPOSITION_DELETE_TCB
;
2380 err
= (struct sctp_errhdr
*)(chunk
->skb
->data
);
2382 /* When calculating the time extension, an implementation
2383 * SHOULD use the RTT information measured based on the
2384 * previous COOKIE ECHO / ERROR exchange, and should add no
2385 * more than 1 second beyond the measured RTT, due to long
2386 * State Cookie lifetimes making the endpoint more subject to
2388 * Measure of Staleness's unit is usec. (1/1000000 sec)
2389 * Suggested Cookie Life-span Increment's unit is msec.
2391 * In general, if you use the suggested cookie life, the value
2392 * found in the field of measure of staleness should be doubled
2393 * to give ample time to retransmit the new cookie and thus
2394 * yield a higher probability of success on the reattempt.
2396 stale
= ntohl(*(__be32
*)((u8
*)err
+ sizeof(*err
)));
2397 stale
= (stale
* 2) / 1000;
2399 bht
.param_hdr
.type
= SCTP_PARAM_COOKIE_PRESERVATIVE
;
2400 bht
.param_hdr
.length
= htons(sizeof(bht
));
2401 bht
.lifespan_increment
= htonl(stale
);
2403 /* Build that new INIT chunk. */
2404 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
2405 reply
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, sizeof(bht
));
2409 sctp_addto_chunk(reply
, sizeof(bht
), &bht
);
2411 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2412 sctp_add_cmd_sf(commands
, SCTP_CMD_CLEAR_INIT_TAG
, SCTP_NULL());
2414 /* Stop pending T3-rtx and heartbeat timers */
2415 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
2416 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
2418 /* Delete non-primary peer ip addresses since we are transitioning
2419 * back to the COOKIE-WAIT state
2421 sctp_add_cmd_sf(commands
, SCTP_CMD_DEL_NON_PRIMARY
, SCTP_NULL());
2423 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2426 sctp_add_cmd_sf(commands
, SCTP_CMD_T1_RETRAN
,
2427 SCTP_TRANSPORT(asoc
->peer
.primary_path
));
2429 /* Cast away the const modifier, as we want to just
2430 * rerun it through as a sideffect.
2432 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_INC
, SCTP_NULL());
2434 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2435 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
2436 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2437 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
2438 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
2439 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2441 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2443 return SCTP_DISPOSITION_CONSUME
;
2446 return SCTP_DISPOSITION_NOMEM
;
2453 * After checking the Verification Tag, the receiving endpoint shall
2454 * remove the association from its record, and shall report the
2455 * termination to its upper layer.
2457 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2458 * B) Rules for packet carrying ABORT:
2460 * - The endpoint shall always fill in the Verification Tag field of the
2461 * outbound packet with the destination endpoint's tag value if it
2464 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2465 * MUST follow the procedure described in Section 8.4.
2467 * - The receiver MUST accept the packet if the Verification Tag
2468 * matches either its own tag, OR the tag of its peer. Otherwise, the
2469 * receiver MUST silently discard the packet and take no further
2473 * (endpoint, asoc, chunk)
2476 * (asoc, reply_msg, msg_up, timers, counters)
2478 * The return value is the disposition of the chunk.
2480 enum sctp_disposition
sctp_sf_do_9_1_abort(
2482 const struct sctp_endpoint
*ep
,
2483 const struct sctp_association
*asoc
,
2484 const union sctp_subtype type
,
2486 struct sctp_cmd_seq
*commands
)
2488 struct sctp_chunk
*chunk
= arg
;
2490 if (!sctp_vtag_verify_either(chunk
, asoc
))
2491 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2493 /* Make sure that the ABORT chunk has a valid length.
2494 * Since this is an ABORT chunk, we have to discard it
2495 * because of the following text:
2496 * RFC 2960, Section 3.3.7
2497 * If an endpoint receives an ABORT with a format error or for an
2498 * association that doesn't exist, it MUST silently discard it.
2499 * Because the length is "invalid", we can't really discard just
2500 * as we do not know its true length. So, to be safe, discard the
2503 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_abort_chunk
)))
2504 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2506 /* ADD-IP: Special case for ABORT chunks
2507 * F4) One special consideration is that ABORT Chunks arriving
2508 * destined to the IP address being deleted MUST be
2509 * ignored (see Section 5.3.1 for further details).
2511 if (SCTP_ADDR_DEL
==
2512 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2513 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2515 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2518 static enum sctp_disposition
__sctp_sf_do_9_1_abort(
2520 const struct sctp_endpoint
*ep
,
2521 const struct sctp_association
*asoc
,
2522 const union sctp_subtype type
,
2524 struct sctp_cmd_seq
*commands
)
2526 __be16 error
= SCTP_ERROR_NO_ERROR
;
2527 struct sctp_chunk
*chunk
= arg
;
2530 /* See if we have an error cause code in the chunk. */
2531 len
= ntohs(chunk
->chunk_hdr
->length
);
2532 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
)) {
2533 struct sctp_errhdr
*err
;
2535 sctp_walk_errors(err
, chunk
->chunk_hdr
);
2536 if ((void *)err
!= (void *)chunk
->chunk_end
)
2537 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
,
2540 error
= ((struct sctp_errhdr
*)chunk
->skb
->data
)->cause
;
2543 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(ECONNRESET
));
2544 /* ASSOC_FAILED will DELETE_TCB. */
2545 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
, SCTP_PERR(error
));
2546 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
2547 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
2549 return SCTP_DISPOSITION_ABORT
;
2553 * Process an ABORT. (COOKIE-WAIT state)
2555 * See sctp_sf_do_9_1_abort() above.
2557 enum sctp_disposition
sctp_sf_cookie_wait_abort(
2559 const struct sctp_endpoint
*ep
,
2560 const struct sctp_association
*asoc
,
2561 const union sctp_subtype type
,
2563 struct sctp_cmd_seq
*commands
)
2565 __be16 error
= SCTP_ERROR_NO_ERROR
;
2566 struct sctp_chunk
*chunk
= arg
;
2569 if (!sctp_vtag_verify_either(chunk
, asoc
))
2570 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2572 /* Make sure that the ABORT chunk has a valid length.
2573 * Since this is an ABORT chunk, we have to discard it
2574 * because of the following text:
2575 * RFC 2960, Section 3.3.7
2576 * If an endpoint receives an ABORT with a format error or for an
2577 * association that doesn't exist, it MUST silently discard it.
2578 * Because the length is "invalid", we can't really discard just
2579 * as we do not know its true length. So, to be safe, discard the
2582 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_abort_chunk
)))
2583 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2585 /* See if we have an error cause code in the chunk. */
2586 len
= ntohs(chunk
->chunk_hdr
->length
);
2587 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2588 error
= ((struct sctp_errhdr
*)chunk
->skb
->data
)->cause
;
2590 return sctp_stop_t1_and_abort(net
, commands
, error
, ECONNREFUSED
, asoc
,
2595 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2597 enum sctp_disposition
sctp_sf_cookie_wait_icmp_abort(
2599 const struct sctp_endpoint
*ep
,
2600 const struct sctp_association
*asoc
,
2601 const union sctp_subtype type
,
2603 struct sctp_cmd_seq
*commands
)
2605 return sctp_stop_t1_and_abort(net
, commands
, SCTP_ERROR_NO_ERROR
,
2607 (struct sctp_transport
*)arg
);
2611 * Process an ABORT. (COOKIE-ECHOED state)
2613 enum sctp_disposition
sctp_sf_cookie_echoed_abort(
2615 const struct sctp_endpoint
*ep
,
2616 const struct sctp_association
*asoc
,
2617 const union sctp_subtype type
,
2619 struct sctp_cmd_seq
*commands
)
2621 /* There is a single T1 timer, so we should be able to use
2622 * common function with the COOKIE-WAIT state.
2624 return sctp_sf_cookie_wait_abort(net
, ep
, asoc
, type
, arg
, commands
);
2628 * Stop T1 timer and abort association with "INIT failed".
2630 * This is common code called by several sctp_sf_*_abort() functions above.
2632 static enum sctp_disposition
sctp_stop_t1_and_abort(
2634 struct sctp_cmd_seq
*commands
,
2635 __be16 error
, int sk_err
,
2636 const struct sctp_association
*asoc
,
2637 struct sctp_transport
*transport
)
2639 pr_debug("%s: ABORT received (INIT)\n", __func__
);
2641 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2642 SCTP_STATE(SCTP_STATE_CLOSED
));
2643 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
2644 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2645 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2646 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(sk_err
));
2647 /* CMD_INIT_FAILED will DELETE_TCB. */
2648 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2651 return SCTP_DISPOSITION_ABORT
;
2655 * sctp_sf_do_9_2_shut
2658 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2659 * - enter the SHUTDOWN-RECEIVED state,
2661 * - stop accepting new data from its SCTP user
2663 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2664 * that all its outstanding DATA chunks have been received by the
2667 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2668 * send a SHUTDOWN in response to a ULP request. And should discard
2669 * subsequent SHUTDOWN chunks.
2671 * If there are still outstanding DATA chunks left, the SHUTDOWN
2672 * receiver shall continue to follow normal data transmission
2673 * procedures defined in Section 6 until all outstanding DATA chunks
2674 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2675 * new data from its SCTP user.
2677 * Verification Tag: 8.5 Verification Tag [Normal verification]
2680 * (endpoint, asoc, chunk)
2683 * (asoc, reply_msg, msg_up, timers, counters)
2685 * The return value is the disposition of the chunk.
2687 enum sctp_disposition
sctp_sf_do_9_2_shutdown(
2689 const struct sctp_endpoint
*ep
,
2690 const struct sctp_association
*asoc
,
2691 const union sctp_subtype type
,
2693 struct sctp_cmd_seq
*commands
)
2695 enum sctp_disposition disposition
;
2696 struct sctp_chunk
*chunk
= arg
;
2697 struct sctp_shutdownhdr
*sdh
;
2698 struct sctp_ulpevent
*ev
;
2701 if (!sctp_vtag_verify(chunk
, asoc
))
2702 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2704 /* Make sure that the SHUTDOWN chunk has a valid length. */
2705 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_shutdown_chunk
)))
2706 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2709 /* Convert the elaborate header. */
2710 sdh
= (struct sctp_shutdownhdr
*)chunk
->skb
->data
;
2711 skb_pull(chunk
->skb
, sizeof(*sdh
));
2712 chunk
->subh
.shutdown_hdr
= sdh
;
2713 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2715 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2716 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__
, ctsn
,
2717 asoc
->ctsn_ack_point
);
2719 return SCTP_DISPOSITION_DISCARD
;
2722 /* If Cumulative TSN Ack beyond the max tsn currently
2723 * send, terminating the association and respond to the
2724 * sender with an ABORT.
2726 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2727 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
2729 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2730 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2731 * inform the application that it should cease sending data.
2733 ev
= sctp_ulpevent_make_shutdown_event(asoc
, 0, GFP_ATOMIC
);
2735 disposition
= SCTP_DISPOSITION_NOMEM
;
2738 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
2740 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2741 * - enter the SHUTDOWN-RECEIVED state,
2742 * - stop accepting new data from its SCTP user
2744 * [This is implicit in the new state.]
2746 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2747 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED
));
2748 disposition
= SCTP_DISPOSITION_CONSUME
;
2750 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
2751 disposition
= sctp_sf_do_9_2_shutdown_ack(net
, ep
, asoc
, type
,
2755 if (SCTP_DISPOSITION_NOMEM
== disposition
)
2758 /* - verify, by checking the Cumulative TSN Ack field of the
2759 * chunk, that all its outstanding DATA chunks have been
2760 * received by the SHUTDOWN sender.
2762 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2763 SCTP_BE32(chunk
->subh
.shutdown_hdr
->cum_tsn_ack
));
2770 * sctp_sf_do_9_2_shut_ctsn
2772 * Once an endpoint has reached the SHUTDOWN-RECEIVED state,
2773 * it MUST NOT send a SHUTDOWN in response to a ULP request.
2774 * The Cumulative TSN Ack of the received SHUTDOWN chunk
2775 * MUST be processed.
2777 enum sctp_disposition
sctp_sf_do_9_2_shut_ctsn(
2779 const struct sctp_endpoint
*ep
,
2780 const struct sctp_association
*asoc
,
2781 const union sctp_subtype type
,
2783 struct sctp_cmd_seq
*commands
)
2785 struct sctp_chunk
*chunk
= arg
;
2786 struct sctp_shutdownhdr
*sdh
;
2789 if (!sctp_vtag_verify(chunk
, asoc
))
2790 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2792 /* Make sure that the SHUTDOWN chunk has a valid length. */
2793 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_shutdown_chunk
)))
2794 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2797 sdh
= (struct sctp_shutdownhdr
*)chunk
->skb
->data
;
2798 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2800 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2801 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__
, ctsn
,
2802 asoc
->ctsn_ack_point
);
2804 return SCTP_DISPOSITION_DISCARD
;
2807 /* If Cumulative TSN Ack beyond the max tsn currently
2808 * send, terminating the association and respond to the
2809 * sender with an ABORT.
2811 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2812 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
2814 /* verify, by checking the Cumulative TSN Ack field of the
2815 * chunk, that all its outstanding DATA chunks have been
2816 * received by the SHUTDOWN sender.
2818 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2819 SCTP_BE32(sdh
->cum_tsn_ack
));
2821 return SCTP_DISPOSITION_CONSUME
;
2825 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2826 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2827 * transport addresses (either in the IP addresses or in the INIT chunk)
2828 * that belong to this association, it should discard the INIT chunk and
2829 * retransmit the SHUTDOWN ACK chunk.
2831 enum sctp_disposition
sctp_sf_do_9_2_reshutack(
2833 const struct sctp_endpoint
*ep
,
2834 const struct sctp_association
*asoc
,
2835 const union sctp_subtype type
,
2837 struct sctp_cmd_seq
*commands
)
2839 struct sctp_chunk
*chunk
= arg
;
2840 struct sctp_chunk
*reply
;
2842 /* Make sure that the chunk has a valid length */
2843 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
2844 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2847 /* Since we are not going to really process this INIT, there
2848 * is no point in verifying chunk boundries. Just generate
2851 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
2855 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2856 * the T2-SHUTDOWN timer.
2858 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
2860 /* and restart the T2-shutdown timer. */
2861 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2862 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2864 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2866 return SCTP_DISPOSITION_CONSUME
;
2868 return SCTP_DISPOSITION_NOMEM
;
2872 * sctp_sf_do_ecn_cwr
2874 * Section: Appendix A: Explicit Congestion Notification
2878 * RFC 2481 details a specific bit for a sender to send in the header of
2879 * its next outbound TCP segment to indicate to its peer that it has
2880 * reduced its congestion window. This is termed the CWR bit. For
2881 * SCTP the same indication is made by including the CWR chunk.
2882 * This chunk contains one data element, i.e. the TSN number that
2883 * was sent in the ECNE chunk. This element represents the lowest
2884 * TSN number in the datagram that was originally marked with the
2887 * Verification Tag: 8.5 Verification Tag [Normal verification]
2889 * (endpoint, asoc, chunk)
2892 * (asoc, reply_msg, msg_up, timers, counters)
2894 * The return value is the disposition of the chunk.
2896 enum sctp_disposition
sctp_sf_do_ecn_cwr(struct net
*net
,
2897 const struct sctp_endpoint
*ep
,
2898 const struct sctp_association
*asoc
,
2899 const union sctp_subtype type
,
2901 struct sctp_cmd_seq
*commands
)
2903 struct sctp_chunk
*chunk
= arg
;
2904 struct sctp_cwrhdr
*cwr
;
2907 if (!sctp_vtag_verify(chunk
, asoc
))
2908 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2910 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_ecne_chunk
)))
2911 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2914 cwr
= (struct sctp_cwrhdr
*)chunk
->skb
->data
;
2915 skb_pull(chunk
->skb
, sizeof(*cwr
));
2917 lowest_tsn
= ntohl(cwr
->lowest_tsn
);
2919 /* Does this CWR ack the last sent congestion notification? */
2920 if (TSN_lte(asoc
->last_ecne_tsn
, lowest_tsn
)) {
2921 /* Stop sending ECNE. */
2922 sctp_add_cmd_sf(commands
,
2924 SCTP_U32(lowest_tsn
));
2926 return SCTP_DISPOSITION_CONSUME
;
2932 * Section: Appendix A: Explicit Congestion Notification
2936 * RFC 2481 details a specific bit for a receiver to send back in its
2937 * TCP acknowledgements to notify the sender of the Congestion
2938 * Experienced (CE) bit having arrived from the network. For SCTP this
2939 * same indication is made by including the ECNE chunk. This chunk
2940 * contains one data element, i.e. the lowest TSN associated with the IP
2941 * datagram marked with the CE bit.....
2943 * Verification Tag: 8.5 Verification Tag [Normal verification]
2945 * (endpoint, asoc, chunk)
2948 * (asoc, reply_msg, msg_up, timers, counters)
2950 * The return value is the disposition of the chunk.
2952 enum sctp_disposition
sctp_sf_do_ecne(struct net
*net
,
2953 const struct sctp_endpoint
*ep
,
2954 const struct sctp_association
*asoc
,
2955 const union sctp_subtype type
,
2956 void *arg
, struct sctp_cmd_seq
*commands
)
2958 struct sctp_chunk
*chunk
= arg
;
2959 struct sctp_ecnehdr
*ecne
;
2961 if (!sctp_vtag_verify(chunk
, asoc
))
2962 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2964 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_ecne_chunk
)))
2965 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2968 ecne
= (struct sctp_ecnehdr
*)chunk
->skb
->data
;
2969 skb_pull(chunk
->skb
, sizeof(*ecne
));
2971 /* If this is a newer ECNE than the last CWR packet we sent out */
2972 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_ECNE
,
2973 SCTP_U32(ntohl(ecne
->lowest_tsn
)));
2975 return SCTP_DISPOSITION_CONSUME
;
2979 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2981 * The SCTP endpoint MUST always acknowledge the reception of each valid
2984 * The guidelines on delayed acknowledgement algorithm specified in
2985 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2986 * acknowledgement SHOULD be generated for at least every second packet
2987 * (not every second DATA chunk) received, and SHOULD be generated within
2988 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2989 * situations it may be beneficial for an SCTP transmitter to be more
2990 * conservative than the algorithms detailed in this document allow.
2991 * However, an SCTP transmitter MUST NOT be more aggressive than the
2992 * following algorithms allow.
2994 * A SCTP receiver MUST NOT generate more than one SACK for every
2995 * incoming packet, other than to update the offered window as the
2996 * receiving application consumes new data.
2998 * Verification Tag: 8.5 Verification Tag [Normal verification]
3001 * (endpoint, asoc, chunk)
3004 * (asoc, reply_msg, msg_up, timers, counters)
3006 * The return value is the disposition of the chunk.
3008 enum sctp_disposition
sctp_sf_eat_data_6_2(struct net
*net
,
3009 const struct sctp_endpoint
*ep
,
3010 const struct sctp_association
*asoc
,
3011 const union sctp_subtype type
,
3013 struct sctp_cmd_seq
*commands
)
3015 union sctp_arg force
= SCTP_NOFORCE();
3016 struct sctp_chunk
*chunk
= arg
;
3019 if (!sctp_vtag_verify(chunk
, asoc
)) {
3020 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3022 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3025 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_data_chunk
)))
3026 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3029 error
= sctp_eat_data(asoc
, chunk
, commands
);
3031 case SCTP_IERROR_NO_ERROR
:
3033 case SCTP_IERROR_HIGH_TSN
:
3034 case SCTP_IERROR_BAD_STREAM
:
3035 SCTP_INC_STATS(net
, SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
3036 goto discard_noforce
;
3037 case SCTP_IERROR_DUP_TSN
:
3038 case SCTP_IERROR_IGNORE_TSN
:
3039 SCTP_INC_STATS(net
, SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
3041 case SCTP_IERROR_NO_DATA
:
3042 return SCTP_DISPOSITION_ABORT
;
3043 case SCTP_IERROR_PROTO_VIOLATION
:
3044 return sctp_sf_abort_violation(net
, ep
, asoc
, chunk
, commands
,
3045 (u8
*)chunk
->subh
.data_hdr
,
3046 sizeof(struct sctp_datahdr
));
3051 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_SACK_IMM
)
3052 force
= SCTP_FORCE();
3054 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
]) {
3055 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3056 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
3059 /* If this is the last chunk in a packet, we need to count it
3060 * toward sack generation. Note that we need to SACK every
3061 * OTHER packet containing data chunks, EVEN IF WE DISCARD
3062 * THEM. We elect to NOT generate SACK's if the chunk fails
3063 * the verification tag test.
3065 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
3067 * The SCTP endpoint MUST always acknowledge the reception of
3068 * each valid DATA chunk.
3070 * The guidelines on delayed acknowledgement algorithm
3071 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
3072 * Specifically, an acknowledgement SHOULD be generated for at
3073 * least every second packet (not every second DATA chunk)
3074 * received, and SHOULD be generated within 200 ms of the
3075 * arrival of any unacknowledged DATA chunk. In some
3076 * situations it may be beneficial for an SCTP transmitter to
3077 * be more conservative than the algorithms detailed in this
3078 * document allow. However, an SCTP transmitter MUST NOT be
3079 * more aggressive than the following algorithms allow.
3081 if (chunk
->end_of_packet
)
3082 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, force
);
3084 return SCTP_DISPOSITION_CONSUME
;
3087 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
3089 * When a packet arrives with duplicate DATA chunk(s) and with
3090 * no new DATA chunk(s), the endpoint MUST immediately send a
3091 * SACK with no delay. If a packet arrives with duplicate
3092 * DATA chunk(s) bundled with new DATA chunks, the endpoint
3093 * MAY immediately send a SACK. Normally receipt of duplicate
3094 * DATA chunks will occur when the original SACK chunk was lost
3095 * and the peer's RTO has expired. The duplicate TSN number(s)
3096 * SHOULD be reported in the SACK as duplicate.
3098 /* In our case, we split the MAY SACK advice up whether or not
3099 * the last chunk is a duplicate.'
3101 if (chunk
->end_of_packet
)
3102 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3103 return SCTP_DISPOSITION_DISCARD
;
3106 if (chunk
->end_of_packet
)
3107 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, force
);
3109 return SCTP_DISPOSITION_DISCARD
;
3113 * sctp_sf_eat_data_fast_4_4
3116 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
3117 * DATA chunks without delay.
3119 * Verification Tag: 8.5 Verification Tag [Normal verification]
3121 * (endpoint, asoc, chunk)
3124 * (asoc, reply_msg, msg_up, timers, counters)
3126 * The return value is the disposition of the chunk.
3128 enum sctp_disposition
sctp_sf_eat_data_fast_4_4(
3130 const struct sctp_endpoint
*ep
,
3131 const struct sctp_association
*asoc
,
3132 const union sctp_subtype type
,
3134 struct sctp_cmd_seq
*commands
)
3136 struct sctp_chunk
*chunk
= arg
;
3139 if (!sctp_vtag_verify(chunk
, asoc
)) {
3140 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3142 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3145 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_data_chunk
)))
3146 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3149 error
= sctp_eat_data(asoc
, chunk
, commands
);
3151 case SCTP_IERROR_NO_ERROR
:
3152 case SCTP_IERROR_HIGH_TSN
:
3153 case SCTP_IERROR_DUP_TSN
:
3154 case SCTP_IERROR_IGNORE_TSN
:
3155 case SCTP_IERROR_BAD_STREAM
:
3157 case SCTP_IERROR_NO_DATA
:
3158 return SCTP_DISPOSITION_ABORT
;
3159 case SCTP_IERROR_PROTO_VIOLATION
:
3160 return sctp_sf_abort_violation(net
, ep
, asoc
, chunk
, commands
,
3161 (u8
*)chunk
->subh
.data_hdr
,
3162 sizeof(struct sctp_datahdr
));
3167 /* Go a head and force a SACK, since we are shutting down. */
3169 /* Implementor's Guide.
3171 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3172 * respond to each received packet containing one or more DATA chunk(s)
3173 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3175 if (chunk
->end_of_packet
) {
3176 /* We must delay the chunk creation since the cumulative
3177 * TSN has not been updated yet.
3179 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3180 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3181 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3182 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3185 return SCTP_DISPOSITION_CONSUME
;
3189 * Section: 6.2 Processing a Received SACK
3190 * D) Any time a SACK arrives, the endpoint performs the following:
3192 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
3193 * then drop the SACK. Since Cumulative TSN Ack is monotonically
3194 * increasing, a SACK whose Cumulative TSN Ack is less than the
3195 * Cumulative TSN Ack Point indicates an out-of-order SACK.
3197 * ii) Set rwnd equal to the newly received a_rwnd minus the number
3198 * of bytes still outstanding after processing the Cumulative TSN Ack
3199 * and the Gap Ack Blocks.
3201 * iii) If the SACK is missing a TSN that was previously
3202 * acknowledged via a Gap Ack Block (e.g., the data receiver
3203 * reneged on the data), then mark the corresponding DATA chunk
3204 * as available for retransmit: Mark it as missing for fast
3205 * retransmit as described in Section 7.2.4 and if no retransmit
3206 * timer is running for the destination address to which the DATA
3207 * chunk was originally transmitted, then T3-rtx is started for
3208 * that destination address.
3210 * Verification Tag: 8.5 Verification Tag [Normal verification]
3213 * (endpoint, asoc, chunk)
3216 * (asoc, reply_msg, msg_up, timers, counters)
3218 * The return value is the disposition of the chunk.
3220 enum sctp_disposition
sctp_sf_eat_sack_6_2(struct net
*net
,
3221 const struct sctp_endpoint
*ep
,
3222 const struct sctp_association
*asoc
,
3223 const union sctp_subtype type
,
3225 struct sctp_cmd_seq
*commands
)
3227 struct sctp_chunk
*chunk
= arg
;
3228 struct sctp_sackhdr
*sackh
;
3231 if (!sctp_vtag_verify(chunk
, asoc
))
3232 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3234 /* Make sure that the SACK chunk has a valid length. */
3235 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_sack_chunk
)))
3236 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3239 /* Pull the SACK chunk from the data buffer */
3240 sackh
= sctp_sm_pull_sack(chunk
);
3241 /* Was this a bogus SACK? */
3243 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3244 chunk
->subh
.sack_hdr
= sackh
;
3245 ctsn
= ntohl(sackh
->cum_tsn_ack
);
3247 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
3248 * Ack Point, then drop the SACK. Since Cumulative TSN
3249 * Ack is monotonically increasing, a SACK whose
3250 * Cumulative TSN Ack is less than the Cumulative TSN Ack
3251 * Point indicates an out-of-order SACK.
3253 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
3254 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__
, ctsn
,
3255 asoc
->ctsn_ack_point
);
3257 return SCTP_DISPOSITION_DISCARD
;
3260 /* If Cumulative TSN Ack beyond the max tsn currently
3261 * send, terminating the association and respond to the
3262 * sender with an ABORT.
3264 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
3265 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
3267 /* Return this SACK for further processing. */
3268 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_SACK
, SCTP_CHUNK(chunk
));
3270 /* Note: We do the rest of the work on the PROCESS_SACK
3273 return SCTP_DISPOSITION_CONSUME
;
3277 * Generate an ABORT in response to a packet.
3279 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
3281 * 8) The receiver should respond to the sender of the OOTB packet with
3282 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3283 * MUST fill in the Verification Tag field of the outbound packet
3284 * with the value found in the Verification Tag field of the OOTB
3285 * packet and set the T-bit in the Chunk Flags to indicate that the
3286 * Verification Tag is reflected. After sending this ABORT, the
3287 * receiver of the OOTB packet shall discard the OOTB packet and take
3288 * no further action.
3292 * The return value is the disposition of the chunk.
3294 static enum sctp_disposition
sctp_sf_tabort_8_4_8(
3296 const struct sctp_endpoint
*ep
,
3297 const struct sctp_association
*asoc
,
3298 const union sctp_subtype type
,
3300 struct sctp_cmd_seq
*commands
)
3302 struct sctp_packet
*packet
= NULL
;
3303 struct sctp_chunk
*chunk
= arg
;
3304 struct sctp_chunk
*abort
;
3306 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
3308 return SCTP_DISPOSITION_NOMEM
;
3310 /* Make an ABORT. The T bit will be set if the asoc
3313 abort
= sctp_make_abort(asoc
, chunk
, 0);
3315 sctp_ootb_pkt_free(packet
);
3316 return SCTP_DISPOSITION_NOMEM
;
3319 /* Reflect vtag if T-Bit is set */
3320 if (sctp_test_T_bit(abort
))
3321 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3323 /* Set the skb to the belonging sock for accounting. */
3324 abort
->skb
->sk
= ep
->base
.sk
;
3326 sctp_packet_append_chunk(packet
, abort
);
3328 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3329 SCTP_PACKET(packet
));
3331 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
3333 sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3334 return SCTP_DISPOSITION_CONSUME
;
3338 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
3339 * event as ULP notification for each cause included in the chunk.
3341 * API 5.3.1.3 - SCTP_REMOTE_ERROR
3343 * The return value is the disposition of the chunk.
3345 enum sctp_disposition
sctp_sf_operr_notify(struct net
*net
,
3346 const struct sctp_endpoint
*ep
,
3347 const struct sctp_association
*asoc
,
3348 const union sctp_subtype type
,
3350 struct sctp_cmd_seq
*commands
)
3352 struct sctp_chunk
*chunk
= arg
;
3353 struct sctp_errhdr
*err
;
3355 if (!sctp_vtag_verify(chunk
, asoc
))
3356 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3358 /* Make sure that the ERROR chunk has a valid length. */
3359 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_operr_chunk
)))
3360 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3362 sctp_walk_errors(err
, chunk
->chunk_hdr
);
3363 if ((void *)err
!= (void *)chunk
->chunk_end
)
3364 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3365 (void *)err
, commands
);
3367 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_OPERR
,
3370 return SCTP_DISPOSITION_CONSUME
;
3374 * Process an inbound SHUTDOWN ACK.
3377 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3378 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3379 * peer, and remove all record of the association.
3381 * The return value is the disposition.
3383 enum sctp_disposition
sctp_sf_do_9_2_final(struct net
*net
,
3384 const struct sctp_endpoint
*ep
,
3385 const struct sctp_association
*asoc
,
3386 const union sctp_subtype type
,
3388 struct sctp_cmd_seq
*commands
)
3390 struct sctp_chunk
*chunk
= arg
;
3391 struct sctp_chunk
*reply
;
3392 struct sctp_ulpevent
*ev
;
3394 if (!sctp_vtag_verify(chunk
, asoc
))
3395 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3397 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3398 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
3399 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3401 /* 10.2 H) SHUTDOWN COMPLETE notification
3403 * When SCTP completes the shutdown procedures (section 9.2) this
3404 * notification is passed to the upper layer.
3406 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
3407 0, 0, 0, NULL
, GFP_ATOMIC
);
3411 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3412 reply
= sctp_make_shutdown_complete(asoc
, chunk
);
3416 /* Do all the commands now (after allocation), so that we
3417 * have consistent state if memory allocation failes
3419 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
3421 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3422 * stop the T2-shutdown timer,
3424 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3425 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3427 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3428 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
3430 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
3431 SCTP_STATE(SCTP_STATE_CLOSED
));
3432 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
3433 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3434 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
3436 /* ...and remove all record of the association. */
3437 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
3438 return SCTP_DISPOSITION_DELETE_TCB
;
3441 sctp_ulpevent_free(ev
);
3443 return SCTP_DISPOSITION_NOMEM
;
3447 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3449 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3450 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3451 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3452 * packet must fill in the Verification Tag field of the outbound
3453 * packet with the Verification Tag received in the SHUTDOWN ACK and
3454 * set the T-bit in the Chunk Flags to indicate that the Verification
3457 * 8) The receiver should respond to the sender of the OOTB packet with
3458 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3459 * MUST fill in the Verification Tag field of the outbound packet
3460 * with the value found in the Verification Tag field of the OOTB
3461 * packet and set the T-bit in the Chunk Flags to indicate that the
3462 * Verification Tag is reflected. After sending this ABORT, the
3463 * receiver of the OOTB packet shall discard the OOTB packet and take
3464 * no further action.
3466 enum sctp_disposition
sctp_sf_ootb(struct net
*net
,
3467 const struct sctp_endpoint
*ep
,
3468 const struct sctp_association
*asoc
,
3469 const union sctp_subtype type
,
3470 void *arg
, struct sctp_cmd_seq
*commands
)
3472 struct sctp_chunk
*chunk
= arg
;
3473 struct sk_buff
*skb
= chunk
->skb
;
3474 struct sctp_chunkhdr
*ch
;
3475 struct sctp_errhdr
*err
;
3476 int ootb_cookie_ack
= 0;
3477 int ootb_shut_ack
= 0;
3480 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
3482 ch
= (struct sctp_chunkhdr
*)chunk
->chunk_hdr
;
3484 /* Report violation if the chunk is less then minimal */
3485 if (ntohs(ch
->length
) < sizeof(*ch
))
3486 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3489 /* Report violation if chunk len overflows */
3490 ch_end
= ((__u8
*)ch
) + SCTP_PAD4(ntohs(ch
->length
));
3491 if (ch_end
> skb_tail_pointer(skb
))
3492 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3495 /* Now that we know we at least have a chunk header,
3496 * do things that are type appropriate.
3498 if (SCTP_CID_SHUTDOWN_ACK
== ch
->type
)
3501 /* RFC 2960, Section 3.3.7
3502 * Moreover, under any circumstances, an endpoint that
3503 * receives an ABORT MUST NOT respond to that ABORT by
3504 * sending an ABORT of its own.
3506 if (SCTP_CID_ABORT
== ch
->type
)
3507 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3509 /* RFC 8.4, 7) If the packet contains a "Stale cookie" ERROR
3510 * or a COOKIE ACK the SCTP Packet should be silently
3514 if (SCTP_CID_COOKIE_ACK
== ch
->type
)
3515 ootb_cookie_ack
= 1;
3517 if (SCTP_CID_ERROR
== ch
->type
) {
3518 sctp_walk_errors(err
, ch
) {
3519 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
) {
3520 ootb_cookie_ack
= 1;
3526 ch
= (struct sctp_chunkhdr
*)ch_end
;
3527 } while (ch_end
< skb_tail_pointer(skb
));
3530 return sctp_sf_shut_8_4_5(net
, ep
, asoc
, type
, arg
, commands
);
3531 else if (ootb_cookie_ack
)
3532 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3534 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
3538 * Handle an "Out of the blue" SHUTDOWN ACK.
3540 * Section: 8.4 5, sctpimpguide 2.41.
3542 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3543 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3544 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3545 * packet must fill in the Verification Tag field of the outbound
3546 * packet with the Verification Tag received in the SHUTDOWN ACK and
3547 * set the T-bit in the Chunk Flags to indicate that the Verification
3551 * (endpoint, asoc, type, arg, commands)
3554 * (enum sctp_disposition)
3556 * The return value is the disposition of the chunk.
3558 static enum sctp_disposition
sctp_sf_shut_8_4_5(
3560 const struct sctp_endpoint
*ep
,
3561 const struct sctp_association
*asoc
,
3562 const union sctp_subtype type
,
3564 struct sctp_cmd_seq
*commands
)
3566 struct sctp_packet
*packet
= NULL
;
3567 struct sctp_chunk
*chunk
= arg
;
3568 struct sctp_chunk
*shut
;
3570 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
3572 return SCTP_DISPOSITION_NOMEM
;
3574 /* Make an SHUTDOWN_COMPLETE.
3575 * The T bit will be set if the asoc is NULL.
3577 shut
= sctp_make_shutdown_complete(asoc
, chunk
);
3579 sctp_ootb_pkt_free(packet
);
3580 return SCTP_DISPOSITION_NOMEM
;
3583 /* Reflect vtag if T-Bit is set */
3584 if (sctp_test_T_bit(shut
))
3585 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3587 /* Set the skb to the belonging sock for accounting. */
3588 shut
->skb
->sk
= ep
->base
.sk
;
3590 sctp_packet_append_chunk(packet
, shut
);
3592 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3593 SCTP_PACKET(packet
));
3595 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
3597 /* If the chunk length is invalid, we don't want to process
3598 * the reset of the packet.
3600 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
3601 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3603 /* We need to discard the rest of the packet to prevent
3604 * potential bomming attacks from additional bundled chunks.
3605 * This is documented in SCTP Threats ID.
3607 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3611 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3613 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3614 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3615 * procedures in section 8.4 SHOULD be followed, in other words it
3616 * should be treated as an Out Of The Blue packet.
3617 * [This means that we do NOT check the Verification Tag on these
3621 enum sctp_disposition
sctp_sf_do_8_5_1_E_sa(struct net
*net
,
3622 const struct sctp_endpoint
*ep
,
3623 const struct sctp_association
*asoc
,
3624 const union sctp_subtype type
,
3626 struct sctp_cmd_seq
*commands
)
3628 struct sctp_chunk
*chunk
= arg
;
3630 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3631 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
3632 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3635 /* Although we do have an association in this case, it corresponds
3636 * to a restarted association. So the packet is treated as an OOTB
3637 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3638 * called with a NULL association.
3640 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
3642 return sctp_sf_shut_8_4_5(net
, ep
, NULL
, type
, arg
, commands
);
3645 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3646 enum sctp_disposition
sctp_sf_do_asconf(struct net
*net
,
3647 const struct sctp_endpoint
*ep
,
3648 const struct sctp_association
*asoc
,
3649 const union sctp_subtype type
,
3651 struct sctp_cmd_seq
*commands
)
3653 struct sctp_paramhdr
*err_param
= NULL
;
3654 struct sctp_chunk
*asconf_ack
= NULL
;
3655 struct sctp_chunk
*chunk
= arg
;
3656 struct sctp_addiphdr
*hdr
;
3659 if (!sctp_vtag_verify(chunk
, asoc
)) {
3660 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3662 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3665 /* ADD-IP: Section 4.1.1
3666 * This chunk MUST be sent in an authenticated way by using
3667 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3668 * is received unauthenticated it MUST be silently discarded as
3669 * described in [I-D.ietf-tsvwg-sctp-auth].
3671 if (!net
->sctp
.addip_noauth
&& !chunk
->auth
)
3672 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
,
3675 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3676 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_addip_chunk
)))
3677 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3680 hdr
= (struct sctp_addiphdr
*)chunk
->skb
->data
;
3681 serial
= ntohl(hdr
->serial
);
3683 /* Verify the ASCONF chunk before processing it. */
3684 if (!sctp_verify_asconf(asoc
, chunk
, true, &err_param
))
3685 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3686 (void *)err_param
, commands
);
3688 /* ADDIP 5.2 E1) Compare the value of the serial number to the value
3689 * the endpoint stored in a new association variable
3690 * 'Peer-Serial-Number'.
3692 if (serial
== asoc
->peer
.addip_serial
+ 1) {
3693 /* If this is the first instance of ASCONF in the packet,
3694 * we can clean our old ASCONF-ACKs.
3696 if (!chunk
->has_asconf
)
3697 sctp_assoc_clean_asconf_ack_cache(asoc
);
3699 /* ADDIP 5.2 E4) When the Sequence Number matches the next one
3700 * expected, process the ASCONF as described below and after
3701 * processing the ASCONF Chunk, append an ASCONF-ACK Chunk to
3702 * the response packet and cache a copy of it (in the event it
3703 * later needs to be retransmitted).
3705 * Essentially, do V1-V5.
3707 asconf_ack
= sctp_process_asconf((struct sctp_association
*)
3710 return SCTP_DISPOSITION_NOMEM
;
3711 } else if (serial
< asoc
->peer
.addip_serial
+ 1) {
3713 * If the value found in the Sequence Number is less than the
3714 * ('Peer- Sequence-Number' + 1), simply skip to the next
3715 * ASCONF, and include in the outbound response packet
3716 * any previously cached ASCONF-ACK response that was
3717 * sent and saved that matches the Sequence Number of the
3718 * ASCONF. Note: It is possible that no cached ASCONF-ACK
3719 * Chunk exists. This will occur when an older ASCONF
3720 * arrives out of order. In such a case, the receiver
3721 * should skip the ASCONF Chunk and not include ASCONF-ACK
3722 * Chunk for that chunk.
3724 asconf_ack
= sctp_assoc_lookup_asconf_ack(asoc
, hdr
->serial
);
3726 return SCTP_DISPOSITION_DISCARD
;
3728 /* Reset the transport so that we select the correct one
3729 * this time around. This is to make sure that we don't
3730 * accidentally use a stale transport that's been removed.
3732 asconf_ack
->transport
= NULL
;
3734 /* ADDIP 5.2 E5) Otherwise, the ASCONF Chunk is discarded since
3735 * it must be either a stale packet or from an attacker.
3737 return SCTP_DISPOSITION_DISCARD
;
3740 /* ADDIP 5.2 E6) The destination address of the SCTP packet
3741 * containing the ASCONF-ACK Chunks MUST be the source address of
3742 * the SCTP packet that held the ASCONF Chunks.
3744 * To do this properly, we'll set the destination address of the chunk
3745 * and at the transmit time, will try look up the transport to use.
3746 * Since ASCONFs may be bundled, the correct transport may not be
3747 * created until we process the entire packet, thus this workaround.
3749 asconf_ack
->dest
= chunk
->source
;
3750 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(asconf_ack
));
3751 if (asoc
->new_transport
) {
3752 sctp_sf_heartbeat(ep
, asoc
, type
, asoc
->new_transport
, commands
);
3753 ((struct sctp_association
*)asoc
)->new_transport
= NULL
;
3756 return SCTP_DISPOSITION_CONSUME
;
3760 * ADDIP Section 4.3 General rules for address manipulation
3761 * When building TLV parameters for the ASCONF Chunk that will add or
3762 * delete IP addresses the D0 to D13 rules should be applied:
3764 enum sctp_disposition
sctp_sf_do_asconf_ack(struct net
*net
,
3765 const struct sctp_endpoint
*ep
,
3766 const struct sctp_association
*asoc
,
3767 const union sctp_subtype type
,
3769 struct sctp_cmd_seq
*commands
)
3771 struct sctp_chunk
*last_asconf
= asoc
->addip_last_asconf
;
3772 struct sctp_paramhdr
*err_param
= NULL
;
3773 struct sctp_chunk
*asconf_ack
= arg
;
3774 struct sctp_addiphdr
*addip_hdr
;
3775 __u32 sent_serial
, rcvd_serial
;
3776 struct sctp_chunk
*abort
;
3778 if (!sctp_vtag_verify(asconf_ack
, asoc
)) {
3779 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3781 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3784 /* ADD-IP, Section 4.1.2:
3785 * This chunk MUST be sent in an authenticated way by using
3786 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3787 * is received unauthenticated it MUST be silently discarded as
3788 * described in [I-D.ietf-tsvwg-sctp-auth].
3790 if (!net
->sctp
.addip_noauth
&& !asconf_ack
->auth
)
3791 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
,
3794 /* Make sure that the ADDIP chunk has a valid length. */
3795 if (!sctp_chunk_length_valid(asconf_ack
,
3796 sizeof(struct sctp_addip_chunk
)))
3797 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3800 addip_hdr
= (struct sctp_addiphdr
*)asconf_ack
->skb
->data
;
3801 rcvd_serial
= ntohl(addip_hdr
->serial
);
3803 /* Verify the ASCONF-ACK chunk before processing it. */
3804 if (!sctp_verify_asconf(asoc
, asconf_ack
, false, &err_param
))
3805 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3806 (void *)err_param
, commands
);
3809 addip_hdr
= (struct sctp_addiphdr
*)last_asconf
->subh
.addip_hdr
;
3810 sent_serial
= ntohl(addip_hdr
->serial
);
3812 sent_serial
= asoc
->addip_serial
- 1;
3815 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3816 * equal to the next serial number to be used but no ASCONF chunk is
3817 * outstanding the endpoint MUST ABORT the association. Note that a
3818 * sequence number is greater than if it is no more than 2^^31-1
3819 * larger than the current sequence number (using serial arithmetic).
3821 if (ADDIP_SERIAL_gte(rcvd_serial
, sent_serial
+ 1) &&
3822 !(asoc
->addip_last_asconf
)) {
3823 abort
= sctp_make_abort(asoc
, asconf_ack
,
3824 sizeof(struct sctp_errhdr
));
3826 sctp_init_cause(abort
, SCTP_ERROR_ASCONF_ACK
, 0);
3827 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3830 /* We are going to ABORT, so we might as well stop
3831 * processing the rest of the chunks in the packet.
3833 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3834 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3835 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
3836 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3837 SCTP_ERROR(ECONNABORTED
));
3838 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3839 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3840 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
3841 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3842 return SCTP_DISPOSITION_ABORT
;
3845 if ((rcvd_serial
== sent_serial
) && asoc
->addip_last_asconf
) {
3846 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3847 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3849 if (!sctp_process_asconf_ack((struct sctp_association
*)asoc
,
3851 /* Successfully processed ASCONF_ACK. We can
3852 * release the next asconf if we have one.
3854 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_NEXT_ASCONF
,
3856 return SCTP_DISPOSITION_CONSUME
;
3859 abort
= sctp_make_abort(asoc
, asconf_ack
,
3860 sizeof(struct sctp_errhdr
));
3862 sctp_init_cause(abort
, SCTP_ERROR_RSRC_LOW
, 0);
3863 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3866 /* We are going to ABORT, so we might as well stop
3867 * processing the rest of the chunks in the packet.
3869 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
3870 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3871 SCTP_ERROR(ECONNABORTED
));
3872 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3873 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3874 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
3875 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3876 return SCTP_DISPOSITION_ABORT
;
3879 return SCTP_DISPOSITION_DISCARD
;
3882 /* RE-CONFIG Section 5.2 Upon reception of an RECONF Chunk. */
3883 enum sctp_disposition
sctp_sf_do_reconf(struct net
*net
,
3884 const struct sctp_endpoint
*ep
,
3885 const struct sctp_association
*asoc
,
3886 const union sctp_subtype type
,
3888 struct sctp_cmd_seq
*commands
)
3890 struct sctp_paramhdr
*err_param
= NULL
;
3891 struct sctp_chunk
*chunk
= arg
;
3892 struct sctp_reconf_chunk
*hdr
;
3893 union sctp_params param
;
3895 if (!sctp_vtag_verify(chunk
, asoc
)) {
3896 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3898 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3901 /* Make sure that the RECONF chunk has a valid length. */
3902 if (!sctp_chunk_length_valid(chunk
, sizeof(*hdr
)))
3903 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3906 if (!sctp_verify_reconf(asoc
, chunk
, &err_param
))
3907 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3908 (void *)err_param
, commands
);
3910 hdr
= (struct sctp_reconf_chunk
*)chunk
->chunk_hdr
;
3911 sctp_walk_params(param
, hdr
, params
) {
3912 struct sctp_chunk
*reply
= NULL
;
3913 struct sctp_ulpevent
*ev
= NULL
;
3915 if (param
.p
->type
== SCTP_PARAM_RESET_OUT_REQUEST
)
3916 reply
= sctp_process_strreset_outreq(
3917 (struct sctp_association
*)asoc
, param
, &ev
);
3918 else if (param
.p
->type
== SCTP_PARAM_RESET_IN_REQUEST
)
3919 reply
= sctp_process_strreset_inreq(
3920 (struct sctp_association
*)asoc
, param
, &ev
);
3921 else if (param
.p
->type
== SCTP_PARAM_RESET_TSN_REQUEST
)
3922 reply
= sctp_process_strreset_tsnreq(
3923 (struct sctp_association
*)asoc
, param
, &ev
);
3924 else if (param
.p
->type
== SCTP_PARAM_RESET_ADD_OUT_STREAMS
)
3925 reply
= sctp_process_strreset_addstrm_out(
3926 (struct sctp_association
*)asoc
, param
, &ev
);
3927 else if (param
.p
->type
== SCTP_PARAM_RESET_ADD_IN_STREAMS
)
3928 reply
= sctp_process_strreset_addstrm_in(
3929 (struct sctp_association
*)asoc
, param
, &ev
);
3930 else if (param
.p
->type
== SCTP_PARAM_RESET_RESPONSE
)
3931 reply
= sctp_process_strreset_resp(
3932 (struct sctp_association
*)asoc
, param
, &ev
);
3935 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
3939 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3943 return SCTP_DISPOSITION_CONSUME
;
3947 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3949 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3950 * its cumulative TSN point to the value carried in the FORWARD TSN
3951 * chunk, and then MUST further advance its cumulative TSN point locally
3953 * After the above processing, the data receiver MUST stop reporting any
3954 * missing TSNs earlier than or equal to the new cumulative TSN point.
3956 * Verification Tag: 8.5 Verification Tag [Normal verification]
3958 * The return value is the disposition of the chunk.
3960 enum sctp_disposition
sctp_sf_eat_fwd_tsn(struct net
*net
,
3961 const struct sctp_endpoint
*ep
,
3962 const struct sctp_association
*asoc
,
3963 const union sctp_subtype type
,
3965 struct sctp_cmd_seq
*commands
)
3967 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3968 struct sctp_chunk
*chunk
= arg
;
3969 struct sctp_fwdtsn_skip
*skip
;
3973 if (!sctp_vtag_verify(chunk
, asoc
)) {
3974 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3976 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3979 if (!asoc
->peer
.prsctp_capable
)
3980 return sctp_sf_unk_chunk(net
, ep
, asoc
, type
, arg
, commands
);
3982 /* Make sure that the FORWARD_TSN chunk has valid length. */
3983 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3984 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3987 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3988 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3989 len
= ntohs(chunk
->chunk_hdr
->length
);
3990 len
-= sizeof(struct sctp_chunkhdr
);
3991 skb_pull(chunk
->skb
, len
);
3993 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3994 pr_debug("%s: TSN 0x%x\n", __func__
, tsn
);
3996 /* The TSN is too high--silently discard the chunk and count on it
3997 * getting retransmitted later.
3999 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
4000 goto discard_noforce
;
4002 /* Silently discard the chunk if stream-id is not valid */
4003 sctp_walk_fwdtsn(skip
, chunk
) {
4004 if (ntohs(skip
->stream
) >= asoc
->stream
.incnt
)
4005 goto discard_noforce
;
4008 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
4009 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
4010 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
4013 /* Count this as receiving DATA. */
4014 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
]) {
4015 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
4016 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
4019 /* FIXME: For now send a SACK, but DATA processing may
4022 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
4024 return SCTP_DISPOSITION_CONSUME
;
4027 return SCTP_DISPOSITION_DISCARD
;
4030 enum sctp_disposition
sctp_sf_eat_fwd_tsn_fast(
4032 const struct sctp_endpoint
*ep
,
4033 const struct sctp_association
*asoc
,
4034 const union sctp_subtype type
,
4036 struct sctp_cmd_seq
*commands
)
4038 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
4039 struct sctp_chunk
*chunk
= arg
;
4040 struct sctp_fwdtsn_skip
*skip
;
4044 if (!sctp_vtag_verify(chunk
, asoc
)) {
4045 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
4047 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4050 if (!asoc
->peer
.prsctp_capable
)
4051 return sctp_sf_unk_chunk(net
, ep
, asoc
, type
, arg
, commands
);
4053 /* Make sure that the FORWARD_TSN chunk has a valid length. */
4054 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
4055 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4058 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
4059 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
4060 len
= ntohs(chunk
->chunk_hdr
->length
);
4061 len
-= sizeof(struct sctp_chunkhdr
);
4062 skb_pull(chunk
->skb
, len
);
4064 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
4065 pr_debug("%s: TSN 0x%x\n", __func__
, tsn
);
4067 /* The TSN is too high--silently discard the chunk and count on it
4068 * getting retransmitted later.
4070 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
4073 /* Silently discard the chunk if stream-id is not valid */
4074 sctp_walk_fwdtsn(skip
, chunk
) {
4075 if (ntohs(skip
->stream
) >= asoc
->stream
.incnt
)
4079 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
4080 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
4081 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
4084 /* Go a head and force a SACK, since we are shutting down. */
4086 /* Implementor's Guide.
4088 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
4089 * respond to each received packet containing one or more DATA chunk(s)
4090 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
4092 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
4093 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
4094 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
4095 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
4097 return SCTP_DISPOSITION_CONSUME
;
4101 * SCTP-AUTH Section 6.3 Receiving authenticated chukns
4103 * The receiver MUST use the HMAC algorithm indicated in the HMAC
4104 * Identifier field. If this algorithm was not specified by the
4105 * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk
4106 * during association setup, the AUTH chunk and all chunks after it MUST
4107 * be discarded and an ERROR chunk SHOULD be sent with the error cause
4108 * defined in Section 4.1.
4110 * If an endpoint with no shared key receives a Shared Key Identifier
4111 * other than 0, it MUST silently discard all authenticated chunks. If
4112 * the endpoint has at least one endpoint pair shared key for the peer,
4113 * it MUST use the key specified by the Shared Key Identifier if a
4114 * key has been configured for that Shared Key Identifier. If no
4115 * endpoint pair shared key has been configured for that Shared Key
4116 * Identifier, all authenticated chunks MUST be silently discarded.
4118 * Verification Tag: 8.5 Verification Tag [Normal verification]
4120 * The return value is the disposition of the chunk.
4122 static enum sctp_ierror
sctp_sf_authenticate(
4123 const struct sctp_association
*asoc
,
4124 struct sctp_chunk
*chunk
)
4126 struct sctp_authhdr
*auth_hdr
;
4127 __u8
*save_digest
, *digest
;
4128 struct sctp_hmac
*hmac
;
4129 unsigned int sig_len
;
4132 /* Pull in the auth header, so we can do some more verification */
4133 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
4134 chunk
->subh
.auth_hdr
= auth_hdr
;
4135 skb_pull(chunk
->skb
, sizeof(*auth_hdr
));
4137 /* Make sure that we support the HMAC algorithm from the auth
4140 if (!sctp_auth_asoc_verify_hmac_id(asoc
, auth_hdr
->hmac_id
))
4141 return SCTP_IERROR_AUTH_BAD_HMAC
;
4143 /* Make sure that the provided shared key identifier has been
4146 key_id
= ntohs(auth_hdr
->shkey_id
);
4147 if (key_id
!= asoc
->active_key_id
&& !sctp_auth_get_shkey(asoc
, key_id
))
4148 return SCTP_IERROR_AUTH_BAD_KEYID
;
4151 /* Make sure that the length of the signature matches what
4154 sig_len
= ntohs(chunk
->chunk_hdr
->length
) -
4155 sizeof(struct sctp_auth_chunk
);
4156 hmac
= sctp_auth_get_hmac(ntohs(auth_hdr
->hmac_id
));
4157 if (sig_len
!= hmac
->hmac_len
)
4158 return SCTP_IERROR_PROTO_VIOLATION
;
4160 /* Now that we've done validation checks, we can compute and
4161 * verify the hmac. The steps involved are:
4162 * 1. Save the digest from the chunk.
4163 * 2. Zero out the digest in the chunk.
4164 * 3. Compute the new digest
4165 * 4. Compare saved and new digests.
4167 digest
= auth_hdr
->hmac
;
4168 skb_pull(chunk
->skb
, sig_len
);
4170 save_digest
= kmemdup(digest
, sig_len
, GFP_ATOMIC
);
4174 memset(digest
, 0, sig_len
);
4176 sctp_auth_calculate_hmac(asoc
, chunk
->skb
,
4177 (struct sctp_auth_chunk
*)chunk
->chunk_hdr
,
4180 /* Discard the packet if the digests do not match */
4181 if (memcmp(save_digest
, digest
, sig_len
)) {
4183 return SCTP_IERROR_BAD_SIG
;
4189 return SCTP_IERROR_NO_ERROR
;
4191 return SCTP_IERROR_NOMEM
;
4194 enum sctp_disposition
sctp_sf_eat_auth(struct net
*net
,
4195 const struct sctp_endpoint
*ep
,
4196 const struct sctp_association
*asoc
,
4197 const union sctp_subtype type
,
4198 void *arg
, struct sctp_cmd_seq
*commands
)
4200 struct sctp_chunk
*chunk
= arg
;
4201 struct sctp_authhdr
*auth_hdr
;
4202 struct sctp_chunk
*err_chunk
;
4203 enum sctp_ierror error
;
4205 /* Make sure that the peer has AUTH capable */
4206 if (!asoc
->peer
.auth_capable
)
4207 return sctp_sf_unk_chunk(net
, ep
, asoc
, type
, arg
, commands
);
4209 if (!sctp_vtag_verify(chunk
, asoc
)) {
4210 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
4212 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4215 /* Make sure that the AUTH chunk has valid length. */
4216 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_auth_chunk
)))
4217 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4220 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
4221 error
= sctp_sf_authenticate(asoc
, chunk
);
4223 case SCTP_IERROR_AUTH_BAD_HMAC
:
4224 /* Generate the ERROR chunk and discard the rest
4227 err_chunk
= sctp_make_op_error(asoc
, chunk
,
4228 SCTP_ERROR_UNSUP_HMAC
,
4232 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4233 SCTP_CHUNK(err_chunk
));
4236 case SCTP_IERROR_AUTH_BAD_KEYID
:
4237 case SCTP_IERROR_BAD_SIG
:
4238 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4240 case SCTP_IERROR_PROTO_VIOLATION
:
4241 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4244 case SCTP_IERROR_NOMEM
:
4245 return SCTP_DISPOSITION_NOMEM
;
4247 default: /* Prevent gcc warnings */
4251 if (asoc
->active_key_id
!= ntohs(auth_hdr
->shkey_id
)) {
4252 struct sctp_ulpevent
*ev
;
4254 ev
= sctp_ulpevent_make_authkey(asoc
, ntohs(auth_hdr
->shkey_id
),
4255 SCTP_AUTH_NEWKEY
, GFP_ATOMIC
);
4260 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
4264 return SCTP_DISPOSITION_CONSUME
;
4268 * Process an unknown chunk.
4270 * Section: 3.2. Also, 2.1 in the implementor's guide.
4272 * Chunk Types are encoded such that the highest-order two bits specify
4273 * the action that must be taken if the processing endpoint does not
4274 * recognize the Chunk Type.
4276 * 00 - Stop processing this SCTP packet and discard it, do not process
4277 * any further chunks within it.
4279 * 01 - Stop processing this SCTP packet and discard it, do not process
4280 * any further chunks within it, and report the unrecognized
4281 * chunk in an 'Unrecognized Chunk Type'.
4283 * 10 - Skip this chunk and continue processing.
4285 * 11 - Skip this chunk and continue processing, but report in an ERROR
4286 * Chunk using the 'Unrecognized Chunk Type' cause of error.
4288 * The return value is the disposition of the chunk.
4290 enum sctp_disposition
sctp_sf_unk_chunk(struct net
*net
,
4291 const struct sctp_endpoint
*ep
,
4292 const struct sctp_association
*asoc
,
4293 const union sctp_subtype type
,
4295 struct sctp_cmd_seq
*commands
)
4297 struct sctp_chunk
*unk_chunk
= arg
;
4298 struct sctp_chunk
*err_chunk
;
4299 struct sctp_chunkhdr
*hdr
;
4301 pr_debug("%s: processing unknown chunk id:%d\n", __func__
, type
.chunk
);
4303 if (!sctp_vtag_verify(unk_chunk
, asoc
))
4304 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4306 /* Make sure that the chunk has a valid length.
4307 * Since we don't know the chunk type, we use a general
4308 * chunkhdr structure to make a comparison.
4310 if (!sctp_chunk_length_valid(unk_chunk
, sizeof(*hdr
)))
4311 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4314 switch (type
.chunk
& SCTP_CID_ACTION_MASK
) {
4315 case SCTP_CID_ACTION_DISCARD
:
4316 /* Discard the packet. */
4317 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4318 case SCTP_CID_ACTION_DISCARD_ERR
:
4319 /* Generate an ERROR chunk as response. */
4320 hdr
= unk_chunk
->chunk_hdr
;
4321 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4322 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4323 SCTP_PAD4(ntohs(hdr
->length
)),
4326 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4327 SCTP_CHUNK(err_chunk
));
4330 /* Discard the packet. */
4331 sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4332 return SCTP_DISPOSITION_CONSUME
;
4333 case SCTP_CID_ACTION_SKIP
:
4334 /* Skip the chunk. */
4335 return SCTP_DISPOSITION_DISCARD
;
4336 case SCTP_CID_ACTION_SKIP_ERR
:
4337 /* Generate an ERROR chunk as response. */
4338 hdr
= unk_chunk
->chunk_hdr
;
4339 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4340 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4341 SCTP_PAD4(ntohs(hdr
->length
)),
4344 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4345 SCTP_CHUNK(err_chunk
));
4347 /* Skip the chunk. */
4348 return SCTP_DISPOSITION_CONSUME
;
4353 return SCTP_DISPOSITION_DISCARD
;
4357 * Discard the chunk.
4359 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
4360 * [Too numerous to mention...]
4361 * Verification Tag: No verification needed.
4363 * (endpoint, asoc, chunk)
4366 * (asoc, reply_msg, msg_up, timers, counters)
4368 * The return value is the disposition of the chunk.
4370 enum sctp_disposition
sctp_sf_discard_chunk(struct net
*net
,
4371 const struct sctp_endpoint
*ep
,
4372 const struct sctp_association
*asoc
,
4373 const union sctp_subtype type
,
4375 struct sctp_cmd_seq
*commands
)
4377 struct sctp_chunk
*chunk
= arg
;
4379 /* Make sure that the chunk has a valid length.
4380 * Since we don't know the chunk type, we use a general
4381 * chunkhdr structure to make a comparison.
4383 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
4384 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4387 pr_debug("%s: chunk:%d is discarded\n", __func__
, type
.chunk
);
4389 return SCTP_DISPOSITION_DISCARD
;
4393 * Discard the whole packet.
4397 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
4398 * silently discard the OOTB packet and take no further action.
4400 * Verification Tag: No verification necessary
4403 * (endpoint, asoc, chunk)
4406 * (asoc, reply_msg, msg_up, timers, counters)
4408 * The return value is the disposition of the chunk.
4410 enum sctp_disposition
sctp_sf_pdiscard(struct net
*net
,
4411 const struct sctp_endpoint
*ep
,
4412 const struct sctp_association
*asoc
,
4413 const union sctp_subtype type
,
4414 void *arg
, struct sctp_cmd_seq
*commands
)
4416 SCTP_INC_STATS(net
, SCTP_MIB_IN_PKT_DISCARDS
);
4417 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
4419 return SCTP_DISPOSITION_CONSUME
;
4424 * The other end is violating protocol.
4426 * Section: Not specified
4427 * Verification Tag: Not specified
4429 * (endpoint, asoc, chunk)
4432 * (asoc, reply_msg, msg_up, timers, counters)
4434 * We simply tag the chunk as a violation. The state machine will log
4435 * the violation and continue.
4437 enum sctp_disposition
sctp_sf_violation(struct net
*net
,
4438 const struct sctp_endpoint
*ep
,
4439 const struct sctp_association
*asoc
,
4440 const union sctp_subtype type
,
4442 struct sctp_cmd_seq
*commands
)
4444 struct sctp_chunk
*chunk
= arg
;
4446 /* Make sure that the chunk has a valid length. */
4447 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
4448 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4451 return SCTP_DISPOSITION_VIOLATION
;
4455 * Common function to handle a protocol violation.
4457 static enum sctp_disposition
sctp_sf_abort_violation(
4459 const struct sctp_endpoint
*ep
,
4460 const struct sctp_association
*asoc
,
4462 struct sctp_cmd_seq
*commands
,
4463 const __u8
*payload
,
4464 const size_t paylen
)
4466 struct sctp_packet
*packet
= NULL
;
4467 struct sctp_chunk
*chunk
= arg
;
4468 struct sctp_chunk
*abort
= NULL
;
4470 /* SCTP-AUTH, Section 6.3:
4471 * It should be noted that if the receiver wants to tear
4472 * down an association in an authenticated way only, the
4473 * handling of malformed packets should not result in
4474 * tearing down the association.
4476 * This means that if we only want to abort associations
4477 * in an authenticated way (i.e AUTH+ABORT), then we
4478 * can't destroy this association just because the packet
4481 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4484 /* Make the abort chunk. */
4485 abort
= sctp_make_abort_violation(asoc
, chunk
, payload
, paylen
);
4490 /* Treat INIT-ACK as a special case during COOKIE-WAIT. */
4491 if (chunk
->chunk_hdr
->type
== SCTP_CID_INIT_ACK
&&
4492 !asoc
->peer
.i
.init_tag
) {
4493 struct sctp_initack_chunk
*initack
;
4495 initack
= (struct sctp_initack_chunk
*)chunk
->chunk_hdr
;
4496 if (!sctp_chunk_length_valid(chunk
, sizeof(*initack
)))
4497 abort
->chunk_hdr
->flags
|= SCTP_CHUNK_FLAG_T
;
4499 unsigned int inittag
;
4501 inittag
= ntohl(initack
->init_hdr
.init_tag
);
4502 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_INITTAG
,
4507 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4508 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4510 if (asoc
->state
<= SCTP_STATE_COOKIE_ECHOED
) {
4511 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4512 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4513 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4514 SCTP_ERROR(ECONNREFUSED
));
4515 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4516 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4518 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4519 SCTP_ERROR(ECONNABORTED
));
4520 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4521 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4522 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4525 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
4530 if (sctp_test_T_bit(abort
))
4531 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
4533 abort
->skb
->sk
= ep
->base
.sk
;
4535 sctp_packet_append_chunk(packet
, abort
);
4537 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
4538 SCTP_PACKET(packet
));
4540 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4543 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4546 sctp_sf_pdiscard(net
, ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4547 return SCTP_DISPOSITION_ABORT
;
4550 sctp_chunk_free(abort
);
4552 return SCTP_DISPOSITION_NOMEM
;
4556 * Handle a protocol violation when the chunk length is invalid.
4557 * "Invalid" length is identified as smaller than the minimal length a
4558 * given chunk can be. For example, a SACK chunk has invalid length
4559 * if its length is set to be smaller than the size of struct sctp_sack_chunk.
4561 * We inform the other end by sending an ABORT with a Protocol Violation
4564 * Section: Not specified
4565 * Verification Tag: Nothing to do
4567 * (endpoint, asoc, chunk)
4570 * (reply_msg, msg_up, counters)
4572 * Generate an ABORT chunk and terminate the association.
4574 static enum sctp_disposition
sctp_sf_violation_chunklen(
4576 const struct sctp_endpoint
*ep
,
4577 const struct sctp_association
*asoc
,
4578 const union sctp_subtype type
,
4580 struct sctp_cmd_seq
*commands
)
4582 static const char err_str
[] = "The following chunk had invalid length:";
4584 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4589 * Handle a protocol violation when the parameter length is invalid.
4590 * If the length is smaller than the minimum length of a given parameter,
4591 * or accumulated length in multi parameters exceeds the end of the chunk,
4592 * the length is considered as invalid.
4594 static enum sctp_disposition
sctp_sf_violation_paramlen(
4596 const struct sctp_endpoint
*ep
,
4597 const struct sctp_association
*asoc
,
4598 const union sctp_subtype type
,
4599 void *arg
, void *ext
,
4600 struct sctp_cmd_seq
*commands
)
4602 struct sctp_paramhdr
*param
= ext
;
4603 struct sctp_chunk
*abort
= NULL
;
4604 struct sctp_chunk
*chunk
= arg
;
4606 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4609 /* Make the abort chunk. */
4610 abort
= sctp_make_violation_paramlen(asoc
, chunk
, param
);
4614 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4615 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4617 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4618 SCTP_ERROR(ECONNABORTED
));
4619 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4620 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4621 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4622 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4625 sctp_sf_pdiscard(net
, ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4626 return SCTP_DISPOSITION_ABORT
;
4628 return SCTP_DISPOSITION_NOMEM
;
4631 /* Handle a protocol violation when the peer trying to advance the
4632 * cumulative tsn ack to a point beyond the max tsn currently sent.
4634 * We inform the other end by sending an ABORT with a Protocol Violation
4637 static enum sctp_disposition
sctp_sf_violation_ctsn(
4639 const struct sctp_endpoint
*ep
,
4640 const struct sctp_association
*asoc
,
4641 const union sctp_subtype type
,
4643 struct sctp_cmd_seq
*commands
)
4645 static const char err_str
[] = "The cumulative tsn ack beyond the max tsn currently sent:";
4647 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4651 /* Handle protocol violation of an invalid chunk bundling. For example,
4652 * when we have an association and we receive bundled INIT-ACK, or
4653 * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle"
4654 * statement from the specs. Additionally, there might be an attacker
4655 * on the path and we may not want to continue this communication.
4657 static enum sctp_disposition
sctp_sf_violation_chunk(
4659 const struct sctp_endpoint
*ep
,
4660 const struct sctp_association
*asoc
,
4661 const union sctp_subtype type
,
4663 struct sctp_cmd_seq
*commands
)
4665 static const char err_str
[] = "The following chunk violates protocol:";
4668 return sctp_sf_violation(net
, ep
, asoc
, type
, arg
, commands
);
4670 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4673 /***************************************************************************
4674 * These are the state functions for handling primitive (Section 10) events.
4675 ***************************************************************************/
4677 * sctp_sf_do_prm_asoc
4679 * Section: 10.1 ULP-to-SCTP
4682 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
4683 * outbound stream count)
4684 * -> association id [,destination transport addr list] [,outbound stream
4687 * This primitive allows the upper layer to initiate an association to a
4688 * specific peer endpoint.
4690 * The peer endpoint shall be specified by one of the transport addresses
4691 * which defines the endpoint (see Section 1.4). If the local SCTP
4692 * instance has not been initialized, the ASSOCIATE is considered an
4694 * [This is not relevant for the kernel implementation since we do all
4695 * initialization at boot time. It we hadn't initialized we wouldn't
4696 * get anywhere near this code.]
4698 * An association id, which is a local handle to the SCTP association,
4699 * will be returned on successful establishment of the association. If
4700 * SCTP is not able to open an SCTP association with the peer endpoint,
4701 * an error is returned.
4702 * [In the kernel implementation, the struct sctp_association needs to
4703 * be created BEFORE causing this primitive to run.]
4705 * Other association parameters may be returned, including the
4706 * complete destination transport addresses of the peer as well as the
4707 * outbound stream count of the local endpoint. One of the transport
4708 * address from the returned destination addresses will be selected by
4709 * the local endpoint as default primary path for sending SCTP packets
4710 * to this peer. The returned "destination transport addr list" can
4711 * be used by the ULP to change the default primary path or to force
4712 * sending a packet to a specific transport address. [All of this
4713 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
4716 * Mandatory attributes:
4718 * o local SCTP instance name - obtained from the INITIALIZE operation.
4719 * [This is the argument asoc.]
4720 * o destination transport addr - specified as one of the transport
4721 * addresses of the peer endpoint with which the association is to be
4723 * [This is asoc->peer.active_path.]
4724 * o outbound stream count - the number of outbound streams the ULP
4725 * would like to open towards this peer endpoint.
4726 * [BUG: This is not currently implemented.]
4727 * Optional attributes:
4731 * The return value is a disposition.
4733 enum sctp_disposition
sctp_sf_do_prm_asoc(struct net
*net
,
4734 const struct sctp_endpoint
*ep
,
4735 const struct sctp_association
*asoc
,
4736 const union sctp_subtype type
,
4738 struct sctp_cmd_seq
*commands
)
4740 struct sctp_association
*my_asoc
;
4741 struct sctp_chunk
*repl
;
4743 /* The comment below says that we enter COOKIE-WAIT AFTER
4744 * sending the INIT, but that doesn't actually work in our
4747 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4748 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
4750 /* RFC 2960 5.1 Normal Establishment of an Association
4752 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
4753 * must provide its Verification Tag (Tag_A) in the Initiate
4754 * Tag field. Tag_A SHOULD be a random number in the range of
4755 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
4758 repl
= sctp_make_init(asoc
, &asoc
->base
.bind_addr
, GFP_ATOMIC
, 0);
4762 /* Choose transport for INIT. */
4763 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
4766 /* Cast away the const modifier, as we want to just
4767 * rerun it through as a sideffect.
4769 my_asoc
= (struct sctp_association
*)asoc
;
4770 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(my_asoc
));
4772 /* After sending the INIT, "A" starts the T1-init timer and
4773 * enters the COOKIE-WAIT state.
4775 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4776 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4777 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
4778 return SCTP_DISPOSITION_CONSUME
;
4781 return SCTP_DISPOSITION_NOMEM
;
4785 * Process the SEND primitive.
4787 * Section: 10.1 ULP-to-SCTP
4790 * Format: SEND(association id, buffer address, byte count [,context]
4791 * [,stream id] [,life time] [,destination transport address]
4792 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
4795 * This is the main method to send user data via SCTP.
4797 * Mandatory attributes:
4799 * o association id - local handle to the SCTP association
4801 * o buffer address - the location where the user message to be
4802 * transmitted is stored;
4804 * o byte count - The size of the user data in number of bytes;
4806 * Optional attributes:
4808 * o context - an optional 32 bit integer that will be carried in the
4809 * sending failure notification to the ULP if the transportation of
4810 * this User Message fails.
4812 * o stream id - to indicate which stream to send the data on. If not
4813 * specified, stream 0 will be used.
4815 * o life time - specifies the life time of the user data. The user data
4816 * will not be sent by SCTP after the life time expires. This
4817 * parameter can be used to avoid efforts to transmit stale
4818 * user messages. SCTP notifies the ULP if the data cannot be
4819 * initiated to transport (i.e. sent to the destination via SCTP's
4820 * send primitive) within the life time variable. However, the
4821 * user data will be transmitted if SCTP has attempted to transmit a
4822 * chunk before the life time expired.
4824 * o destination transport address - specified as one of the destination
4825 * transport addresses of the peer endpoint to which this packet
4826 * should be sent. Whenever possible, SCTP should use this destination
4827 * transport address for sending the packets, instead of the current
4830 * o unorder flag - this flag, if present, indicates that the user
4831 * would like the data delivered in an unordered fashion to the peer
4832 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
4835 * o no-bundle flag - instructs SCTP not to bundle this user data with
4836 * other outbound DATA chunks. SCTP MAY still bundle even when
4837 * this flag is present, when faced with network congestion.
4839 * o payload protocol-id - A 32 bit unsigned integer that is to be
4840 * passed to the peer indicating the type of payload protocol data
4841 * being transmitted. This value is passed as opaque data by SCTP.
4843 * The return value is the disposition.
4845 enum sctp_disposition
sctp_sf_do_prm_send(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_datamsg
*msg
= arg
;
4854 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_MSG
, SCTP_DATAMSG(msg
));
4855 return SCTP_DISPOSITION_CONSUME
;
4859 * Process the SHUTDOWN primitive.
4864 * Format: SHUTDOWN(association id)
4867 * Gracefully closes an association. Any locally queued user data
4868 * will be delivered to the peer. The association will be terminated only
4869 * after the peer acknowledges all the SCTP packets sent. A success code
4870 * will be returned on successful termination of the association. If
4871 * attempting to terminate the association results in a failure, an error
4872 * code shall be returned.
4874 * Mandatory attributes:
4876 * o association id - local handle to the SCTP association
4878 * Optional attributes:
4882 * The return value is the disposition.
4884 enum sctp_disposition
sctp_sf_do_9_2_prm_shutdown(
4886 const struct sctp_endpoint
*ep
,
4887 const struct sctp_association
*asoc
,
4888 const union sctp_subtype type
,
4890 struct sctp_cmd_seq
*commands
)
4892 enum sctp_disposition disposition
;
4894 /* From 9.2 Shutdown of an Association
4895 * Upon receipt of the SHUTDOWN primitive from its upper
4896 * layer, the endpoint enters SHUTDOWN-PENDING state and
4897 * remains there until all outstanding data has been
4898 * acknowledged by its peer. The endpoint accepts no new data
4899 * from its upper layer, but retransmits data to the far end
4900 * if necessary to fill gaps.
4902 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4903 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
4905 disposition
= SCTP_DISPOSITION_CONSUME
;
4906 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
4907 disposition
= sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
, type
,
4915 * Process the ABORT primitive.
4920 * Format: Abort(association id [, cause code])
4923 * Ungracefully closes an association. Any locally queued user data
4924 * will be discarded and an ABORT chunk is sent to the peer. A success code
4925 * will be returned on successful abortion of the association. If
4926 * attempting to abort the association results in a failure, an error
4927 * code shall be returned.
4929 * Mandatory attributes:
4931 * o association id - local handle to the SCTP association
4933 * Optional attributes:
4935 * o cause code - reason of the abort to be passed to the peer
4939 * The return value is the disposition.
4941 enum sctp_disposition
sctp_sf_do_9_1_prm_abort(
4943 const struct sctp_endpoint
*ep
,
4944 const struct sctp_association
*asoc
,
4945 const union sctp_subtype type
,
4947 struct sctp_cmd_seq
*commands
)
4949 /* From 9.1 Abort of an Association
4950 * Upon receipt of the ABORT primitive from its upper
4951 * layer, the endpoint enters CLOSED state and
4952 * discard all outstanding data has been
4953 * acknowledged by its peer. The endpoint accepts no new data
4954 * from its upper layer, but retransmits data to the far end
4955 * if necessary to fill gaps.
4957 struct sctp_chunk
*abort
= arg
;
4960 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4962 /* Even if we can't send the ABORT due to low memory delete the
4963 * TCB. This is a departure from our typical NOMEM handling.
4966 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4967 SCTP_ERROR(ECONNABORTED
));
4968 /* Delete the established association. */
4969 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4970 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4972 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4973 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4975 return SCTP_DISPOSITION_ABORT
;
4978 /* We tried an illegal operation on an association which is closed. */
4979 enum sctp_disposition
sctp_sf_error_closed(struct net
*net
,
4980 const struct sctp_endpoint
*ep
,
4981 const struct sctp_association
*asoc
,
4982 const union sctp_subtype type
,
4984 struct sctp_cmd_seq
*commands
)
4986 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
, SCTP_ERROR(-EINVAL
));
4987 return SCTP_DISPOSITION_CONSUME
;
4990 /* We tried an illegal operation on an association which is shutting
4993 enum sctp_disposition
sctp_sf_error_shutdown(
4995 const struct sctp_endpoint
*ep
,
4996 const struct sctp_association
*asoc
,
4997 const union sctp_subtype type
,
4999 struct sctp_cmd_seq
*commands
)
5001 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
,
5002 SCTP_ERROR(-ESHUTDOWN
));
5003 return SCTP_DISPOSITION_CONSUME
;
5007 * sctp_cookie_wait_prm_shutdown
5009 * Section: 4 Note: 2
5014 * The RFC does not explicitly address this issue, but is the route through the
5015 * state table when someone issues a shutdown while in COOKIE_WAIT state.
5020 enum sctp_disposition
sctp_sf_cookie_wait_prm_shutdown(
5022 const struct sctp_endpoint
*ep
,
5023 const struct sctp_association
*asoc
,
5024 const union sctp_subtype type
,
5026 struct sctp_cmd_seq
*commands
)
5028 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5029 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5031 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5032 SCTP_STATE(SCTP_STATE_CLOSED
));
5034 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
5036 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
5038 return SCTP_DISPOSITION_DELETE_TCB
;
5042 * sctp_cookie_echoed_prm_shutdown
5044 * Section: 4 Note: 2
5049 * The RFC does not explcitly address this issue, but is the route through the
5050 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
5055 enum sctp_disposition
sctp_sf_cookie_echoed_prm_shutdown(
5057 const struct sctp_endpoint
*ep
,
5058 const struct sctp_association
*asoc
,
5059 const union sctp_subtype type
,
5061 struct sctp_cmd_seq
*commands
)
5063 /* There is a single T1 timer, so we should be able to use
5064 * common function with the COOKIE-WAIT state.
5066 return sctp_sf_cookie_wait_prm_shutdown(net
, ep
, asoc
, type
, arg
, commands
);
5070 * sctp_sf_cookie_wait_prm_abort
5072 * Section: 4 Note: 2
5077 * The RFC does not explicitly address this issue, but is the route through the
5078 * state table when someone issues an abort while in COOKIE_WAIT state.
5083 enum sctp_disposition
sctp_sf_cookie_wait_prm_abort(
5085 const struct sctp_endpoint
*ep
,
5086 const struct sctp_association
*asoc
,
5087 const union sctp_subtype type
,
5089 struct sctp_cmd_seq
*commands
)
5091 struct sctp_chunk
*abort
= arg
;
5093 /* Stop T1-init timer */
5094 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5095 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5098 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
5100 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5101 SCTP_STATE(SCTP_STATE_CLOSED
));
5103 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5105 /* Even if we can't send the ABORT due to low memory delete the
5106 * TCB. This is a departure from our typical NOMEM handling.
5109 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5110 SCTP_ERROR(ECONNREFUSED
));
5111 /* Delete the established association. */
5112 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5113 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
5115 return SCTP_DISPOSITION_ABORT
;
5119 * sctp_sf_cookie_echoed_prm_abort
5121 * Section: 4 Note: 3
5126 * The RFC does not explcitly address this issue, but is the route through the
5127 * state table when someone issues an abort while in COOKIE_ECHOED state.
5132 enum sctp_disposition
sctp_sf_cookie_echoed_prm_abort(
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 /* There is a single T1 timer, so we should be able to use
5141 * common function with the COOKIE-WAIT state.
5143 return sctp_sf_cookie_wait_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5147 * sctp_sf_shutdown_pending_prm_abort
5152 * The RFC does not explicitly address this issue, but is the route through the
5153 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
5158 enum sctp_disposition
sctp_sf_shutdown_pending_prm_abort(
5160 const struct sctp_endpoint
*ep
,
5161 const struct sctp_association
*asoc
,
5162 const union sctp_subtype type
,
5164 struct sctp_cmd_seq
*commands
)
5166 /* Stop the T5-shutdown guard timer. */
5167 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5168 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5170 return sctp_sf_do_9_1_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5174 * sctp_sf_shutdown_sent_prm_abort
5179 * The RFC does not explicitly address this issue, but is the route through the
5180 * state table when someone issues an abort while in SHUTDOWN-SENT state.
5185 enum sctp_disposition
sctp_sf_shutdown_sent_prm_abort(
5187 const struct sctp_endpoint
*ep
,
5188 const struct sctp_association
*asoc
,
5189 const union sctp_subtype type
,
5191 struct sctp_cmd_seq
*commands
)
5193 /* Stop the T2-shutdown timer. */
5194 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5195 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5197 /* Stop the T5-shutdown guard timer. */
5198 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5199 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5201 return sctp_sf_do_9_1_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5205 * sctp_sf_cookie_echoed_prm_abort
5210 * The RFC does not explcitly address this issue, but is the route through the
5211 * state table when someone issues an abort while in COOKIE_ECHOED state.
5216 enum sctp_disposition
sctp_sf_shutdown_ack_sent_prm_abort(
5218 const struct sctp_endpoint
*ep
,
5219 const struct sctp_association
*asoc
,
5220 const union sctp_subtype type
,
5222 struct sctp_cmd_seq
*commands
)
5224 /* The same T2 timer, so we should be able to use
5225 * common function with the SHUTDOWN-SENT state.
5227 return sctp_sf_shutdown_sent_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5231 * Process the REQUESTHEARTBEAT primitive
5234 * J) Request Heartbeat
5236 * Format: REQUESTHEARTBEAT(association id, destination transport address)
5240 * Instructs the local endpoint to perform a HeartBeat on the specified
5241 * destination transport address of the given association. The returned
5242 * result should indicate whether the transmission of the HEARTBEAT
5243 * chunk to the destination address is successful.
5245 * Mandatory attributes:
5247 * o association id - local handle to the SCTP association
5249 * o destination transport address - the transport address of the
5250 * association on which a heartbeat should be issued.
5252 enum sctp_disposition
sctp_sf_do_prm_requestheartbeat(
5254 const struct sctp_endpoint
*ep
,
5255 const struct sctp_association
*asoc
,
5256 const union sctp_subtype type
,
5258 struct sctp_cmd_seq
*commands
)
5260 if (SCTP_DISPOSITION_NOMEM
== sctp_sf_heartbeat(ep
, asoc
, type
,
5261 (struct sctp_transport
*)arg
, commands
))
5262 return SCTP_DISPOSITION_NOMEM
;
5265 * RFC 2960 (bis), section 8.3
5267 * D) Request an on-demand HEARTBEAT on a specific destination
5268 * transport address of a given association.
5270 * The endpoint should increment the respective error counter of
5271 * the destination transport address each time a HEARTBEAT is sent
5272 * to that address and not acknowledged within one RTO.
5275 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
5276 SCTP_TRANSPORT(arg
));
5277 return SCTP_DISPOSITION_CONSUME
;
5281 * ADDIP Section 4.1 ASCONF Chunk Procedures
5282 * When an endpoint has an ASCONF signaled change to be sent to the
5283 * remote endpoint it should do A1 to A9
5285 enum sctp_disposition
sctp_sf_do_prm_asconf(struct net
*net
,
5286 const struct sctp_endpoint
*ep
,
5287 const struct sctp_association
*asoc
,
5288 const union sctp_subtype type
,
5290 struct sctp_cmd_seq
*commands
)
5292 struct sctp_chunk
*chunk
= arg
;
5294 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5295 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5296 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5297 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
5298 return SCTP_DISPOSITION_CONSUME
;
5301 /* RE-CONFIG Section 5.1 RECONF Chunk Procedures */
5302 enum sctp_disposition
sctp_sf_do_prm_reconf(struct net
*net
,
5303 const struct sctp_endpoint
*ep
,
5304 const struct sctp_association
*asoc
,
5305 const union sctp_subtype type
,
5307 struct sctp_cmd_seq
*commands
)
5309 struct sctp_chunk
*chunk
= arg
;
5311 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
5312 return SCTP_DISPOSITION_CONSUME
;
5316 * Ignore the primitive event
5318 * The return value is the disposition of the primitive.
5320 enum sctp_disposition
sctp_sf_ignore_primitive(
5322 const struct sctp_endpoint
*ep
,
5323 const struct sctp_association
*asoc
,
5324 const union sctp_subtype type
,
5326 struct sctp_cmd_seq
*commands
)
5328 pr_debug("%s: primitive type:%d is ignored\n", __func__
,
5331 return SCTP_DISPOSITION_DISCARD
;
5334 /***************************************************************************
5335 * These are the state functions for the OTHER events.
5336 ***************************************************************************/
5339 * When the SCTP stack has no more user data to send or retransmit, this
5340 * notification is given to the user. Also, at the time when a user app
5341 * subscribes to this event, if there is no data to be sent or
5342 * retransmit, the stack will immediately send up this notification.
5344 enum sctp_disposition
sctp_sf_do_no_pending_tsn(
5346 const struct sctp_endpoint
*ep
,
5347 const struct sctp_association
*asoc
,
5348 const union sctp_subtype type
,
5350 struct sctp_cmd_seq
*commands
)
5352 struct sctp_ulpevent
*event
;
5354 event
= sctp_ulpevent_make_sender_dry_event(asoc
, GFP_ATOMIC
);
5356 return SCTP_DISPOSITION_NOMEM
;
5358 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(event
));
5360 return SCTP_DISPOSITION_CONSUME
;
5364 * Start the shutdown negotiation.
5367 * Once all its outstanding data has been acknowledged, the endpoint
5368 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
5369 * TSN Ack field the last sequential TSN it has received from the peer.
5370 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
5371 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
5372 * with the updated last sequential TSN received from its peer.
5374 * The return value is the disposition.
5376 enum sctp_disposition
sctp_sf_do_9_2_start_shutdown(
5378 const struct sctp_endpoint
*ep
,
5379 const struct sctp_association
*asoc
,
5380 const union sctp_subtype type
,
5382 struct sctp_cmd_seq
*commands
)
5384 struct sctp_chunk
*reply
;
5386 /* Once all its outstanding data has been acknowledged, the
5387 * endpoint shall send a SHUTDOWN chunk to its peer including
5388 * in the Cumulative TSN Ack field the last sequential TSN it
5389 * has received from the peer.
5391 reply
= sctp_make_shutdown(asoc
, NULL
);
5395 /* Set the transport for the SHUTDOWN chunk and the timeout for the
5396 * T2-shutdown timer.
5398 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5400 /* It shall then start the T2-shutdown timer */
5401 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5402 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5404 /* RFC 4960 Section 9.2
5405 * The sender of the SHUTDOWN MAY also start an overall guard timer
5406 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5408 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5409 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5411 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
5412 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5413 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5415 /* and enter the SHUTDOWN-SENT state. */
5416 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5417 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT
));
5419 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5421 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5424 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5426 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5428 return SCTP_DISPOSITION_CONSUME
;
5431 return SCTP_DISPOSITION_NOMEM
;
5435 * Generate a SHUTDOWN ACK now that everything is SACK'd.
5439 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5440 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
5441 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
5442 * endpoint must re-send the SHUTDOWN ACK.
5444 * The return value is the disposition.
5446 enum sctp_disposition
sctp_sf_do_9_2_shutdown_ack(
5448 const struct sctp_endpoint
*ep
,
5449 const struct sctp_association
*asoc
,
5450 const union sctp_subtype type
,
5452 struct sctp_cmd_seq
*commands
)
5454 struct sctp_chunk
*chunk
= arg
;
5455 struct sctp_chunk
*reply
;
5457 /* There are 2 ways of getting here:
5458 * 1) called in response to a SHUTDOWN chunk
5459 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
5461 * For the case (2), the arg parameter is set to NULL. We need
5462 * to check that we have a chunk before accessing it's fields.
5465 if (!sctp_vtag_verify(chunk
, asoc
))
5466 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
,
5469 /* Make sure that the SHUTDOWN chunk has a valid length. */
5470 if (!sctp_chunk_length_valid(
5471 chunk
, sizeof(struct sctp_shutdown_chunk
)))
5472 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
,
5476 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5477 * shall send a SHUTDOWN ACK ...
5479 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
5483 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
5484 * the T2-shutdown timer.
5486 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5488 /* and start/restart a T2-shutdown timer of its own, */
5489 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5490 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5492 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
5493 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5494 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5496 /* Enter the SHUTDOWN-ACK-SENT state. */
5497 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5498 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT
));
5500 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5502 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5505 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5507 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5509 return SCTP_DISPOSITION_CONSUME
;
5512 return SCTP_DISPOSITION_NOMEM
;
5516 * Ignore the event defined as other
5518 * The return value is the disposition of the event.
5520 enum sctp_disposition
sctp_sf_ignore_other(struct net
*net
,
5521 const struct sctp_endpoint
*ep
,
5522 const struct sctp_association
*asoc
,
5523 const union sctp_subtype type
,
5525 struct sctp_cmd_seq
*commands
)
5527 pr_debug("%s: the event other type:%d is ignored\n",
5528 __func__
, type
.other
);
5530 return SCTP_DISPOSITION_DISCARD
;
5533 /************************************************************
5534 * These are the state functions for handling timeout events.
5535 ************************************************************/
5540 * Section: 6.3.3 Handle T3-rtx Expiration
5542 * Whenever the retransmission timer T3-rtx expires for a destination
5543 * address, do the following:
5546 * The return value is the disposition of the chunk.
5548 enum sctp_disposition
sctp_sf_do_6_3_3_rtx(struct net
*net
,
5549 const struct sctp_endpoint
*ep
,
5550 const struct sctp_association
*asoc
,
5551 const union sctp_subtype type
,
5553 struct sctp_cmd_seq
*commands
)
5555 struct sctp_transport
*transport
= arg
;
5557 SCTP_INC_STATS(net
, SCTP_MIB_T3_RTX_EXPIREDS
);
5559 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5560 if (asoc
->peer
.zero_window_announced
&&
5561 asoc
->state
== SCTP_STATE_SHUTDOWN_PENDING
) {
5563 * We are here likely because the receiver had its rwnd
5564 * closed for a while and we have not been able to
5565 * transmit the locally queued data within the maximum
5566 * retransmission attempts limit. Start the T5
5567 * shutdown guard timer to give the receiver one last
5568 * chance and some additional time to recover before
5571 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START_ONCE
,
5572 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5574 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5575 SCTP_ERROR(ETIMEDOUT
));
5576 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5577 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5578 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5579 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5580 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5581 return SCTP_DISPOSITION_DELETE_TCB
;
5585 /* E1) For the destination address for which the timer
5586 * expires, adjust its ssthresh with rules defined in Section
5587 * 7.2.3 and set the cwnd <- MTU.
5590 /* E2) For the destination address for which the timer
5591 * expires, set RTO <- RTO * 2 ("back off the timer"). The
5592 * maximum value discussed in rule C7 above (RTO.max) may be
5593 * used to provide an upper bound to this doubling operation.
5596 /* E3) Determine how many of the earliest (i.e., lowest TSN)
5597 * outstanding DATA chunks for the address for which the
5598 * T3-rtx has expired will fit into a single packet, subject
5599 * to the MTU constraint for the path corresponding to the
5600 * destination transport address to which the retransmission
5601 * is being sent (this may be different from the address for
5602 * which the timer expires [see Section 6.4]). Call this
5603 * value K. Bundle and retransmit those K DATA chunks in a
5604 * single packet to the destination endpoint.
5606 * Note: Any DATA chunks that were sent to the address for
5607 * which the T3-rtx timer expired but did not fit in one MTU
5608 * (rule E3 above), should be marked for retransmission and
5609 * sent as soon as cwnd allows (normally when a SACK arrives).
5612 /* Do some failure management (Section 8.2). */
5613 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
5615 /* NB: Rules E4 and F1 are implicit in R1. */
5616 sctp_add_cmd_sf(commands
, SCTP_CMD_RETRAN
, SCTP_TRANSPORT(transport
));
5618 return SCTP_DISPOSITION_CONSUME
;
5622 * Generate delayed SACK on timeout
5624 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
5626 * The guidelines on delayed acknowledgement algorithm specified in
5627 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
5628 * acknowledgement SHOULD be generated for at least every second packet
5629 * (not every second DATA chunk) received, and SHOULD be generated
5630 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
5631 * some situations it may be beneficial for an SCTP transmitter to be
5632 * more conservative than the algorithms detailed in this document
5633 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
5634 * the following algorithms allow.
5636 enum sctp_disposition
sctp_sf_do_6_2_sack(struct net
*net
,
5637 const struct sctp_endpoint
*ep
,
5638 const struct sctp_association
*asoc
,
5639 const union sctp_subtype type
,
5641 struct sctp_cmd_seq
*commands
)
5643 SCTP_INC_STATS(net
, SCTP_MIB_DELAY_SACK_EXPIREDS
);
5644 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
5645 return SCTP_DISPOSITION_CONSUME
;
5649 * sctp_sf_t1_init_timer_expire
5651 * Section: 4 Note: 2
5656 * RFC 2960 Section 4 Notes
5657 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
5658 * and re-start the T1-init timer without changing state. This MUST
5659 * be repeated up to 'Max.Init.Retransmits' times. After that, the
5660 * endpoint MUST abort the initialization process and report the
5661 * error to SCTP user.
5667 enum sctp_disposition
sctp_sf_t1_init_timer_expire(
5669 const struct sctp_endpoint
*ep
,
5670 const struct sctp_association
*asoc
,
5671 const union sctp_subtype type
,
5673 struct sctp_cmd_seq
*commands
)
5675 int attempts
= asoc
->init_err_counter
+ 1;
5676 struct sctp_chunk
*repl
= NULL
;
5677 struct sctp_bind_addr
*bp
;
5679 pr_debug("%s: timer T1 expired (INIT)\n", __func__
);
5681 SCTP_INC_STATS(net
, SCTP_MIB_T1_INIT_EXPIREDS
);
5683 if (attempts
<= asoc
->max_init_attempts
) {
5684 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
5685 repl
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, 0);
5687 return SCTP_DISPOSITION_NOMEM
;
5689 /* Choose transport for INIT. */
5690 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5693 /* Issue a sideeffect to do the needed accounting. */
5694 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_RESTART
,
5695 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5697 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5699 pr_debug("%s: giving up on INIT, attempts:%d "
5700 "max_init_attempts:%d\n", __func__
, attempts
,
5701 asoc
->max_init_attempts
);
5703 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5704 SCTP_ERROR(ETIMEDOUT
));
5705 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5706 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5707 return SCTP_DISPOSITION_DELETE_TCB
;
5710 return SCTP_DISPOSITION_CONSUME
;
5714 * sctp_sf_t1_cookie_timer_expire
5716 * Section: 4 Note: 2
5721 * RFC 2960 Section 4 Notes
5722 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
5723 * COOKIE ECHO and re-start the T1-cookie timer without changing
5724 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
5725 * After that, the endpoint MUST abort the initialization process and
5726 * report the error to SCTP user.
5732 enum sctp_disposition
sctp_sf_t1_cookie_timer_expire(
5734 const struct sctp_endpoint
*ep
,
5735 const struct sctp_association
*asoc
,
5736 const union sctp_subtype type
,
5738 struct sctp_cmd_seq
*commands
)
5740 int attempts
= asoc
->init_err_counter
+ 1;
5741 struct sctp_chunk
*repl
= NULL
;
5743 pr_debug("%s: timer T1 expired (COOKIE-ECHO)\n", __func__
);
5745 SCTP_INC_STATS(net
, SCTP_MIB_T1_COOKIE_EXPIREDS
);
5747 if (attempts
<= asoc
->max_init_attempts
) {
5748 repl
= sctp_make_cookie_echo(asoc
, NULL
);
5750 return SCTP_DISPOSITION_NOMEM
;
5752 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5754 /* Issue a sideeffect to do the needed accounting. */
5755 sctp_add_cmd_sf(commands
, SCTP_CMD_COOKIEECHO_RESTART
,
5756 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
5758 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5760 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5761 SCTP_ERROR(ETIMEDOUT
));
5762 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5763 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5764 return SCTP_DISPOSITION_DELETE_TCB
;
5767 return SCTP_DISPOSITION_CONSUME
;
5770 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
5771 * with the updated last sequential TSN received from its peer.
5773 * An endpoint should limit the number of retransmissions of the
5774 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
5775 * If this threshold is exceeded the endpoint should destroy the TCB and
5776 * MUST report the peer endpoint unreachable to the upper layer (and
5777 * thus the association enters the CLOSED state). The reception of any
5778 * packet from its peer (i.e. as the peer sends all of its queued DATA
5779 * chunks) should clear the endpoint's retransmission count and restart
5780 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
5781 * all of its queued DATA chunks that have not yet been sent.
5783 enum sctp_disposition
sctp_sf_t2_timer_expire(
5785 const struct sctp_endpoint
*ep
,
5786 const struct sctp_association
*asoc
,
5787 const union sctp_subtype type
,
5789 struct sctp_cmd_seq
*commands
)
5791 struct sctp_chunk
*reply
= NULL
;
5793 pr_debug("%s: timer T2 expired\n", __func__
);
5795 SCTP_INC_STATS(net
, SCTP_MIB_T2_SHUTDOWN_EXPIREDS
);
5797 ((struct sctp_association
*)asoc
)->shutdown_retries
++;
5799 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5800 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5801 SCTP_ERROR(ETIMEDOUT
));
5802 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5803 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5804 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5805 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5806 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5807 return SCTP_DISPOSITION_DELETE_TCB
;
5810 switch (asoc
->state
) {
5811 case SCTP_STATE_SHUTDOWN_SENT
:
5812 reply
= sctp_make_shutdown(asoc
, NULL
);
5815 case SCTP_STATE_SHUTDOWN_ACK_SENT
:
5816 reply
= sctp_make_shutdown_ack(asoc
, NULL
);
5827 /* Do some failure management (Section 8.2).
5828 * If we remove the transport an SHUTDOWN was last sent to, don't
5829 * do failure management.
5831 if (asoc
->shutdown_last_sent_to
)
5832 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5833 SCTP_TRANSPORT(asoc
->shutdown_last_sent_to
));
5835 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
5836 * the T2-shutdown timer.
5838 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5840 /* Restart the T2-shutdown timer. */
5841 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5842 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5843 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5844 return SCTP_DISPOSITION_CONSUME
;
5847 return SCTP_DISPOSITION_NOMEM
;
5851 * ADDIP Section 4.1 ASCONF CHunk Procedures
5852 * If the T4 RTO timer expires the endpoint should do B1 to B5
5854 enum sctp_disposition
sctp_sf_t4_timer_expire(
5856 const struct sctp_endpoint
*ep
,
5857 const struct sctp_association
*asoc
,
5858 const union sctp_subtype type
,
5860 struct sctp_cmd_seq
*commands
)
5862 struct sctp_chunk
*chunk
= asoc
->addip_last_asconf
;
5863 struct sctp_transport
*transport
= chunk
->transport
;
5865 SCTP_INC_STATS(net
, SCTP_MIB_T4_RTO_EXPIREDS
);
5867 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
5868 * detection on the appropriate destination address as defined in
5869 * RFC2960 [5] section 8.1 and 8.2.
5872 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5873 SCTP_TRANSPORT(transport
));
5875 /* Reconfig T4 timer and transport. */
5876 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5878 /* ADDIP 4.1 B2) Increment the association error counters and perform
5879 * endpoint failure detection on the association as defined in
5880 * RFC2960 [5] section 8.1 and 8.2.
5881 * association error counter is incremented in SCTP_CMD_STRIKE.
5883 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5884 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5885 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5886 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5887 SCTP_ERROR(ETIMEDOUT
));
5888 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5889 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5890 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5891 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5892 return SCTP_DISPOSITION_ABORT
;
5895 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
5896 * the ASCONF chunk was sent by doubling the RTO timer value.
5897 * This is done in SCTP_CMD_STRIKE.
5900 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
5901 * choose an alternate destination address (please refer to RFC2960
5902 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
5903 * chunk, it MUST be the same (including its serial number) as the last
5906 sctp_chunk_hold(asoc
->addip_last_asconf
);
5907 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5908 SCTP_CHUNK(asoc
->addip_last_asconf
));
5910 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
5911 * destination is selected, then the RTO used will be that of the new
5912 * destination address.
5914 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5915 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5917 return SCTP_DISPOSITION_CONSUME
;
5920 /* sctpimpguide-05 Section 2.12.2
5921 * The sender of the SHUTDOWN MAY also start an overall guard timer
5922 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5923 * At the expiration of this timer the sender SHOULD abort the association
5924 * by sending an ABORT chunk.
5926 enum sctp_disposition
sctp_sf_t5_timer_expire(
5928 const struct sctp_endpoint
*ep
,
5929 const struct sctp_association
*asoc
,
5930 const union sctp_subtype type
,
5932 struct sctp_cmd_seq
*commands
)
5934 struct sctp_chunk
*reply
= NULL
;
5936 pr_debug("%s: timer T5 expired\n", __func__
);
5938 SCTP_INC_STATS(net
, SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS
);
5940 reply
= sctp_make_abort(asoc
, NULL
, 0);
5944 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5945 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5946 SCTP_ERROR(ETIMEDOUT
));
5947 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5948 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5950 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5951 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5953 return SCTP_DISPOSITION_DELETE_TCB
;
5955 return SCTP_DISPOSITION_NOMEM
;
5958 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
5959 * the association is automatically closed by starting the shutdown process.
5960 * The work that needs to be done is same as when SHUTDOWN is initiated by
5961 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
5963 enum sctp_disposition
sctp_sf_autoclose_timer_expire(
5965 const struct sctp_endpoint
*ep
,
5966 const struct sctp_association
*asoc
,
5967 const union sctp_subtype type
,
5969 struct sctp_cmd_seq
*commands
)
5971 enum sctp_disposition disposition
;
5973 SCTP_INC_STATS(net
, SCTP_MIB_AUTOCLOSE_EXPIREDS
);
5975 /* From 9.2 Shutdown of an Association
5976 * Upon receipt of the SHUTDOWN primitive from its upper
5977 * layer, the endpoint enters SHUTDOWN-PENDING state and
5978 * remains there until all outstanding data has been
5979 * acknowledged by its peer. The endpoint accepts no new data
5980 * from its upper layer, but retransmits data to the far end
5981 * if necessary to fill gaps.
5983 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5984 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
5986 disposition
= SCTP_DISPOSITION_CONSUME
;
5987 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
5988 disposition
= sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
, type
,
5995 /*****************************************************************************
5996 * These are sa state functions which could apply to all types of events.
5997 ****************************************************************************/
6000 * This table entry is not implemented.
6003 * (endpoint, asoc, chunk)
6005 * The return value is the disposition of the chunk.
6007 enum sctp_disposition
sctp_sf_not_impl(struct net
*net
,
6008 const struct sctp_endpoint
*ep
,
6009 const struct sctp_association
*asoc
,
6010 const union sctp_subtype type
,
6011 void *arg
, struct sctp_cmd_seq
*commands
)
6013 return SCTP_DISPOSITION_NOT_IMPL
;
6017 * This table entry represents a bug.
6020 * (endpoint, asoc, chunk)
6022 * The return value is the disposition of the chunk.
6024 enum sctp_disposition
sctp_sf_bug(struct net
*net
,
6025 const struct sctp_endpoint
*ep
,
6026 const struct sctp_association
*asoc
,
6027 const union sctp_subtype type
,
6028 void *arg
, struct sctp_cmd_seq
*commands
)
6030 return SCTP_DISPOSITION_BUG
;
6034 * This table entry represents the firing of a timer in the wrong state.
6035 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
6036 * when the association is in the wrong state. This event should
6037 * be ignored, so as to prevent any rearming of the timer.
6040 * (endpoint, asoc, chunk)
6042 * The return value is the disposition of the chunk.
6044 enum sctp_disposition
sctp_sf_timer_ignore(struct net
*net
,
6045 const struct sctp_endpoint
*ep
,
6046 const struct sctp_association
*asoc
,
6047 const union sctp_subtype type
,
6049 struct sctp_cmd_seq
*commands
)
6051 pr_debug("%s: timer %d ignored\n", __func__
, type
.chunk
);
6053 return SCTP_DISPOSITION_CONSUME
;
6056 /********************************************************************
6057 * 2nd Level Abstractions
6058 ********************************************************************/
6060 /* Pull the SACK chunk based on the SACK header. */
6061 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
)
6063 struct sctp_sackhdr
*sack
;
6068 /* Protect ourselves from reading too far into
6069 * the skb from a bogus sender.
6071 sack
= (struct sctp_sackhdr
*) chunk
->skb
->data
;
6073 num_blocks
= ntohs(sack
->num_gap_ack_blocks
);
6074 num_dup_tsns
= ntohs(sack
->num_dup_tsns
);
6075 len
= sizeof(struct sctp_sackhdr
);
6076 len
+= (num_blocks
+ num_dup_tsns
) * sizeof(__u32
);
6077 if (len
> chunk
->skb
->len
)
6080 skb_pull(chunk
->skb
, len
);
6085 /* Create an ABORT packet to be sent as a response, with the specified
6088 static struct sctp_packet
*sctp_abort_pkt_new(
6090 const struct sctp_endpoint
*ep
,
6091 const struct sctp_association
*asoc
,
6092 struct sctp_chunk
*chunk
,
6093 const void *payload
, size_t paylen
)
6095 struct sctp_packet
*packet
;
6096 struct sctp_chunk
*abort
;
6098 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
6102 * The T bit will be set if the asoc is NULL.
6104 abort
= sctp_make_abort(asoc
, chunk
, paylen
);
6106 sctp_ootb_pkt_free(packet
);
6110 /* Reflect vtag if T-Bit is set */
6111 if (sctp_test_T_bit(abort
))
6112 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
6114 /* Add specified error causes, i.e., payload, to the
6117 sctp_addto_chunk(abort
, paylen
, payload
);
6119 /* Set the skb to the belonging sock for accounting. */
6120 abort
->skb
->sk
= ep
->base
.sk
;
6122 sctp_packet_append_chunk(packet
, abort
);
6129 /* Allocate a packet for responding in the OOTB conditions. */
6130 static struct sctp_packet
*sctp_ootb_pkt_new(
6132 const struct sctp_association
*asoc
,
6133 const struct sctp_chunk
*chunk
)
6135 struct sctp_transport
*transport
;
6136 struct sctp_packet
*packet
;
6140 /* Get the source and destination port from the inbound packet. */
6141 sport
= ntohs(chunk
->sctp_hdr
->dest
);
6142 dport
= ntohs(chunk
->sctp_hdr
->source
);
6144 /* The V-tag is going to be the same as the inbound packet if no
6145 * association exists, otherwise, use the peer's vtag.
6148 /* Special case the INIT-ACK as there is no peer's vtag
6151 switch (chunk
->chunk_hdr
->type
) {
6152 case SCTP_CID_INIT_ACK
:
6154 struct sctp_initack_chunk
*initack
;
6156 initack
= (struct sctp_initack_chunk
*)chunk
->chunk_hdr
;
6157 vtag
= ntohl(initack
->init_hdr
.init_tag
);
6161 vtag
= asoc
->peer
.i
.init_tag
;
6165 /* Special case the INIT and stale COOKIE_ECHO as there is no
6168 switch (chunk
->chunk_hdr
->type
) {
6171 struct sctp_init_chunk
*init
;
6173 init
= (struct sctp_init_chunk
*)chunk
->chunk_hdr
;
6174 vtag
= ntohl(init
->init_hdr
.init_tag
);
6178 vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
6183 /* Make a transport for the bucket, Eliza... */
6184 transport
= sctp_transport_new(net
, sctp_source(chunk
), GFP_ATOMIC
);
6188 /* Cache a route for the transport with the chunk's destination as
6189 * the source address.
6191 sctp_transport_route(transport
, (union sctp_addr
*)&chunk
->dest
,
6192 sctp_sk(net
->sctp
.ctl_sock
));
6194 packet
= &transport
->packet
;
6195 sctp_packet_init(packet
, transport
, sport
, dport
);
6196 sctp_packet_config(packet
, vtag
, 0);
6204 /* Free the packet allocated earlier for responding in the OOTB condition. */
6205 void sctp_ootb_pkt_free(struct sctp_packet
*packet
)
6207 sctp_transport_free(packet
->transport
);
6210 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
6211 static void sctp_send_stale_cookie_err(struct net
*net
,
6212 const struct sctp_endpoint
*ep
,
6213 const struct sctp_association
*asoc
,
6214 const struct sctp_chunk
*chunk
,
6215 struct sctp_cmd_seq
*commands
,
6216 struct sctp_chunk
*err_chunk
)
6218 struct sctp_packet
*packet
;
6221 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
6223 struct sctp_signed_cookie
*cookie
;
6225 /* Override the OOTB vtag from the cookie. */
6226 cookie
= chunk
->subh
.cookie_hdr
;
6227 packet
->vtag
= cookie
->c
.peer_vtag
;
6229 /* Set the skb to the belonging sock for accounting. */
6230 err_chunk
->skb
->sk
= ep
->base
.sk
;
6231 sctp_packet_append_chunk(packet
, err_chunk
);
6232 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
6233 SCTP_PACKET(packet
));
6234 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
6236 sctp_chunk_free (err_chunk
);
6241 /* Process a data chunk */
6242 static int sctp_eat_data(const struct sctp_association
*asoc
,
6243 struct sctp_chunk
*chunk
,
6244 struct sctp_cmd_seq
*commands
)
6246 struct sctp_tsnmap
*map
= (struct sctp_tsnmap
*)&asoc
->peer
.tsn_map
;
6247 struct sock
*sk
= asoc
->base
.sk
;
6248 struct net
*net
= sock_net(sk
);
6249 struct sctp_datahdr
*data_hdr
;
6250 struct sctp_chunk
*err
;
6251 enum sctp_verb deliver
;
6258 data_hdr
= (struct sctp_datahdr
*)chunk
->skb
->data
;
6259 chunk
->subh
.data_hdr
= data_hdr
;
6260 skb_pull(chunk
->skb
, sizeof(*data_hdr
));
6262 tsn
= ntohl(data_hdr
->tsn
);
6263 pr_debug("%s: TSN 0x%x\n", __func__
, tsn
);
6265 /* ASSERT: Now skb->data is really the user data. */
6267 /* Process ECN based congestion.
6269 * Since the chunk structure is reused for all chunks within
6270 * a packet, we use ecn_ce_done to track if we've already
6271 * done CE processing for this packet.
6273 * We need to do ECN processing even if we plan to discard the
6277 if (asoc
->peer
.ecn_capable
&& !chunk
->ecn_ce_done
) {
6278 struct sctp_af
*af
= SCTP_INPUT_CB(chunk
->skb
)->af
;
6279 chunk
->ecn_ce_done
= 1;
6281 if (af
->is_ce(sctp_gso_headskb(chunk
->skb
))) {
6282 /* Do real work as sideffect. */
6283 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_CE
,
6288 tmp
= sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
);
6290 /* The TSN is too high--silently discard the chunk and
6291 * count on it getting retransmitted later.
6294 chunk
->asoc
->stats
.outofseqtsns
++;
6295 return SCTP_IERROR_HIGH_TSN
;
6296 } else if (tmp
> 0) {
6297 /* This is a duplicate. Record it. */
6298 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_DUP
, SCTP_U32(tsn
));
6299 return SCTP_IERROR_DUP_TSN
;
6302 /* This is a new TSN. */
6304 /* Discard if there is no room in the receive window.
6305 * Actually, allow a little bit of overflow (up to a MTU).
6307 datalen
= ntohs(chunk
->chunk_hdr
->length
);
6308 datalen
-= sizeof(struct sctp_data_chunk
);
6310 deliver
= SCTP_CMD_CHUNK_ULP
;
6312 /* Think about partial delivery. */
6313 if ((datalen
>= asoc
->rwnd
) && (!asoc
->ulpq
.pd_mode
)) {
6315 /* Even if we don't accept this chunk there is
6318 sctp_add_cmd_sf(commands
, SCTP_CMD_PART_DELIVER
, SCTP_NULL());
6321 /* Spill over rwnd a little bit. Note: While allowed, this spill over
6322 * seems a bit troublesome in that frag_point varies based on
6323 * PMTU. In cases, such as loopback, this might be a rather
6326 if ((!chunk
->data_accepted
) && (!asoc
->rwnd
|| asoc
->rwnd_over
||
6327 (datalen
> asoc
->rwnd
+ asoc
->frag_point
))) {
6329 /* If this is the next TSN, consider reneging to make
6330 * room. Note: Playing nice with a confused sender. A
6331 * malicious sender can still eat up all our buffer
6332 * space and in the future we may want to detect and
6333 * do more drastic reneging.
6335 if (sctp_tsnmap_has_gap(map
) &&
6336 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
6337 pr_debug("%s: reneging for tsn:%u\n", __func__
, tsn
);
6338 deliver
= SCTP_CMD_RENEGE
;
6340 pr_debug("%s: discard tsn:%u len:%zu, rwnd:%d\n",
6341 __func__
, tsn
, datalen
, asoc
->rwnd
);
6343 return SCTP_IERROR_IGNORE_TSN
;
6348 * Also try to renege to limit our memory usage in the event that
6349 * we are under memory pressure
6350 * If we can't renege, don't worry about it, the sk_rmem_schedule
6351 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
6352 * memory usage too much
6354 if (*sk
->sk_prot_creator
->memory_pressure
) {
6355 if (sctp_tsnmap_has_gap(map
) &&
6356 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
6357 pr_debug("%s: under pressure, reneging for tsn:%u\n",
6359 deliver
= SCTP_CMD_RENEGE
;
6364 * Section 3.3.10.9 No User Data (9)
6368 * No User Data: This error cause is returned to the originator of a
6369 * DATA chunk if a received DATA chunk has no user data.
6371 if (unlikely(0 == datalen
)) {
6372 err
= sctp_make_abort_no_data(asoc
, chunk
, tsn
);
6374 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6377 /* We are going to ABORT, so we might as well stop
6378 * processing the rest of the chunks in the packet.
6380 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
6381 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
6382 SCTP_ERROR(ECONNABORTED
));
6383 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
6384 SCTP_PERR(SCTP_ERROR_NO_DATA
));
6385 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
6386 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
6387 return SCTP_IERROR_NO_DATA
;
6390 chunk
->data_accepted
= 1;
6392 /* Note: Some chunks may get overcounted (if we drop) or overcounted
6393 * if we renege and the chunk arrives again.
6395 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_UNORDERED
) {
6396 SCTP_INC_STATS(net
, SCTP_MIB_INUNORDERCHUNKS
);
6398 chunk
->asoc
->stats
.iuodchunks
++;
6400 SCTP_INC_STATS(net
, SCTP_MIB_INORDERCHUNKS
);
6402 chunk
->asoc
->stats
.iodchunks
++;
6406 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
6408 * If an endpoint receive a DATA chunk with an invalid stream
6409 * identifier, it shall acknowledge the reception of the DATA chunk
6410 * following the normal procedure, immediately send an ERROR chunk
6411 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
6412 * and discard the DATA chunk.
6414 sid
= ntohs(data_hdr
->stream
);
6415 if (sid
>= asoc
->stream
.incnt
) {
6416 /* Mark tsn as received even though we drop it */
6417 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_TSN
, SCTP_U32(tsn
));
6419 err
= sctp_make_op_error(asoc
, chunk
, SCTP_ERROR_INV_STRM
,
6421 sizeof(data_hdr
->stream
),
6424 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6426 return SCTP_IERROR_BAD_STREAM
;
6429 /* Check to see if the SSN is possible for this TSN.
6430 * The biggest gap we can record is 4K wide. Since SSNs wrap
6431 * at an unsigned short, there is no way that an SSN can
6432 * wrap and for a valid TSN. We can simply check if the current
6433 * SSN is smaller then the next expected one. If it is, it wrapped
6436 ssn
= ntohs(data_hdr
->ssn
);
6437 if (ordered
&& SSN_lt(ssn
, sctp_ssn_peek(&asoc
->stream
, in
, sid
)))
6438 return SCTP_IERROR_PROTO_VIOLATION
;
6440 /* Send the data up to the user. Note: Schedule the
6441 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
6442 * chunk needs the updated rwnd.
6444 sctp_add_cmd_sf(commands
, deliver
, SCTP_CHUNK(chunk
));
6446 return SCTP_IERROR_NO_ERROR
;