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
;
3759 static enum sctp_disposition
sctp_send_next_asconf(
3761 const struct sctp_endpoint
*ep
,
3762 struct sctp_association
*asoc
,
3763 const union sctp_subtype type
,
3764 struct sctp_cmd_seq
*commands
)
3766 struct sctp_chunk
*asconf
;
3767 struct list_head
*entry
;
3769 if (list_empty(&asoc
->addip_chunk_list
))
3770 return SCTP_DISPOSITION_CONSUME
;
3772 entry
= asoc
->addip_chunk_list
.next
;
3773 asconf
= list_entry(entry
, struct sctp_chunk
, list
);
3775 list_del_init(entry
);
3776 sctp_chunk_hold(asconf
);
3777 asoc
->addip_last_asconf
= asconf
;
3779 return sctp_sf_do_prm_asconf(net
, ep
, asoc
, type
, asconf
, commands
);
3783 * ADDIP Section 4.3 General rules for address manipulation
3784 * When building TLV parameters for the ASCONF Chunk that will add or
3785 * delete IP addresses the D0 to D13 rules should be applied:
3787 enum sctp_disposition
sctp_sf_do_asconf_ack(struct net
*net
,
3788 const struct sctp_endpoint
*ep
,
3789 const struct sctp_association
*asoc
,
3790 const union sctp_subtype type
,
3792 struct sctp_cmd_seq
*commands
)
3794 struct sctp_chunk
*last_asconf
= asoc
->addip_last_asconf
;
3795 struct sctp_paramhdr
*err_param
= NULL
;
3796 struct sctp_chunk
*asconf_ack
= arg
;
3797 struct sctp_addiphdr
*addip_hdr
;
3798 __u32 sent_serial
, rcvd_serial
;
3799 struct sctp_chunk
*abort
;
3801 if (!sctp_vtag_verify(asconf_ack
, asoc
)) {
3802 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3804 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3807 /* ADD-IP, Section 4.1.2:
3808 * This chunk MUST be sent in an authenticated way by using
3809 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3810 * is received unauthenticated it MUST be silently discarded as
3811 * described in [I-D.ietf-tsvwg-sctp-auth].
3813 if (!net
->sctp
.addip_noauth
&& !asconf_ack
->auth
)
3814 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
,
3817 /* Make sure that the ADDIP chunk has a valid length. */
3818 if (!sctp_chunk_length_valid(asconf_ack
,
3819 sizeof(struct sctp_addip_chunk
)))
3820 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3823 addip_hdr
= (struct sctp_addiphdr
*)asconf_ack
->skb
->data
;
3824 rcvd_serial
= ntohl(addip_hdr
->serial
);
3826 /* Verify the ASCONF-ACK chunk before processing it. */
3827 if (!sctp_verify_asconf(asoc
, asconf_ack
, false, &err_param
))
3828 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3829 (void *)err_param
, commands
);
3832 addip_hdr
= (struct sctp_addiphdr
*)last_asconf
->subh
.addip_hdr
;
3833 sent_serial
= ntohl(addip_hdr
->serial
);
3835 sent_serial
= asoc
->addip_serial
- 1;
3838 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3839 * equal to the next serial number to be used but no ASCONF chunk is
3840 * outstanding the endpoint MUST ABORT the association. Note that a
3841 * sequence number is greater than if it is no more than 2^^31-1
3842 * larger than the current sequence number (using serial arithmetic).
3844 if (ADDIP_SERIAL_gte(rcvd_serial
, sent_serial
+ 1) &&
3845 !(asoc
->addip_last_asconf
)) {
3846 abort
= sctp_make_abort(asoc
, asconf_ack
,
3847 sizeof(struct sctp_errhdr
));
3849 sctp_init_cause(abort
, SCTP_ERROR_ASCONF_ACK
, 0);
3850 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3853 /* We are going to ABORT, so we might as well stop
3854 * processing the rest of the chunks in the packet.
3856 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3857 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3858 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
3859 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3860 SCTP_ERROR(ECONNABORTED
));
3861 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3862 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3863 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
3864 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3865 return SCTP_DISPOSITION_ABORT
;
3868 if ((rcvd_serial
== sent_serial
) && asoc
->addip_last_asconf
) {
3869 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3870 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3872 if (!sctp_process_asconf_ack((struct sctp_association
*)asoc
,
3874 return sctp_send_next_asconf(net
, ep
,
3875 (struct sctp_association
*)asoc
,
3878 abort
= sctp_make_abort(asoc
, asconf_ack
,
3879 sizeof(struct sctp_errhdr
));
3881 sctp_init_cause(abort
, SCTP_ERROR_RSRC_LOW
, 0);
3882 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3885 /* We are going to ABORT, so we might as well stop
3886 * processing the rest of the chunks in the packet.
3888 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
3889 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3890 SCTP_ERROR(ECONNABORTED
));
3891 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3892 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3893 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
3894 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3895 return SCTP_DISPOSITION_ABORT
;
3898 return SCTP_DISPOSITION_DISCARD
;
3901 /* RE-CONFIG Section 5.2 Upon reception of an RECONF Chunk. */
3902 enum sctp_disposition
sctp_sf_do_reconf(struct net
*net
,
3903 const struct sctp_endpoint
*ep
,
3904 const struct sctp_association
*asoc
,
3905 const union sctp_subtype type
,
3907 struct sctp_cmd_seq
*commands
)
3909 struct sctp_paramhdr
*err_param
= NULL
;
3910 struct sctp_chunk
*chunk
= arg
;
3911 struct sctp_reconf_chunk
*hdr
;
3912 union sctp_params param
;
3914 if (!sctp_vtag_verify(chunk
, asoc
)) {
3915 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3917 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3920 /* Make sure that the RECONF chunk has a valid length. */
3921 if (!sctp_chunk_length_valid(chunk
, sizeof(*hdr
)))
3922 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3925 if (!sctp_verify_reconf(asoc
, chunk
, &err_param
))
3926 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3927 (void *)err_param
, commands
);
3929 hdr
= (struct sctp_reconf_chunk
*)chunk
->chunk_hdr
;
3930 sctp_walk_params(param
, hdr
, params
) {
3931 struct sctp_chunk
*reply
= NULL
;
3932 struct sctp_ulpevent
*ev
= NULL
;
3934 if (param
.p
->type
== SCTP_PARAM_RESET_OUT_REQUEST
)
3935 reply
= sctp_process_strreset_outreq(
3936 (struct sctp_association
*)asoc
, param
, &ev
);
3937 else if (param
.p
->type
== SCTP_PARAM_RESET_IN_REQUEST
)
3938 reply
= sctp_process_strreset_inreq(
3939 (struct sctp_association
*)asoc
, param
, &ev
);
3940 else if (param
.p
->type
== SCTP_PARAM_RESET_TSN_REQUEST
)
3941 reply
= sctp_process_strreset_tsnreq(
3942 (struct sctp_association
*)asoc
, param
, &ev
);
3943 else if (param
.p
->type
== SCTP_PARAM_RESET_ADD_OUT_STREAMS
)
3944 reply
= sctp_process_strreset_addstrm_out(
3945 (struct sctp_association
*)asoc
, param
, &ev
);
3946 else if (param
.p
->type
== SCTP_PARAM_RESET_ADD_IN_STREAMS
)
3947 reply
= sctp_process_strreset_addstrm_in(
3948 (struct sctp_association
*)asoc
, param
, &ev
);
3949 else if (param
.p
->type
== SCTP_PARAM_RESET_RESPONSE
)
3950 reply
= sctp_process_strreset_resp(
3951 (struct sctp_association
*)asoc
, param
, &ev
);
3954 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
3958 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3962 return SCTP_DISPOSITION_CONSUME
;
3966 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3968 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3969 * its cumulative TSN point to the value carried in the FORWARD TSN
3970 * chunk, and then MUST further advance its cumulative TSN point locally
3972 * After the above processing, the data receiver MUST stop reporting any
3973 * missing TSNs earlier than or equal to the new cumulative TSN point.
3975 * Verification Tag: 8.5 Verification Tag [Normal verification]
3977 * The return value is the disposition of the chunk.
3979 enum sctp_disposition
sctp_sf_eat_fwd_tsn(struct net
*net
,
3980 const struct sctp_endpoint
*ep
,
3981 const struct sctp_association
*asoc
,
3982 const union sctp_subtype type
,
3984 struct sctp_cmd_seq
*commands
)
3986 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3987 struct sctp_chunk
*chunk
= arg
;
3988 struct sctp_fwdtsn_skip
*skip
;
3992 if (!sctp_vtag_verify(chunk
, asoc
)) {
3993 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3995 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3998 if (!asoc
->peer
.prsctp_capable
)
3999 return sctp_sf_unk_chunk(net
, ep
, asoc
, type
, arg
, commands
);
4001 /* Make sure that the FORWARD_TSN chunk has valid length. */
4002 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
4003 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4006 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
4007 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
4008 len
= ntohs(chunk
->chunk_hdr
->length
);
4009 len
-= sizeof(struct sctp_chunkhdr
);
4010 skb_pull(chunk
->skb
, len
);
4012 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
4013 pr_debug("%s: TSN 0x%x\n", __func__
, tsn
);
4015 /* The TSN is too high--silently discard the chunk and count on it
4016 * getting retransmitted later.
4018 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
4019 goto discard_noforce
;
4021 /* Silently discard the chunk if stream-id is not valid */
4022 sctp_walk_fwdtsn(skip
, chunk
) {
4023 if (ntohs(skip
->stream
) >= asoc
->stream
.incnt
)
4024 goto discard_noforce
;
4027 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
4028 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
4029 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
4032 /* Count this as receiving DATA. */
4033 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
]) {
4034 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
4035 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
4038 /* FIXME: For now send a SACK, but DATA processing may
4041 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
4043 return SCTP_DISPOSITION_CONSUME
;
4046 return SCTP_DISPOSITION_DISCARD
;
4049 enum sctp_disposition
sctp_sf_eat_fwd_tsn_fast(
4051 const struct sctp_endpoint
*ep
,
4052 const struct sctp_association
*asoc
,
4053 const union sctp_subtype type
,
4055 struct sctp_cmd_seq
*commands
)
4057 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
4058 struct sctp_chunk
*chunk
= arg
;
4059 struct sctp_fwdtsn_skip
*skip
;
4063 if (!sctp_vtag_verify(chunk
, asoc
)) {
4064 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
4066 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4069 if (!asoc
->peer
.prsctp_capable
)
4070 return sctp_sf_unk_chunk(net
, ep
, asoc
, type
, arg
, commands
);
4072 /* Make sure that the FORWARD_TSN chunk has a valid length. */
4073 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
4074 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4077 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
4078 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
4079 len
= ntohs(chunk
->chunk_hdr
->length
);
4080 len
-= sizeof(struct sctp_chunkhdr
);
4081 skb_pull(chunk
->skb
, len
);
4083 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
4084 pr_debug("%s: TSN 0x%x\n", __func__
, tsn
);
4086 /* The TSN is too high--silently discard the chunk and count on it
4087 * getting retransmitted later.
4089 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
4092 /* Silently discard the chunk if stream-id is not valid */
4093 sctp_walk_fwdtsn(skip
, chunk
) {
4094 if (ntohs(skip
->stream
) >= asoc
->stream
.incnt
)
4098 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
4099 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
4100 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
4103 /* Go a head and force a SACK, since we are shutting down. */
4105 /* Implementor's Guide.
4107 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
4108 * respond to each received packet containing one or more DATA chunk(s)
4109 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
4111 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
4112 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
4113 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
4114 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
4116 return SCTP_DISPOSITION_CONSUME
;
4120 * SCTP-AUTH Section 6.3 Receiving authenticated chukns
4122 * The receiver MUST use the HMAC algorithm indicated in the HMAC
4123 * Identifier field. If this algorithm was not specified by the
4124 * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk
4125 * during association setup, the AUTH chunk and all chunks after it MUST
4126 * be discarded and an ERROR chunk SHOULD be sent with the error cause
4127 * defined in Section 4.1.
4129 * If an endpoint with no shared key receives a Shared Key Identifier
4130 * other than 0, it MUST silently discard all authenticated chunks. If
4131 * the endpoint has at least one endpoint pair shared key for the peer,
4132 * it MUST use the key specified by the Shared Key Identifier if a
4133 * key has been configured for that Shared Key Identifier. If no
4134 * endpoint pair shared key has been configured for that Shared Key
4135 * Identifier, all authenticated chunks MUST be silently discarded.
4137 * Verification Tag: 8.5 Verification Tag [Normal verification]
4139 * The return value is the disposition of the chunk.
4141 static enum sctp_ierror
sctp_sf_authenticate(
4142 const struct sctp_association
*asoc
,
4143 struct sctp_chunk
*chunk
)
4145 struct sctp_authhdr
*auth_hdr
;
4146 __u8
*save_digest
, *digest
;
4147 struct sctp_hmac
*hmac
;
4148 unsigned int sig_len
;
4151 /* Pull in the auth header, so we can do some more verification */
4152 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
4153 chunk
->subh
.auth_hdr
= auth_hdr
;
4154 skb_pull(chunk
->skb
, sizeof(*auth_hdr
));
4156 /* Make sure that we support the HMAC algorithm from the auth
4159 if (!sctp_auth_asoc_verify_hmac_id(asoc
, auth_hdr
->hmac_id
))
4160 return SCTP_IERROR_AUTH_BAD_HMAC
;
4162 /* Make sure that the provided shared key identifier has been
4165 key_id
= ntohs(auth_hdr
->shkey_id
);
4166 if (key_id
!= asoc
->active_key_id
&& !sctp_auth_get_shkey(asoc
, key_id
))
4167 return SCTP_IERROR_AUTH_BAD_KEYID
;
4170 /* Make sure that the length of the signature matches what
4173 sig_len
= ntohs(chunk
->chunk_hdr
->length
) -
4174 sizeof(struct sctp_auth_chunk
);
4175 hmac
= sctp_auth_get_hmac(ntohs(auth_hdr
->hmac_id
));
4176 if (sig_len
!= hmac
->hmac_len
)
4177 return SCTP_IERROR_PROTO_VIOLATION
;
4179 /* Now that we've done validation checks, we can compute and
4180 * verify the hmac. The steps involved are:
4181 * 1. Save the digest from the chunk.
4182 * 2. Zero out the digest in the chunk.
4183 * 3. Compute the new digest
4184 * 4. Compare saved and new digests.
4186 digest
= auth_hdr
->hmac
;
4187 skb_pull(chunk
->skb
, sig_len
);
4189 save_digest
= kmemdup(digest
, sig_len
, GFP_ATOMIC
);
4193 memset(digest
, 0, sig_len
);
4195 sctp_auth_calculate_hmac(asoc
, chunk
->skb
,
4196 (struct sctp_auth_chunk
*)chunk
->chunk_hdr
,
4199 /* Discard the packet if the digests do not match */
4200 if (memcmp(save_digest
, digest
, sig_len
)) {
4202 return SCTP_IERROR_BAD_SIG
;
4208 return SCTP_IERROR_NO_ERROR
;
4210 return SCTP_IERROR_NOMEM
;
4213 enum sctp_disposition
sctp_sf_eat_auth(struct net
*net
,
4214 const struct sctp_endpoint
*ep
,
4215 const struct sctp_association
*asoc
,
4216 const union sctp_subtype type
,
4217 void *arg
, struct sctp_cmd_seq
*commands
)
4219 struct sctp_chunk
*chunk
= arg
;
4220 struct sctp_authhdr
*auth_hdr
;
4221 struct sctp_chunk
*err_chunk
;
4222 enum sctp_ierror error
;
4224 /* Make sure that the peer has AUTH capable */
4225 if (!asoc
->peer
.auth_capable
)
4226 return sctp_sf_unk_chunk(net
, ep
, asoc
, type
, arg
, commands
);
4228 if (!sctp_vtag_verify(chunk
, asoc
)) {
4229 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
4231 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4234 /* Make sure that the AUTH chunk has valid length. */
4235 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_auth_chunk
)))
4236 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4239 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
4240 error
= sctp_sf_authenticate(asoc
, chunk
);
4242 case SCTP_IERROR_AUTH_BAD_HMAC
:
4243 /* Generate the ERROR chunk and discard the rest
4246 err_chunk
= sctp_make_op_error(asoc
, chunk
,
4247 SCTP_ERROR_UNSUP_HMAC
,
4251 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4252 SCTP_CHUNK(err_chunk
));
4255 case SCTP_IERROR_AUTH_BAD_KEYID
:
4256 case SCTP_IERROR_BAD_SIG
:
4257 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4259 case SCTP_IERROR_PROTO_VIOLATION
:
4260 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4263 case SCTP_IERROR_NOMEM
:
4264 return SCTP_DISPOSITION_NOMEM
;
4266 default: /* Prevent gcc warnings */
4270 if (asoc
->active_key_id
!= ntohs(auth_hdr
->shkey_id
)) {
4271 struct sctp_ulpevent
*ev
;
4273 ev
= sctp_ulpevent_make_authkey(asoc
, ntohs(auth_hdr
->shkey_id
),
4274 SCTP_AUTH_NEWKEY
, GFP_ATOMIC
);
4279 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
4283 return SCTP_DISPOSITION_CONSUME
;
4287 * Process an unknown chunk.
4289 * Section: 3.2. Also, 2.1 in the implementor's guide.
4291 * Chunk Types are encoded such that the highest-order two bits specify
4292 * the action that must be taken if the processing endpoint does not
4293 * recognize the Chunk Type.
4295 * 00 - Stop processing this SCTP packet and discard it, do not process
4296 * any further chunks within it.
4298 * 01 - Stop processing this SCTP packet and discard it, do not process
4299 * any further chunks within it, and report the unrecognized
4300 * chunk in an 'Unrecognized Chunk Type'.
4302 * 10 - Skip this chunk and continue processing.
4304 * 11 - Skip this chunk and continue processing, but report in an ERROR
4305 * Chunk using the 'Unrecognized Chunk Type' cause of error.
4307 * The return value is the disposition of the chunk.
4309 enum sctp_disposition
sctp_sf_unk_chunk(struct net
*net
,
4310 const struct sctp_endpoint
*ep
,
4311 const struct sctp_association
*asoc
,
4312 const union sctp_subtype type
,
4314 struct sctp_cmd_seq
*commands
)
4316 struct sctp_chunk
*unk_chunk
= arg
;
4317 struct sctp_chunk
*err_chunk
;
4318 struct sctp_chunkhdr
*hdr
;
4320 pr_debug("%s: processing unknown chunk id:%d\n", __func__
, type
.chunk
);
4322 if (!sctp_vtag_verify(unk_chunk
, asoc
))
4323 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4325 /* Make sure that the chunk has a valid length.
4326 * Since we don't know the chunk type, we use a general
4327 * chunkhdr structure to make a comparison.
4329 if (!sctp_chunk_length_valid(unk_chunk
, sizeof(*hdr
)))
4330 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4333 switch (type
.chunk
& SCTP_CID_ACTION_MASK
) {
4334 case SCTP_CID_ACTION_DISCARD
:
4335 /* Discard the packet. */
4336 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4337 case SCTP_CID_ACTION_DISCARD_ERR
:
4338 /* Generate an ERROR chunk as response. */
4339 hdr
= unk_chunk
->chunk_hdr
;
4340 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4341 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4342 SCTP_PAD4(ntohs(hdr
->length
)),
4345 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4346 SCTP_CHUNK(err_chunk
));
4349 /* Discard the packet. */
4350 sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4351 return SCTP_DISPOSITION_CONSUME
;
4352 case SCTP_CID_ACTION_SKIP
:
4353 /* Skip the chunk. */
4354 return SCTP_DISPOSITION_DISCARD
;
4355 case SCTP_CID_ACTION_SKIP_ERR
:
4356 /* Generate an ERROR chunk as response. */
4357 hdr
= unk_chunk
->chunk_hdr
;
4358 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4359 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4360 SCTP_PAD4(ntohs(hdr
->length
)),
4363 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4364 SCTP_CHUNK(err_chunk
));
4366 /* Skip the chunk. */
4367 return SCTP_DISPOSITION_CONSUME
;
4372 return SCTP_DISPOSITION_DISCARD
;
4376 * Discard the chunk.
4378 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
4379 * [Too numerous to mention...]
4380 * Verification Tag: No verification needed.
4382 * (endpoint, asoc, chunk)
4385 * (asoc, reply_msg, msg_up, timers, counters)
4387 * The return value is the disposition of the chunk.
4389 enum sctp_disposition
sctp_sf_discard_chunk(struct net
*net
,
4390 const struct sctp_endpoint
*ep
,
4391 const struct sctp_association
*asoc
,
4392 const union sctp_subtype type
,
4394 struct sctp_cmd_seq
*commands
)
4396 struct sctp_chunk
*chunk
= arg
;
4398 /* Make sure that the chunk has a valid length.
4399 * Since we don't know the chunk type, we use a general
4400 * chunkhdr structure to make a comparison.
4402 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
4403 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4406 pr_debug("%s: chunk:%d is discarded\n", __func__
, type
.chunk
);
4408 return SCTP_DISPOSITION_DISCARD
;
4412 * Discard the whole packet.
4416 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
4417 * silently discard the OOTB packet and take no further action.
4419 * Verification Tag: No verification necessary
4422 * (endpoint, asoc, chunk)
4425 * (asoc, reply_msg, msg_up, timers, counters)
4427 * The return value is the disposition of the chunk.
4429 enum sctp_disposition
sctp_sf_pdiscard(struct net
*net
,
4430 const struct sctp_endpoint
*ep
,
4431 const struct sctp_association
*asoc
,
4432 const union sctp_subtype type
,
4433 void *arg
, struct sctp_cmd_seq
*commands
)
4435 SCTP_INC_STATS(net
, SCTP_MIB_IN_PKT_DISCARDS
);
4436 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
4438 return SCTP_DISPOSITION_CONSUME
;
4443 * The other end is violating protocol.
4445 * Section: Not specified
4446 * Verification Tag: Not specified
4448 * (endpoint, asoc, chunk)
4451 * (asoc, reply_msg, msg_up, timers, counters)
4453 * We simply tag the chunk as a violation. The state machine will log
4454 * the violation and continue.
4456 enum sctp_disposition
sctp_sf_violation(struct net
*net
,
4457 const struct sctp_endpoint
*ep
,
4458 const struct sctp_association
*asoc
,
4459 const union sctp_subtype type
,
4461 struct sctp_cmd_seq
*commands
)
4463 struct sctp_chunk
*chunk
= arg
;
4465 /* Make sure that the chunk has a valid length. */
4466 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
4467 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4470 return SCTP_DISPOSITION_VIOLATION
;
4474 * Common function to handle a protocol violation.
4476 static enum sctp_disposition
sctp_sf_abort_violation(
4478 const struct sctp_endpoint
*ep
,
4479 const struct sctp_association
*asoc
,
4481 struct sctp_cmd_seq
*commands
,
4482 const __u8
*payload
,
4483 const size_t paylen
)
4485 struct sctp_packet
*packet
= NULL
;
4486 struct sctp_chunk
*chunk
= arg
;
4487 struct sctp_chunk
*abort
= NULL
;
4489 /* SCTP-AUTH, Section 6.3:
4490 * It should be noted that if the receiver wants to tear
4491 * down an association in an authenticated way only, the
4492 * handling of malformed packets should not result in
4493 * tearing down the association.
4495 * This means that if we only want to abort associations
4496 * in an authenticated way (i.e AUTH+ABORT), then we
4497 * can't destroy this association just because the packet
4500 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4503 /* Make the abort chunk. */
4504 abort
= sctp_make_abort_violation(asoc
, chunk
, payload
, paylen
);
4509 /* Treat INIT-ACK as a special case during COOKIE-WAIT. */
4510 if (chunk
->chunk_hdr
->type
== SCTP_CID_INIT_ACK
&&
4511 !asoc
->peer
.i
.init_tag
) {
4512 struct sctp_initack_chunk
*initack
;
4514 initack
= (struct sctp_initack_chunk
*)chunk
->chunk_hdr
;
4515 if (!sctp_chunk_length_valid(chunk
, sizeof(*initack
)))
4516 abort
->chunk_hdr
->flags
|= SCTP_CHUNK_FLAG_T
;
4518 unsigned int inittag
;
4520 inittag
= ntohl(initack
->init_hdr
.init_tag
);
4521 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_INITTAG
,
4526 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4527 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4529 if (asoc
->state
<= SCTP_STATE_COOKIE_ECHOED
) {
4530 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4531 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4532 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4533 SCTP_ERROR(ECONNREFUSED
));
4534 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4535 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4537 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4538 SCTP_ERROR(ECONNABORTED
));
4539 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4540 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4541 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4544 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
4549 if (sctp_test_T_bit(abort
))
4550 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
4552 abort
->skb
->sk
= ep
->base
.sk
;
4554 sctp_packet_append_chunk(packet
, abort
);
4556 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
4557 SCTP_PACKET(packet
));
4559 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4562 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4565 sctp_sf_pdiscard(net
, ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4566 return SCTP_DISPOSITION_ABORT
;
4569 sctp_chunk_free(abort
);
4571 return SCTP_DISPOSITION_NOMEM
;
4575 * Handle a protocol violation when the chunk length is invalid.
4576 * "Invalid" length is identified as smaller than the minimal length a
4577 * given chunk can be. For example, a SACK chunk has invalid length
4578 * if its length is set to be smaller than the size of struct sctp_sack_chunk.
4580 * We inform the other end by sending an ABORT with a Protocol Violation
4583 * Section: Not specified
4584 * Verification Tag: Nothing to do
4586 * (endpoint, asoc, chunk)
4589 * (reply_msg, msg_up, counters)
4591 * Generate an ABORT chunk and terminate the association.
4593 static enum sctp_disposition
sctp_sf_violation_chunklen(
4595 const struct sctp_endpoint
*ep
,
4596 const struct sctp_association
*asoc
,
4597 const union sctp_subtype type
,
4599 struct sctp_cmd_seq
*commands
)
4601 static const char err_str
[] = "The following chunk had invalid length:";
4603 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4608 * Handle a protocol violation when the parameter length is invalid.
4609 * If the length is smaller than the minimum length of a given parameter,
4610 * or accumulated length in multi parameters exceeds the end of the chunk,
4611 * the length is considered as invalid.
4613 static enum sctp_disposition
sctp_sf_violation_paramlen(
4615 const struct sctp_endpoint
*ep
,
4616 const struct sctp_association
*asoc
,
4617 const union sctp_subtype type
,
4618 void *arg
, void *ext
,
4619 struct sctp_cmd_seq
*commands
)
4621 struct sctp_paramhdr
*param
= ext
;
4622 struct sctp_chunk
*abort
= NULL
;
4623 struct sctp_chunk
*chunk
= arg
;
4625 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4628 /* Make the abort chunk. */
4629 abort
= sctp_make_violation_paramlen(asoc
, chunk
, param
);
4633 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4634 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4636 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4637 SCTP_ERROR(ECONNABORTED
));
4638 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4639 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4640 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4641 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4644 sctp_sf_pdiscard(net
, ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4645 return SCTP_DISPOSITION_ABORT
;
4647 return SCTP_DISPOSITION_NOMEM
;
4650 /* Handle a protocol violation when the peer trying to advance the
4651 * cumulative tsn ack to a point beyond the max tsn currently sent.
4653 * We inform the other end by sending an ABORT with a Protocol Violation
4656 static enum sctp_disposition
sctp_sf_violation_ctsn(
4658 const struct sctp_endpoint
*ep
,
4659 const struct sctp_association
*asoc
,
4660 const union sctp_subtype type
,
4662 struct sctp_cmd_seq
*commands
)
4664 static const char err_str
[] = "The cumulative tsn ack beyond the max tsn currently sent:";
4666 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4670 /* Handle protocol violation of an invalid chunk bundling. For example,
4671 * when we have an association and we receive bundled INIT-ACK, or
4672 * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle"
4673 * statement from the specs. Additionally, there might be an attacker
4674 * on the path and we may not want to continue this communication.
4676 static enum sctp_disposition
sctp_sf_violation_chunk(
4678 const struct sctp_endpoint
*ep
,
4679 const struct sctp_association
*asoc
,
4680 const union sctp_subtype type
,
4682 struct sctp_cmd_seq
*commands
)
4684 static const char err_str
[] = "The following chunk violates protocol:";
4687 return sctp_sf_violation(net
, ep
, asoc
, type
, arg
, commands
);
4689 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4692 /***************************************************************************
4693 * These are the state functions for handling primitive (Section 10) events.
4694 ***************************************************************************/
4696 * sctp_sf_do_prm_asoc
4698 * Section: 10.1 ULP-to-SCTP
4701 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
4702 * outbound stream count)
4703 * -> association id [,destination transport addr list] [,outbound stream
4706 * This primitive allows the upper layer to initiate an association to a
4707 * specific peer endpoint.
4709 * The peer endpoint shall be specified by one of the transport addresses
4710 * which defines the endpoint (see Section 1.4). If the local SCTP
4711 * instance has not been initialized, the ASSOCIATE is considered an
4713 * [This is not relevant for the kernel implementation since we do all
4714 * initialization at boot time. It we hadn't initialized we wouldn't
4715 * get anywhere near this code.]
4717 * An association id, which is a local handle to the SCTP association,
4718 * will be returned on successful establishment of the association. If
4719 * SCTP is not able to open an SCTP association with the peer endpoint,
4720 * an error is returned.
4721 * [In the kernel implementation, the struct sctp_association needs to
4722 * be created BEFORE causing this primitive to run.]
4724 * Other association parameters may be returned, including the
4725 * complete destination transport addresses of the peer as well as the
4726 * outbound stream count of the local endpoint. One of the transport
4727 * address from the returned destination addresses will be selected by
4728 * the local endpoint as default primary path for sending SCTP packets
4729 * to this peer. The returned "destination transport addr list" can
4730 * be used by the ULP to change the default primary path or to force
4731 * sending a packet to a specific transport address. [All of this
4732 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
4735 * Mandatory attributes:
4737 * o local SCTP instance name - obtained from the INITIALIZE operation.
4738 * [This is the argument asoc.]
4739 * o destination transport addr - specified as one of the transport
4740 * addresses of the peer endpoint with which the association is to be
4742 * [This is asoc->peer.active_path.]
4743 * o outbound stream count - the number of outbound streams the ULP
4744 * would like to open towards this peer endpoint.
4745 * [BUG: This is not currently implemented.]
4746 * Optional attributes:
4750 * The return value is a disposition.
4752 enum sctp_disposition
sctp_sf_do_prm_asoc(struct net
*net
,
4753 const struct sctp_endpoint
*ep
,
4754 const struct sctp_association
*asoc
,
4755 const union sctp_subtype type
,
4757 struct sctp_cmd_seq
*commands
)
4759 struct sctp_association
*my_asoc
;
4760 struct sctp_chunk
*repl
;
4762 /* The comment below says that we enter COOKIE-WAIT AFTER
4763 * sending the INIT, but that doesn't actually work in our
4766 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4767 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
4769 /* RFC 2960 5.1 Normal Establishment of an Association
4771 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
4772 * must provide its Verification Tag (Tag_A) in the Initiate
4773 * Tag field. Tag_A SHOULD be a random number in the range of
4774 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
4777 repl
= sctp_make_init(asoc
, &asoc
->base
.bind_addr
, GFP_ATOMIC
, 0);
4781 /* Choose transport for INIT. */
4782 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
4785 /* Cast away the const modifier, as we want to just
4786 * rerun it through as a sideffect.
4788 my_asoc
= (struct sctp_association
*)asoc
;
4789 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(my_asoc
));
4791 /* After sending the INIT, "A" starts the T1-init timer and
4792 * enters the COOKIE-WAIT state.
4794 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4795 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4796 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
4797 return SCTP_DISPOSITION_CONSUME
;
4800 return SCTP_DISPOSITION_NOMEM
;
4804 * Process the SEND primitive.
4806 * Section: 10.1 ULP-to-SCTP
4809 * Format: SEND(association id, buffer address, byte count [,context]
4810 * [,stream id] [,life time] [,destination transport address]
4811 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
4814 * This is the main method to send user data via SCTP.
4816 * Mandatory attributes:
4818 * o association id - local handle to the SCTP association
4820 * o buffer address - the location where the user message to be
4821 * transmitted is stored;
4823 * o byte count - The size of the user data in number of bytes;
4825 * Optional attributes:
4827 * o context - an optional 32 bit integer that will be carried in the
4828 * sending failure notification to the ULP if the transportation of
4829 * this User Message fails.
4831 * o stream id - to indicate which stream to send the data on. If not
4832 * specified, stream 0 will be used.
4834 * o life time - specifies the life time of the user data. The user data
4835 * will not be sent by SCTP after the life time expires. This
4836 * parameter can be used to avoid efforts to transmit stale
4837 * user messages. SCTP notifies the ULP if the data cannot be
4838 * initiated to transport (i.e. sent to the destination via SCTP's
4839 * send primitive) within the life time variable. However, the
4840 * user data will be transmitted if SCTP has attempted to transmit a
4841 * chunk before the life time expired.
4843 * o destination transport address - specified as one of the destination
4844 * transport addresses of the peer endpoint to which this packet
4845 * should be sent. Whenever possible, SCTP should use this destination
4846 * transport address for sending the packets, instead of the current
4849 * o unorder flag - this flag, if present, indicates that the user
4850 * would like the data delivered in an unordered fashion to the peer
4851 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
4854 * o no-bundle flag - instructs SCTP not to bundle this user data with
4855 * other outbound DATA chunks. SCTP MAY still bundle even when
4856 * this flag is present, when faced with network congestion.
4858 * o payload protocol-id - A 32 bit unsigned integer that is to be
4859 * passed to the peer indicating the type of payload protocol data
4860 * being transmitted. This value is passed as opaque data by SCTP.
4862 * The return value is the disposition.
4864 enum sctp_disposition
sctp_sf_do_prm_send(struct net
*net
,
4865 const struct sctp_endpoint
*ep
,
4866 const struct sctp_association
*asoc
,
4867 const union sctp_subtype type
,
4869 struct sctp_cmd_seq
*commands
)
4871 struct sctp_datamsg
*msg
= arg
;
4873 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_MSG
, SCTP_DATAMSG(msg
));
4874 return SCTP_DISPOSITION_CONSUME
;
4878 * Process the SHUTDOWN primitive.
4883 * Format: SHUTDOWN(association id)
4886 * Gracefully closes an association. Any locally queued user data
4887 * will be delivered to the peer. The association will be terminated only
4888 * after the peer acknowledges all the SCTP packets sent. A success code
4889 * will be returned on successful termination of the association. If
4890 * attempting to terminate the association results in a failure, an error
4891 * code shall be returned.
4893 * Mandatory attributes:
4895 * o association id - local handle to the SCTP association
4897 * Optional attributes:
4901 * The return value is the disposition.
4903 enum sctp_disposition
sctp_sf_do_9_2_prm_shutdown(
4905 const struct sctp_endpoint
*ep
,
4906 const struct sctp_association
*asoc
,
4907 const union sctp_subtype type
,
4909 struct sctp_cmd_seq
*commands
)
4911 enum sctp_disposition disposition
;
4913 /* From 9.2 Shutdown of an Association
4914 * Upon receipt of the SHUTDOWN primitive from its upper
4915 * layer, the endpoint enters SHUTDOWN-PENDING state and
4916 * remains there until all outstanding data has been
4917 * acknowledged by its peer. The endpoint accepts no new data
4918 * from its upper layer, but retransmits data to the far end
4919 * if necessary to fill gaps.
4921 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4922 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
4924 disposition
= SCTP_DISPOSITION_CONSUME
;
4925 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
4926 disposition
= sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
, type
,
4934 * Process the ABORT primitive.
4939 * Format: Abort(association id [, cause code])
4942 * Ungracefully closes an association. Any locally queued user data
4943 * will be discarded and an ABORT chunk is sent to the peer. A success code
4944 * will be returned on successful abortion of the association. If
4945 * attempting to abort the association results in a failure, an error
4946 * code shall be returned.
4948 * Mandatory attributes:
4950 * o association id - local handle to the SCTP association
4952 * Optional attributes:
4954 * o cause code - reason of the abort to be passed to the peer
4958 * The return value is the disposition.
4960 enum sctp_disposition
sctp_sf_do_9_1_prm_abort(
4962 const struct sctp_endpoint
*ep
,
4963 const struct sctp_association
*asoc
,
4964 const union sctp_subtype type
,
4966 struct sctp_cmd_seq
*commands
)
4968 /* From 9.1 Abort of an Association
4969 * Upon receipt of the ABORT primitive from its upper
4970 * layer, the endpoint enters CLOSED state and
4971 * discard all outstanding data has been
4972 * acknowledged by its peer. The endpoint accepts no new data
4973 * from its upper layer, but retransmits data to the far end
4974 * if necessary to fill gaps.
4976 struct sctp_chunk
*abort
= arg
;
4979 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4981 /* Even if we can't send the ABORT due to low memory delete the
4982 * TCB. This is a departure from our typical NOMEM handling.
4985 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4986 SCTP_ERROR(ECONNABORTED
));
4987 /* Delete the established association. */
4988 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4989 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4991 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4992 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4994 return SCTP_DISPOSITION_ABORT
;
4997 /* We tried an illegal operation on an association which is closed. */
4998 enum sctp_disposition
sctp_sf_error_closed(struct net
*net
,
4999 const struct sctp_endpoint
*ep
,
5000 const struct sctp_association
*asoc
,
5001 const union sctp_subtype type
,
5003 struct sctp_cmd_seq
*commands
)
5005 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
, SCTP_ERROR(-EINVAL
));
5006 return SCTP_DISPOSITION_CONSUME
;
5009 /* We tried an illegal operation on an association which is shutting
5012 enum sctp_disposition
sctp_sf_error_shutdown(
5014 const struct sctp_endpoint
*ep
,
5015 const struct sctp_association
*asoc
,
5016 const union sctp_subtype type
,
5018 struct sctp_cmd_seq
*commands
)
5020 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
,
5021 SCTP_ERROR(-ESHUTDOWN
));
5022 return SCTP_DISPOSITION_CONSUME
;
5026 * sctp_cookie_wait_prm_shutdown
5028 * Section: 4 Note: 2
5033 * The RFC does not explicitly address this issue, but is the route through the
5034 * state table when someone issues a shutdown while in COOKIE_WAIT state.
5039 enum sctp_disposition
sctp_sf_cookie_wait_prm_shutdown(
5041 const struct sctp_endpoint
*ep
,
5042 const struct sctp_association
*asoc
,
5043 const union sctp_subtype type
,
5045 struct sctp_cmd_seq
*commands
)
5047 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5048 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5050 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5051 SCTP_STATE(SCTP_STATE_CLOSED
));
5053 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
5055 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
5057 return SCTP_DISPOSITION_DELETE_TCB
;
5061 * sctp_cookie_echoed_prm_shutdown
5063 * Section: 4 Note: 2
5068 * The RFC does not explcitly address this issue, but is the route through the
5069 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
5074 enum sctp_disposition
sctp_sf_cookie_echoed_prm_shutdown(
5076 const struct sctp_endpoint
*ep
,
5077 const struct sctp_association
*asoc
,
5078 const union sctp_subtype type
,
5080 struct sctp_cmd_seq
*commands
)
5082 /* There is a single T1 timer, so we should be able to use
5083 * common function with the COOKIE-WAIT state.
5085 return sctp_sf_cookie_wait_prm_shutdown(net
, ep
, asoc
, type
, arg
, commands
);
5089 * sctp_sf_cookie_wait_prm_abort
5091 * Section: 4 Note: 2
5096 * The RFC does not explicitly address this issue, but is the route through the
5097 * state table when someone issues an abort while in COOKIE_WAIT state.
5102 enum sctp_disposition
sctp_sf_cookie_wait_prm_abort(
5104 const struct sctp_endpoint
*ep
,
5105 const struct sctp_association
*asoc
,
5106 const union sctp_subtype type
,
5108 struct sctp_cmd_seq
*commands
)
5110 struct sctp_chunk
*abort
= arg
;
5112 /* Stop T1-init timer */
5113 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5114 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5117 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
5119 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5120 SCTP_STATE(SCTP_STATE_CLOSED
));
5122 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5124 /* Even if we can't send the ABORT due to low memory delete the
5125 * TCB. This is a departure from our typical NOMEM handling.
5128 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5129 SCTP_ERROR(ECONNREFUSED
));
5130 /* Delete the established association. */
5131 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5132 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
5134 return SCTP_DISPOSITION_ABORT
;
5138 * sctp_sf_cookie_echoed_prm_abort
5140 * Section: 4 Note: 3
5145 * The RFC does not explcitly address this issue, but is the route through the
5146 * state table when someone issues an abort while in COOKIE_ECHOED state.
5151 enum sctp_disposition
sctp_sf_cookie_echoed_prm_abort(
5153 const struct sctp_endpoint
*ep
,
5154 const struct sctp_association
*asoc
,
5155 const union sctp_subtype type
,
5157 struct sctp_cmd_seq
*commands
)
5159 /* There is a single T1 timer, so we should be able to use
5160 * common function with the COOKIE-WAIT state.
5162 return sctp_sf_cookie_wait_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5166 * sctp_sf_shutdown_pending_prm_abort
5171 * The RFC does not explicitly address this issue, but is the route through the
5172 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
5177 enum sctp_disposition
sctp_sf_shutdown_pending_prm_abort(
5179 const struct sctp_endpoint
*ep
,
5180 const struct sctp_association
*asoc
,
5181 const union sctp_subtype type
,
5183 struct sctp_cmd_seq
*commands
)
5185 /* Stop the T5-shutdown guard timer. */
5186 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5187 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5189 return sctp_sf_do_9_1_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5193 * sctp_sf_shutdown_sent_prm_abort
5198 * The RFC does not explicitly address this issue, but is the route through the
5199 * state table when someone issues an abort while in SHUTDOWN-SENT state.
5204 enum sctp_disposition
sctp_sf_shutdown_sent_prm_abort(
5206 const struct sctp_endpoint
*ep
,
5207 const struct sctp_association
*asoc
,
5208 const union sctp_subtype type
,
5210 struct sctp_cmd_seq
*commands
)
5212 /* Stop the T2-shutdown timer. */
5213 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5214 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5216 /* Stop the T5-shutdown guard timer. */
5217 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5218 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5220 return sctp_sf_do_9_1_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5224 * sctp_sf_cookie_echoed_prm_abort
5229 * The RFC does not explcitly address this issue, but is the route through the
5230 * state table when someone issues an abort while in COOKIE_ECHOED state.
5235 enum sctp_disposition
sctp_sf_shutdown_ack_sent_prm_abort(
5237 const struct sctp_endpoint
*ep
,
5238 const struct sctp_association
*asoc
,
5239 const union sctp_subtype type
,
5241 struct sctp_cmd_seq
*commands
)
5243 /* The same T2 timer, so we should be able to use
5244 * common function with the SHUTDOWN-SENT state.
5246 return sctp_sf_shutdown_sent_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5250 * Process the REQUESTHEARTBEAT primitive
5253 * J) Request Heartbeat
5255 * Format: REQUESTHEARTBEAT(association id, destination transport address)
5259 * Instructs the local endpoint to perform a HeartBeat on the specified
5260 * destination transport address of the given association. The returned
5261 * result should indicate whether the transmission of the HEARTBEAT
5262 * chunk to the destination address is successful.
5264 * Mandatory attributes:
5266 * o association id - local handle to the SCTP association
5268 * o destination transport address - the transport address of the
5269 * association on which a heartbeat should be issued.
5271 enum sctp_disposition
sctp_sf_do_prm_requestheartbeat(
5273 const struct sctp_endpoint
*ep
,
5274 const struct sctp_association
*asoc
,
5275 const union sctp_subtype type
,
5277 struct sctp_cmd_seq
*commands
)
5279 if (SCTP_DISPOSITION_NOMEM
== sctp_sf_heartbeat(ep
, asoc
, type
,
5280 (struct sctp_transport
*)arg
, commands
))
5281 return SCTP_DISPOSITION_NOMEM
;
5284 * RFC 2960 (bis), section 8.3
5286 * D) Request an on-demand HEARTBEAT on a specific destination
5287 * transport address of a given association.
5289 * The endpoint should increment the respective error counter of
5290 * the destination transport address each time a HEARTBEAT is sent
5291 * to that address and not acknowledged within one RTO.
5294 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
5295 SCTP_TRANSPORT(arg
));
5296 return SCTP_DISPOSITION_CONSUME
;
5300 * ADDIP Section 4.1 ASCONF Chunk Procedures
5301 * When an endpoint has an ASCONF signaled change to be sent to the
5302 * remote endpoint it should do A1 to A9
5304 enum sctp_disposition
sctp_sf_do_prm_asconf(struct net
*net
,
5305 const struct sctp_endpoint
*ep
,
5306 const struct sctp_association
*asoc
,
5307 const union sctp_subtype type
,
5309 struct sctp_cmd_seq
*commands
)
5311 struct sctp_chunk
*chunk
= arg
;
5313 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5314 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5315 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5316 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
5317 return SCTP_DISPOSITION_CONSUME
;
5320 /* RE-CONFIG Section 5.1 RECONF Chunk Procedures */
5321 enum sctp_disposition
sctp_sf_do_prm_reconf(struct net
*net
,
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 struct sctp_chunk
*chunk
= arg
;
5330 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
5331 return SCTP_DISPOSITION_CONSUME
;
5335 * Ignore the primitive event
5337 * The return value is the disposition of the primitive.
5339 enum sctp_disposition
sctp_sf_ignore_primitive(
5341 const struct sctp_endpoint
*ep
,
5342 const struct sctp_association
*asoc
,
5343 const union sctp_subtype type
,
5345 struct sctp_cmd_seq
*commands
)
5347 pr_debug("%s: primitive type:%d is ignored\n", __func__
,
5350 return SCTP_DISPOSITION_DISCARD
;
5353 /***************************************************************************
5354 * These are the state functions for the OTHER events.
5355 ***************************************************************************/
5358 * When the SCTP stack has no more user data to send or retransmit, this
5359 * notification is given to the user. Also, at the time when a user app
5360 * subscribes to this event, if there is no data to be sent or
5361 * retransmit, the stack will immediately send up this notification.
5363 enum sctp_disposition
sctp_sf_do_no_pending_tsn(
5365 const struct sctp_endpoint
*ep
,
5366 const struct sctp_association
*asoc
,
5367 const union sctp_subtype type
,
5369 struct sctp_cmd_seq
*commands
)
5371 struct sctp_ulpevent
*event
;
5373 event
= sctp_ulpevent_make_sender_dry_event(asoc
, GFP_ATOMIC
);
5375 return SCTP_DISPOSITION_NOMEM
;
5377 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(event
));
5379 return SCTP_DISPOSITION_CONSUME
;
5383 * Start the shutdown negotiation.
5386 * Once all its outstanding data has been acknowledged, the endpoint
5387 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
5388 * TSN Ack field the last sequential TSN it has received from the peer.
5389 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
5390 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
5391 * with the updated last sequential TSN received from its peer.
5393 * The return value is the disposition.
5395 enum sctp_disposition
sctp_sf_do_9_2_start_shutdown(
5397 const struct sctp_endpoint
*ep
,
5398 const struct sctp_association
*asoc
,
5399 const union sctp_subtype type
,
5401 struct sctp_cmd_seq
*commands
)
5403 struct sctp_chunk
*reply
;
5405 /* Once all its outstanding data has been acknowledged, the
5406 * endpoint shall send a SHUTDOWN chunk to its peer including
5407 * in the Cumulative TSN Ack field the last sequential TSN it
5408 * has received from the peer.
5410 reply
= sctp_make_shutdown(asoc
, NULL
);
5414 /* Set the transport for the SHUTDOWN chunk and the timeout for the
5415 * T2-shutdown timer.
5417 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5419 /* It shall then start the T2-shutdown timer */
5420 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5421 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5423 /* RFC 4960 Section 9.2
5424 * The sender of the SHUTDOWN MAY also start an overall guard timer
5425 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5427 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5428 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5430 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
5431 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5432 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5434 /* and enter the SHUTDOWN-SENT state. */
5435 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5436 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT
));
5438 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5440 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5443 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5445 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5447 return SCTP_DISPOSITION_CONSUME
;
5450 return SCTP_DISPOSITION_NOMEM
;
5454 * Generate a SHUTDOWN ACK now that everything is SACK'd.
5458 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5459 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
5460 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
5461 * endpoint must re-send the SHUTDOWN ACK.
5463 * The return value is the disposition.
5465 enum sctp_disposition
sctp_sf_do_9_2_shutdown_ack(
5467 const struct sctp_endpoint
*ep
,
5468 const struct sctp_association
*asoc
,
5469 const union sctp_subtype type
,
5471 struct sctp_cmd_seq
*commands
)
5473 struct sctp_chunk
*chunk
= arg
;
5474 struct sctp_chunk
*reply
;
5476 /* There are 2 ways of getting here:
5477 * 1) called in response to a SHUTDOWN chunk
5478 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
5480 * For the case (2), the arg parameter is set to NULL. We need
5481 * to check that we have a chunk before accessing it's fields.
5484 if (!sctp_vtag_verify(chunk
, asoc
))
5485 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
,
5488 /* Make sure that the SHUTDOWN chunk has a valid length. */
5489 if (!sctp_chunk_length_valid(
5490 chunk
, sizeof(struct sctp_shutdown_chunk
)))
5491 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
,
5495 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5496 * shall send a SHUTDOWN ACK ...
5498 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
5502 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
5503 * the T2-shutdown timer.
5505 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5507 /* and start/restart a T2-shutdown timer of its own, */
5508 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5509 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5511 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
5512 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5513 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5515 /* Enter the SHUTDOWN-ACK-SENT state. */
5516 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5517 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT
));
5519 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5521 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5524 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5526 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5528 return SCTP_DISPOSITION_CONSUME
;
5531 return SCTP_DISPOSITION_NOMEM
;
5535 * Ignore the event defined as other
5537 * The return value is the disposition of the event.
5539 enum sctp_disposition
sctp_sf_ignore_other(struct net
*net
,
5540 const struct sctp_endpoint
*ep
,
5541 const struct sctp_association
*asoc
,
5542 const union sctp_subtype type
,
5544 struct sctp_cmd_seq
*commands
)
5546 pr_debug("%s: the event other type:%d is ignored\n",
5547 __func__
, type
.other
);
5549 return SCTP_DISPOSITION_DISCARD
;
5552 /************************************************************
5553 * These are the state functions for handling timeout events.
5554 ************************************************************/
5559 * Section: 6.3.3 Handle T3-rtx Expiration
5561 * Whenever the retransmission timer T3-rtx expires for a destination
5562 * address, do the following:
5565 * The return value is the disposition of the chunk.
5567 enum sctp_disposition
sctp_sf_do_6_3_3_rtx(struct net
*net
,
5568 const struct sctp_endpoint
*ep
,
5569 const struct sctp_association
*asoc
,
5570 const union sctp_subtype type
,
5572 struct sctp_cmd_seq
*commands
)
5574 struct sctp_transport
*transport
= arg
;
5576 SCTP_INC_STATS(net
, SCTP_MIB_T3_RTX_EXPIREDS
);
5578 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5579 if (asoc
->peer
.zero_window_announced
&&
5580 asoc
->state
== SCTP_STATE_SHUTDOWN_PENDING
) {
5582 * We are here likely because the receiver had its rwnd
5583 * closed for a while and we have not been able to
5584 * transmit the locally queued data within the maximum
5585 * retransmission attempts limit. Start the T5
5586 * shutdown guard timer to give the receiver one last
5587 * chance and some additional time to recover before
5590 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START_ONCE
,
5591 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5593 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5594 SCTP_ERROR(ETIMEDOUT
));
5595 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5596 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5597 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5598 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5599 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5600 return SCTP_DISPOSITION_DELETE_TCB
;
5604 /* E1) For the destination address for which the timer
5605 * expires, adjust its ssthresh with rules defined in Section
5606 * 7.2.3 and set the cwnd <- MTU.
5609 /* E2) For the destination address for which the timer
5610 * expires, set RTO <- RTO * 2 ("back off the timer"). The
5611 * maximum value discussed in rule C7 above (RTO.max) may be
5612 * used to provide an upper bound to this doubling operation.
5615 /* E3) Determine how many of the earliest (i.e., lowest TSN)
5616 * outstanding DATA chunks for the address for which the
5617 * T3-rtx has expired will fit into a single packet, subject
5618 * to the MTU constraint for the path corresponding to the
5619 * destination transport address to which the retransmission
5620 * is being sent (this may be different from the address for
5621 * which the timer expires [see Section 6.4]). Call this
5622 * value K. Bundle and retransmit those K DATA chunks in a
5623 * single packet to the destination endpoint.
5625 * Note: Any DATA chunks that were sent to the address for
5626 * which the T3-rtx timer expired but did not fit in one MTU
5627 * (rule E3 above), should be marked for retransmission and
5628 * sent as soon as cwnd allows (normally when a SACK arrives).
5631 /* Do some failure management (Section 8.2). */
5632 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
5634 /* NB: Rules E4 and F1 are implicit in R1. */
5635 sctp_add_cmd_sf(commands
, SCTP_CMD_RETRAN
, SCTP_TRANSPORT(transport
));
5637 return SCTP_DISPOSITION_CONSUME
;
5641 * Generate delayed SACK on timeout
5643 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
5645 * The guidelines on delayed acknowledgement algorithm specified in
5646 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
5647 * acknowledgement SHOULD be generated for at least every second packet
5648 * (not every second DATA chunk) received, and SHOULD be generated
5649 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
5650 * some situations it may be beneficial for an SCTP transmitter to be
5651 * more conservative than the algorithms detailed in this document
5652 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
5653 * the following algorithms allow.
5655 enum sctp_disposition
sctp_sf_do_6_2_sack(struct net
*net
,
5656 const struct sctp_endpoint
*ep
,
5657 const struct sctp_association
*asoc
,
5658 const union sctp_subtype type
,
5660 struct sctp_cmd_seq
*commands
)
5662 SCTP_INC_STATS(net
, SCTP_MIB_DELAY_SACK_EXPIREDS
);
5663 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
5664 return SCTP_DISPOSITION_CONSUME
;
5668 * sctp_sf_t1_init_timer_expire
5670 * Section: 4 Note: 2
5675 * RFC 2960 Section 4 Notes
5676 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
5677 * and re-start the T1-init timer without changing state. This MUST
5678 * be repeated up to 'Max.Init.Retransmits' times. After that, the
5679 * endpoint MUST abort the initialization process and report the
5680 * error to SCTP user.
5686 enum sctp_disposition
sctp_sf_t1_init_timer_expire(
5688 const struct sctp_endpoint
*ep
,
5689 const struct sctp_association
*asoc
,
5690 const union sctp_subtype type
,
5692 struct sctp_cmd_seq
*commands
)
5694 int attempts
= asoc
->init_err_counter
+ 1;
5695 struct sctp_chunk
*repl
= NULL
;
5696 struct sctp_bind_addr
*bp
;
5698 pr_debug("%s: timer T1 expired (INIT)\n", __func__
);
5700 SCTP_INC_STATS(net
, SCTP_MIB_T1_INIT_EXPIREDS
);
5702 if (attempts
<= asoc
->max_init_attempts
) {
5703 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
5704 repl
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, 0);
5706 return SCTP_DISPOSITION_NOMEM
;
5708 /* Choose transport for INIT. */
5709 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5712 /* Issue a sideeffect to do the needed accounting. */
5713 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_RESTART
,
5714 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5716 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5718 pr_debug("%s: giving up on INIT, attempts:%d "
5719 "max_init_attempts:%d\n", __func__
, attempts
,
5720 asoc
->max_init_attempts
);
5722 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5723 SCTP_ERROR(ETIMEDOUT
));
5724 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5725 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5726 return SCTP_DISPOSITION_DELETE_TCB
;
5729 return SCTP_DISPOSITION_CONSUME
;
5733 * sctp_sf_t1_cookie_timer_expire
5735 * Section: 4 Note: 2
5740 * RFC 2960 Section 4 Notes
5741 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
5742 * COOKIE ECHO and re-start the T1-cookie timer without changing
5743 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
5744 * After that, the endpoint MUST abort the initialization process and
5745 * report the error to SCTP user.
5751 enum sctp_disposition
sctp_sf_t1_cookie_timer_expire(
5753 const struct sctp_endpoint
*ep
,
5754 const struct sctp_association
*asoc
,
5755 const union sctp_subtype type
,
5757 struct sctp_cmd_seq
*commands
)
5759 int attempts
= asoc
->init_err_counter
+ 1;
5760 struct sctp_chunk
*repl
= NULL
;
5762 pr_debug("%s: timer T1 expired (COOKIE-ECHO)\n", __func__
);
5764 SCTP_INC_STATS(net
, SCTP_MIB_T1_COOKIE_EXPIREDS
);
5766 if (attempts
<= asoc
->max_init_attempts
) {
5767 repl
= sctp_make_cookie_echo(asoc
, NULL
);
5769 return SCTP_DISPOSITION_NOMEM
;
5771 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5773 /* Issue a sideeffect to do the needed accounting. */
5774 sctp_add_cmd_sf(commands
, SCTP_CMD_COOKIEECHO_RESTART
,
5775 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
5777 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5779 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5780 SCTP_ERROR(ETIMEDOUT
));
5781 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5782 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5783 return SCTP_DISPOSITION_DELETE_TCB
;
5786 return SCTP_DISPOSITION_CONSUME
;
5789 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
5790 * with the updated last sequential TSN received from its peer.
5792 * An endpoint should limit the number of retransmissions of the
5793 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
5794 * If this threshold is exceeded the endpoint should destroy the TCB and
5795 * MUST report the peer endpoint unreachable to the upper layer (and
5796 * thus the association enters the CLOSED state). The reception of any
5797 * packet from its peer (i.e. as the peer sends all of its queued DATA
5798 * chunks) should clear the endpoint's retransmission count and restart
5799 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
5800 * all of its queued DATA chunks that have not yet been sent.
5802 enum sctp_disposition
sctp_sf_t2_timer_expire(
5804 const struct sctp_endpoint
*ep
,
5805 const struct sctp_association
*asoc
,
5806 const union sctp_subtype type
,
5808 struct sctp_cmd_seq
*commands
)
5810 struct sctp_chunk
*reply
= NULL
;
5812 pr_debug("%s: timer T2 expired\n", __func__
);
5814 SCTP_INC_STATS(net
, SCTP_MIB_T2_SHUTDOWN_EXPIREDS
);
5816 ((struct sctp_association
*)asoc
)->shutdown_retries
++;
5818 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5819 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5820 SCTP_ERROR(ETIMEDOUT
));
5821 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5822 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5823 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5824 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5825 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5826 return SCTP_DISPOSITION_DELETE_TCB
;
5829 switch (asoc
->state
) {
5830 case SCTP_STATE_SHUTDOWN_SENT
:
5831 reply
= sctp_make_shutdown(asoc
, NULL
);
5834 case SCTP_STATE_SHUTDOWN_ACK_SENT
:
5835 reply
= sctp_make_shutdown_ack(asoc
, NULL
);
5846 /* Do some failure management (Section 8.2).
5847 * If we remove the transport an SHUTDOWN was last sent to, don't
5848 * do failure management.
5850 if (asoc
->shutdown_last_sent_to
)
5851 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5852 SCTP_TRANSPORT(asoc
->shutdown_last_sent_to
));
5854 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
5855 * the T2-shutdown timer.
5857 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5859 /* Restart the T2-shutdown timer. */
5860 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5861 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5862 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5863 return SCTP_DISPOSITION_CONSUME
;
5866 return SCTP_DISPOSITION_NOMEM
;
5870 * ADDIP Section 4.1 ASCONF CHunk Procedures
5871 * If the T4 RTO timer expires the endpoint should do B1 to B5
5873 enum sctp_disposition
sctp_sf_t4_timer_expire(
5875 const struct sctp_endpoint
*ep
,
5876 const struct sctp_association
*asoc
,
5877 const union sctp_subtype type
,
5879 struct sctp_cmd_seq
*commands
)
5881 struct sctp_chunk
*chunk
= asoc
->addip_last_asconf
;
5882 struct sctp_transport
*transport
= chunk
->transport
;
5884 SCTP_INC_STATS(net
, SCTP_MIB_T4_RTO_EXPIREDS
);
5886 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
5887 * detection on the appropriate destination address as defined in
5888 * RFC2960 [5] section 8.1 and 8.2.
5891 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5892 SCTP_TRANSPORT(transport
));
5894 /* Reconfig T4 timer and transport. */
5895 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5897 /* ADDIP 4.1 B2) Increment the association error counters and perform
5898 * endpoint failure detection on the association as defined in
5899 * RFC2960 [5] section 8.1 and 8.2.
5900 * association error counter is incremented in SCTP_CMD_STRIKE.
5902 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5903 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5904 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5905 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5906 SCTP_ERROR(ETIMEDOUT
));
5907 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5908 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5909 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5910 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5911 return SCTP_DISPOSITION_ABORT
;
5914 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
5915 * the ASCONF chunk was sent by doubling the RTO timer value.
5916 * This is done in SCTP_CMD_STRIKE.
5919 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
5920 * choose an alternate destination address (please refer to RFC2960
5921 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
5922 * chunk, it MUST be the same (including its serial number) as the last
5925 sctp_chunk_hold(asoc
->addip_last_asconf
);
5926 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5927 SCTP_CHUNK(asoc
->addip_last_asconf
));
5929 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
5930 * destination is selected, then the RTO used will be that of the new
5931 * destination address.
5933 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5934 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5936 return SCTP_DISPOSITION_CONSUME
;
5939 /* sctpimpguide-05 Section 2.12.2
5940 * The sender of the SHUTDOWN MAY also start an overall guard timer
5941 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5942 * At the expiration of this timer the sender SHOULD abort the association
5943 * by sending an ABORT chunk.
5945 enum sctp_disposition
sctp_sf_t5_timer_expire(
5947 const struct sctp_endpoint
*ep
,
5948 const struct sctp_association
*asoc
,
5949 const union sctp_subtype type
,
5951 struct sctp_cmd_seq
*commands
)
5953 struct sctp_chunk
*reply
= NULL
;
5955 pr_debug("%s: timer T5 expired\n", __func__
);
5957 SCTP_INC_STATS(net
, SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS
);
5959 reply
= sctp_make_abort(asoc
, NULL
, 0);
5963 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5964 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5965 SCTP_ERROR(ETIMEDOUT
));
5966 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5967 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5969 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5970 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5972 return SCTP_DISPOSITION_DELETE_TCB
;
5974 return SCTP_DISPOSITION_NOMEM
;
5977 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
5978 * the association is automatically closed by starting the shutdown process.
5979 * The work that needs to be done is same as when SHUTDOWN is initiated by
5980 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
5982 enum sctp_disposition
sctp_sf_autoclose_timer_expire(
5984 const struct sctp_endpoint
*ep
,
5985 const struct sctp_association
*asoc
,
5986 const union sctp_subtype type
,
5988 struct sctp_cmd_seq
*commands
)
5990 enum sctp_disposition disposition
;
5992 SCTP_INC_STATS(net
, SCTP_MIB_AUTOCLOSE_EXPIREDS
);
5994 /* From 9.2 Shutdown of an Association
5995 * Upon receipt of the SHUTDOWN primitive from its upper
5996 * layer, the endpoint enters SHUTDOWN-PENDING state and
5997 * remains there until all outstanding data has been
5998 * acknowledged by its peer. The endpoint accepts no new data
5999 * from its upper layer, but retransmits data to the far end
6000 * if necessary to fill gaps.
6002 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
6003 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
6005 disposition
= SCTP_DISPOSITION_CONSUME
;
6006 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
6007 disposition
= sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
, type
,
6014 /*****************************************************************************
6015 * These are sa state functions which could apply to all types of events.
6016 ****************************************************************************/
6019 * This table entry is not implemented.
6022 * (endpoint, asoc, chunk)
6024 * The return value is the disposition of the chunk.
6026 enum sctp_disposition
sctp_sf_not_impl(struct net
*net
,
6027 const struct sctp_endpoint
*ep
,
6028 const struct sctp_association
*asoc
,
6029 const union sctp_subtype type
,
6030 void *arg
, struct sctp_cmd_seq
*commands
)
6032 return SCTP_DISPOSITION_NOT_IMPL
;
6036 * This table entry represents a bug.
6039 * (endpoint, asoc, chunk)
6041 * The return value is the disposition of the chunk.
6043 enum sctp_disposition
sctp_sf_bug(struct net
*net
,
6044 const struct sctp_endpoint
*ep
,
6045 const struct sctp_association
*asoc
,
6046 const union sctp_subtype type
,
6047 void *arg
, struct sctp_cmd_seq
*commands
)
6049 return SCTP_DISPOSITION_BUG
;
6053 * This table entry represents the firing of a timer in the wrong state.
6054 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
6055 * when the association is in the wrong state. This event should
6056 * be ignored, so as to prevent any rearming of the timer.
6059 * (endpoint, asoc, chunk)
6061 * The return value is the disposition of the chunk.
6063 enum sctp_disposition
sctp_sf_timer_ignore(struct net
*net
,
6064 const struct sctp_endpoint
*ep
,
6065 const struct sctp_association
*asoc
,
6066 const union sctp_subtype type
,
6068 struct sctp_cmd_seq
*commands
)
6070 pr_debug("%s: timer %d ignored\n", __func__
, type
.chunk
);
6072 return SCTP_DISPOSITION_CONSUME
;
6075 /********************************************************************
6076 * 2nd Level Abstractions
6077 ********************************************************************/
6079 /* Pull the SACK chunk based on the SACK header. */
6080 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
)
6082 struct sctp_sackhdr
*sack
;
6087 /* Protect ourselves from reading too far into
6088 * the skb from a bogus sender.
6090 sack
= (struct sctp_sackhdr
*) chunk
->skb
->data
;
6092 num_blocks
= ntohs(sack
->num_gap_ack_blocks
);
6093 num_dup_tsns
= ntohs(sack
->num_dup_tsns
);
6094 len
= sizeof(struct sctp_sackhdr
);
6095 len
+= (num_blocks
+ num_dup_tsns
) * sizeof(__u32
);
6096 if (len
> chunk
->skb
->len
)
6099 skb_pull(chunk
->skb
, len
);
6104 /* Create an ABORT packet to be sent as a response, with the specified
6107 static struct sctp_packet
*sctp_abort_pkt_new(
6109 const struct sctp_endpoint
*ep
,
6110 const struct sctp_association
*asoc
,
6111 struct sctp_chunk
*chunk
,
6112 const void *payload
, size_t paylen
)
6114 struct sctp_packet
*packet
;
6115 struct sctp_chunk
*abort
;
6117 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
6121 * The T bit will be set if the asoc is NULL.
6123 abort
= sctp_make_abort(asoc
, chunk
, paylen
);
6125 sctp_ootb_pkt_free(packet
);
6129 /* Reflect vtag if T-Bit is set */
6130 if (sctp_test_T_bit(abort
))
6131 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
6133 /* Add specified error causes, i.e., payload, to the
6136 sctp_addto_chunk(abort
, paylen
, payload
);
6138 /* Set the skb to the belonging sock for accounting. */
6139 abort
->skb
->sk
= ep
->base
.sk
;
6141 sctp_packet_append_chunk(packet
, abort
);
6148 /* Allocate a packet for responding in the OOTB conditions. */
6149 static struct sctp_packet
*sctp_ootb_pkt_new(
6151 const struct sctp_association
*asoc
,
6152 const struct sctp_chunk
*chunk
)
6154 struct sctp_transport
*transport
;
6155 struct sctp_packet
*packet
;
6159 /* Get the source and destination port from the inbound packet. */
6160 sport
= ntohs(chunk
->sctp_hdr
->dest
);
6161 dport
= ntohs(chunk
->sctp_hdr
->source
);
6163 /* The V-tag is going to be the same as the inbound packet if no
6164 * association exists, otherwise, use the peer's vtag.
6167 /* Special case the INIT-ACK as there is no peer's vtag
6170 switch (chunk
->chunk_hdr
->type
) {
6171 case SCTP_CID_INIT_ACK
:
6173 struct sctp_initack_chunk
*initack
;
6175 initack
= (struct sctp_initack_chunk
*)chunk
->chunk_hdr
;
6176 vtag
= ntohl(initack
->init_hdr
.init_tag
);
6180 vtag
= asoc
->peer
.i
.init_tag
;
6184 /* Special case the INIT and stale COOKIE_ECHO as there is no
6187 switch (chunk
->chunk_hdr
->type
) {
6190 struct sctp_init_chunk
*init
;
6192 init
= (struct sctp_init_chunk
*)chunk
->chunk_hdr
;
6193 vtag
= ntohl(init
->init_hdr
.init_tag
);
6197 vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
6202 /* Make a transport for the bucket, Eliza... */
6203 transport
= sctp_transport_new(net
, sctp_source(chunk
), GFP_ATOMIC
);
6207 /* Cache a route for the transport with the chunk's destination as
6208 * the source address.
6210 sctp_transport_route(transport
, (union sctp_addr
*)&chunk
->dest
,
6211 sctp_sk(net
->sctp
.ctl_sock
));
6213 packet
= &transport
->packet
;
6214 sctp_packet_init(packet
, transport
, sport
, dport
);
6215 sctp_packet_config(packet
, vtag
, 0);
6223 /* Free the packet allocated earlier for responding in the OOTB condition. */
6224 void sctp_ootb_pkt_free(struct sctp_packet
*packet
)
6226 sctp_transport_free(packet
->transport
);
6229 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
6230 static void sctp_send_stale_cookie_err(struct net
*net
,
6231 const struct sctp_endpoint
*ep
,
6232 const struct sctp_association
*asoc
,
6233 const struct sctp_chunk
*chunk
,
6234 struct sctp_cmd_seq
*commands
,
6235 struct sctp_chunk
*err_chunk
)
6237 struct sctp_packet
*packet
;
6240 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
6242 struct sctp_signed_cookie
*cookie
;
6244 /* Override the OOTB vtag from the cookie. */
6245 cookie
= chunk
->subh
.cookie_hdr
;
6246 packet
->vtag
= cookie
->c
.peer_vtag
;
6248 /* Set the skb to the belonging sock for accounting. */
6249 err_chunk
->skb
->sk
= ep
->base
.sk
;
6250 sctp_packet_append_chunk(packet
, err_chunk
);
6251 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
6252 SCTP_PACKET(packet
));
6253 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
6255 sctp_chunk_free (err_chunk
);
6260 /* Process a data chunk */
6261 static int sctp_eat_data(const struct sctp_association
*asoc
,
6262 struct sctp_chunk
*chunk
,
6263 struct sctp_cmd_seq
*commands
)
6265 struct sctp_tsnmap
*map
= (struct sctp_tsnmap
*)&asoc
->peer
.tsn_map
;
6266 struct sock
*sk
= asoc
->base
.sk
;
6267 struct net
*net
= sock_net(sk
);
6268 struct sctp_datahdr
*data_hdr
;
6269 struct sctp_chunk
*err
;
6270 enum sctp_verb deliver
;
6277 data_hdr
= (struct sctp_datahdr
*)chunk
->skb
->data
;
6278 chunk
->subh
.data_hdr
= data_hdr
;
6279 skb_pull(chunk
->skb
, sizeof(*data_hdr
));
6281 tsn
= ntohl(data_hdr
->tsn
);
6282 pr_debug("%s: TSN 0x%x\n", __func__
, tsn
);
6284 /* ASSERT: Now skb->data is really the user data. */
6286 /* Process ECN based congestion.
6288 * Since the chunk structure is reused for all chunks within
6289 * a packet, we use ecn_ce_done to track if we've already
6290 * done CE processing for this packet.
6292 * We need to do ECN processing even if we plan to discard the
6296 if (asoc
->peer
.ecn_capable
&& !chunk
->ecn_ce_done
) {
6297 struct sctp_af
*af
= SCTP_INPUT_CB(chunk
->skb
)->af
;
6298 chunk
->ecn_ce_done
= 1;
6300 if (af
->is_ce(sctp_gso_headskb(chunk
->skb
))) {
6301 /* Do real work as sideffect. */
6302 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_CE
,
6307 tmp
= sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
);
6309 /* The TSN is too high--silently discard the chunk and
6310 * count on it getting retransmitted later.
6313 chunk
->asoc
->stats
.outofseqtsns
++;
6314 return SCTP_IERROR_HIGH_TSN
;
6315 } else if (tmp
> 0) {
6316 /* This is a duplicate. Record it. */
6317 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_DUP
, SCTP_U32(tsn
));
6318 return SCTP_IERROR_DUP_TSN
;
6321 /* This is a new TSN. */
6323 /* Discard if there is no room in the receive window.
6324 * Actually, allow a little bit of overflow (up to a MTU).
6326 datalen
= ntohs(chunk
->chunk_hdr
->length
);
6327 datalen
-= sizeof(struct sctp_data_chunk
);
6329 deliver
= SCTP_CMD_CHUNK_ULP
;
6331 /* Think about partial delivery. */
6332 if ((datalen
>= asoc
->rwnd
) && (!asoc
->ulpq
.pd_mode
)) {
6334 /* Even if we don't accept this chunk there is
6337 sctp_add_cmd_sf(commands
, SCTP_CMD_PART_DELIVER
, SCTP_NULL());
6340 /* Spill over rwnd a little bit. Note: While allowed, this spill over
6341 * seems a bit troublesome in that frag_point varies based on
6342 * PMTU. In cases, such as loopback, this might be a rather
6345 if ((!chunk
->data_accepted
) && (!asoc
->rwnd
|| asoc
->rwnd_over
||
6346 (datalen
> asoc
->rwnd
+ asoc
->frag_point
))) {
6348 /* If this is the next TSN, consider reneging to make
6349 * room. Note: Playing nice with a confused sender. A
6350 * malicious sender can still eat up all our buffer
6351 * space and in the future we may want to detect and
6352 * do more drastic reneging.
6354 if (sctp_tsnmap_has_gap(map
) &&
6355 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
6356 pr_debug("%s: reneging for tsn:%u\n", __func__
, tsn
);
6357 deliver
= SCTP_CMD_RENEGE
;
6359 pr_debug("%s: discard tsn:%u len:%zu, rwnd:%d\n",
6360 __func__
, tsn
, datalen
, asoc
->rwnd
);
6362 return SCTP_IERROR_IGNORE_TSN
;
6367 * Also try to renege to limit our memory usage in the event that
6368 * we are under memory pressure
6369 * If we can't renege, don't worry about it, the sk_rmem_schedule
6370 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
6371 * memory usage too much
6373 if (sk_under_memory_pressure(sk
)) {
6374 if (sctp_tsnmap_has_gap(map
) &&
6375 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
6376 pr_debug("%s: under pressure, reneging for tsn:%u\n",
6378 deliver
= SCTP_CMD_RENEGE
;
6385 * Section 3.3.10.9 No User Data (9)
6389 * No User Data: This error cause is returned to the originator of a
6390 * DATA chunk if a received DATA chunk has no user data.
6392 if (unlikely(0 == datalen
)) {
6393 err
= sctp_make_abort_no_data(asoc
, chunk
, tsn
);
6395 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6398 /* We are going to ABORT, so we might as well stop
6399 * processing the rest of the chunks in the packet.
6401 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
6402 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
6403 SCTP_ERROR(ECONNABORTED
));
6404 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
6405 SCTP_PERR(SCTP_ERROR_NO_DATA
));
6406 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
6407 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
6408 return SCTP_IERROR_NO_DATA
;
6411 chunk
->data_accepted
= 1;
6413 /* Note: Some chunks may get overcounted (if we drop) or overcounted
6414 * if we renege and the chunk arrives again.
6416 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_UNORDERED
) {
6417 SCTP_INC_STATS(net
, SCTP_MIB_INUNORDERCHUNKS
);
6419 chunk
->asoc
->stats
.iuodchunks
++;
6421 SCTP_INC_STATS(net
, SCTP_MIB_INORDERCHUNKS
);
6423 chunk
->asoc
->stats
.iodchunks
++;
6427 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
6429 * If an endpoint receive a DATA chunk with an invalid stream
6430 * identifier, it shall acknowledge the reception of the DATA chunk
6431 * following the normal procedure, immediately send an ERROR chunk
6432 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
6433 * and discard the DATA chunk.
6435 sid
= ntohs(data_hdr
->stream
);
6436 if (sid
>= asoc
->stream
.incnt
) {
6437 /* Mark tsn as received even though we drop it */
6438 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_TSN
, SCTP_U32(tsn
));
6440 err
= sctp_make_op_error(asoc
, chunk
, SCTP_ERROR_INV_STRM
,
6442 sizeof(data_hdr
->stream
),
6445 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6447 return SCTP_IERROR_BAD_STREAM
;
6450 /* Check to see if the SSN is possible for this TSN.
6451 * The biggest gap we can record is 4K wide. Since SSNs wrap
6452 * at an unsigned short, there is no way that an SSN can
6453 * wrap and for a valid TSN. We can simply check if the current
6454 * SSN is smaller then the next expected one. If it is, it wrapped
6457 ssn
= ntohs(data_hdr
->ssn
);
6458 if (ordered
&& SSN_lt(ssn
, sctp_ssn_peek(&asoc
->stream
, in
, sid
)))
6459 return SCTP_IERROR_PROTO_VIOLATION
;
6461 /* Send the data up to the user. Note: Schedule the
6462 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
6463 * chunk needs the updated rwnd.
6465 sctp_add_cmd_sf(commands
, deliver
, SCTP_CHUNK(chunk
));
6467 return SCTP_IERROR_NO_ERROR
;