1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* SCTP kernel implementation
3 * (C) Copyright IBM Corp. 2001, 2004
4 * Copyright (c) 1999-2000 Cisco, Inc.
5 * Copyright (c) 1999-2001 Motorola, Inc.
6 * Copyright (c) 2001-2002 Intel Corp.
7 * Copyright (c) 2002 Nokia Corp.
9 * This is part of the SCTP Linux Kernel Implementation.
11 * These are the state functions for the state machine.
13 * Please send any bug reports or fixes you make to the
15 * lksctp developers <linux-sctp@vger.kernel.org>
17 * Written or modified by:
18 * La Monte H.P. Yarroll <piggy@acm.org>
19 * Karl Knutson <karl@athena.chicago.il.us>
20 * Mathew Kotowsky <kotowsky@sctp.org>
21 * Sridhar Samudrala <samudrala@us.ibm.com>
22 * Jon Grimm <jgrimm@us.ibm.com>
23 * Hui Huang <hui.huang@nokia.com>
24 * Dajiang Zhang <dajiang.zhang@nokia.com>
25 * Daisy Chang <daisyc@us.ibm.com>
26 * Ardelle Fan <ardelle.fan@intel.com>
27 * Ryan Layer <rmlayer@us.ibm.com>
28 * Kevin Gao <kevin.gao@intel.com>
31 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33 #include <linux/types.h>
34 #include <linux/kernel.h>
36 #include <linux/ipv6.h>
37 #include <linux/net.h>
38 #include <linux/inet.h>
39 #include <linux/slab.h>
41 #include <net/inet_ecn.h>
42 #include <linux/skbuff.h>
43 #include <net/sctp/sctp.h>
44 #include <net/sctp/sm.h>
45 #include <net/sctp/structs.h>
47 #define CREATE_TRACE_POINTS
48 #include <trace/events/sctp.h>
50 static struct sctp_packet
*sctp_abort_pkt_new(
52 const struct sctp_endpoint
*ep
,
53 const struct sctp_association
*asoc
,
54 struct sctp_chunk
*chunk
,
55 const void *payload
, size_t paylen
);
56 static int sctp_eat_data(const struct sctp_association
*asoc
,
57 struct sctp_chunk
*chunk
,
58 struct sctp_cmd_seq
*commands
);
59 static struct sctp_packet
*sctp_ootb_pkt_new(
61 const struct sctp_association
*asoc
,
62 const struct sctp_chunk
*chunk
);
63 static void sctp_send_stale_cookie_err(struct net
*net
,
64 const struct sctp_endpoint
*ep
,
65 const struct sctp_association
*asoc
,
66 const struct sctp_chunk
*chunk
,
67 struct sctp_cmd_seq
*commands
,
68 struct sctp_chunk
*err_chunk
);
69 static enum sctp_disposition
sctp_sf_do_5_2_6_stale(
71 const struct sctp_endpoint
*ep
,
72 const struct sctp_association
*asoc
,
73 const union sctp_subtype type
,
75 struct sctp_cmd_seq
*commands
);
76 static enum sctp_disposition
sctp_sf_shut_8_4_5(
78 const struct sctp_endpoint
*ep
,
79 const struct sctp_association
*asoc
,
80 const union sctp_subtype type
,
82 struct sctp_cmd_seq
*commands
);
83 static enum sctp_disposition
sctp_sf_tabort_8_4_8(
85 const struct sctp_endpoint
*ep
,
86 const struct sctp_association
*asoc
,
87 const union sctp_subtype type
,
89 struct sctp_cmd_seq
*commands
);
90 static enum sctp_disposition
sctp_sf_new_encap_port(
92 const struct sctp_endpoint
*ep
,
93 const struct sctp_association
*asoc
,
94 const union sctp_subtype type
,
96 struct sctp_cmd_seq
*commands
);
97 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
);
99 static enum sctp_disposition
sctp_stop_t1_and_abort(
101 struct sctp_cmd_seq
*commands
,
102 __be16 error
, int sk_err
,
103 const struct sctp_association
*asoc
,
104 struct sctp_transport
*transport
);
106 static enum sctp_disposition
sctp_sf_abort_violation(
108 const struct sctp_endpoint
*ep
,
109 const struct sctp_association
*asoc
,
111 struct sctp_cmd_seq
*commands
,
113 const size_t paylen
);
115 static enum sctp_disposition
sctp_sf_violation_chunklen(
117 const struct sctp_endpoint
*ep
,
118 const struct sctp_association
*asoc
,
119 const union sctp_subtype type
,
121 struct sctp_cmd_seq
*commands
);
123 static enum sctp_disposition
sctp_sf_violation_paramlen(
125 const struct sctp_endpoint
*ep
,
126 const struct sctp_association
*asoc
,
127 const union sctp_subtype type
,
128 void *arg
, void *ext
,
129 struct sctp_cmd_seq
*commands
);
131 static enum sctp_disposition
sctp_sf_violation_ctsn(
133 const struct sctp_endpoint
*ep
,
134 const struct sctp_association
*asoc
,
135 const union sctp_subtype type
,
137 struct sctp_cmd_seq
*commands
);
139 static enum sctp_disposition
sctp_sf_violation_chunk(
141 const struct sctp_endpoint
*ep
,
142 const struct sctp_association
*asoc
,
143 const union sctp_subtype type
,
145 struct sctp_cmd_seq
*commands
);
147 static enum sctp_ierror
sctp_sf_authenticate(
148 const struct sctp_association
*asoc
,
149 struct sctp_chunk
*chunk
);
151 static enum sctp_disposition
__sctp_sf_do_9_1_abort(
153 const struct sctp_endpoint
*ep
,
154 const struct sctp_association
*asoc
,
155 const union sctp_subtype type
,
157 struct sctp_cmd_seq
*commands
);
159 static enum sctp_disposition
160 __sctp_sf_do_9_2_reshutack(struct net
*net
, const struct sctp_endpoint
*ep
,
161 const struct sctp_association
*asoc
,
162 const union sctp_subtype type
, void *arg
,
163 struct sctp_cmd_seq
*commands
);
165 /* Small helper function that checks if the chunk length
166 * is of the appropriate length. The 'required_length' argument
167 * is set to be the size of a specific chunk we are testing.
168 * Return Values: true = Valid length
169 * false = Invalid length
172 static inline bool sctp_chunk_length_valid(struct sctp_chunk
*chunk
,
173 __u16 required_length
)
175 __u16 chunk_length
= ntohs(chunk
->chunk_hdr
->length
);
177 /* Previously already marked? */
178 if (unlikely(chunk
->pdiscard
))
180 if (unlikely(chunk_length
< required_length
))
186 /* Check for format error in an ABORT chunk */
187 static inline bool sctp_err_chunk_valid(struct sctp_chunk
*chunk
)
189 struct sctp_errhdr
*err
;
191 sctp_walk_errors(err
, chunk
->chunk_hdr
);
193 return (void *)err
== (void *)chunk
->chunk_end
;
196 /**********************************************************
197 * These are the state functions for handling chunk events.
198 **********************************************************/
201 * Process the final SHUTDOWN COMPLETE.
203 * Section: 4 (C) (diagram), 9.2
204 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
205 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
206 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
207 * should stop the T2-shutdown timer and remove all knowledge of the
208 * association (and thus the association enters the CLOSED state).
210 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
211 * C) Rules for packet carrying SHUTDOWN COMPLETE:
213 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
214 * if the Verification Tag field of the packet matches its own tag and
215 * the T bit is not set
217 * it is set to its peer's tag and the T bit is set in the Chunk
219 * Otherwise, the receiver MUST silently discard the packet
220 * and take no further action. An endpoint MUST ignore the
221 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
224 * (endpoint, asoc, chunk)
227 * (asoc, reply_msg, msg_up, timers, counters)
229 * The return value is the disposition of the chunk.
231 enum sctp_disposition
sctp_sf_do_4_C(struct net
*net
,
232 const struct sctp_endpoint
*ep
,
233 const struct sctp_association
*asoc
,
234 const union sctp_subtype type
,
235 void *arg
, struct sctp_cmd_seq
*commands
)
237 struct sctp_chunk
*chunk
= arg
;
238 struct sctp_ulpevent
*ev
;
240 if (!sctp_vtag_verify_either(chunk
, asoc
))
241 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
243 /* RFC 2960 6.10 Bundling
245 * An endpoint MUST NOT bundle INIT, INIT ACK or
246 * SHUTDOWN COMPLETE with any other chunks.
248 if (!chunk
->singleton
)
249 return sctp_sf_violation_chunk(net
, ep
, asoc
, type
, arg
, commands
);
251 /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */
252 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
253 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
256 /* RFC 2960 10.2 SCTP-to-ULP
258 * H) SHUTDOWN COMPLETE notification
260 * When SCTP completes the shutdown procedures (section 9.2) this
261 * notification is passed to the upper layer.
263 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
264 0, 0, 0, NULL
, GFP_ATOMIC
);
266 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
269 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
270 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
271 * not the chunk should be discarded. If the endpoint is in
272 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
273 * T2-shutdown timer and remove all knowledge of the
274 * association (and thus the association enters the CLOSED
277 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
278 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
280 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
281 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
283 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
284 SCTP_STATE(SCTP_STATE_CLOSED
));
286 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
287 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
289 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
291 return SCTP_DISPOSITION_DELETE_TCB
;
295 * Respond to a normal INIT chunk.
296 * We are the side that is being asked for an association.
298 * Section: 5.1 Normal Establishment of an Association, B
299 * B) "Z" shall respond immediately with an INIT ACK chunk. The
300 * destination IP address of the INIT ACK MUST be set to the source
301 * IP address of the INIT to which this INIT ACK is responding. In
302 * the response, besides filling in other parameters, "Z" must set the
303 * Verification Tag field to Tag_A, and also provide its own
304 * Verification Tag (Tag_Z) in the Initiate Tag field.
306 * Verification Tag: Must be 0.
309 * (endpoint, asoc, chunk)
312 * (asoc, reply_msg, msg_up, timers, counters)
314 * The return value is the disposition of the chunk.
316 enum sctp_disposition
sctp_sf_do_5_1B_init(struct net
*net
,
317 const struct sctp_endpoint
*ep
,
318 const struct sctp_association
*asoc
,
319 const union sctp_subtype type
,
321 struct sctp_cmd_seq
*commands
)
323 struct sctp_chunk
*chunk
= arg
, *repl
, *err_chunk
;
324 struct sctp_unrecognized_param
*unk_param
;
325 struct sctp_association
*new_asoc
;
326 struct sctp_packet
*packet
;
329 /* Update socket peer label if first association. */
330 if (security_sctp_assoc_request((struct sctp_endpoint
*)ep
,
332 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
335 * An endpoint MUST NOT bundle INIT, INIT ACK or
336 * SHUTDOWN COMPLETE with any other chunks.
339 * Furthermore, we require that the receiver of an INIT chunk MUST
340 * enforce these rules by silently discarding an arriving packet
341 * with an INIT chunk that is bundled with other chunks.
343 if (!chunk
->singleton
)
344 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
346 /* Make sure that the INIT chunk has a valid length.
347 * Normally, this would cause an ABORT with a Protocol Violation
348 * error, but since we don't have an association, we'll
349 * just discard the packet.
351 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_init_chunk
)))
352 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
354 /* If the packet is an OOTB packet which is temporarily on the
355 * control endpoint, respond with an ABORT.
357 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
) {
358 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
359 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
362 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
365 if (chunk
->sctp_hdr
->vtag
!= 0)
366 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
368 /* If the INIT is coming toward a closing socket, we'll send back
369 * and ABORT. Essentially, this catches the race of INIT being
370 * backloged to the socket at the same time as the user issues close().
371 * Since the socket and all its associations are going away, we
372 * can treat this OOTB
374 if (sctp_sstate(ep
->base
.sk
, CLOSING
))
375 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
377 /* Verify the INIT chunk before processing it. */
379 if (!sctp_verify_init(net
, ep
, asoc
, chunk
->chunk_hdr
->type
,
380 (struct sctp_init_chunk
*)chunk
->chunk_hdr
, chunk
,
382 /* This chunk contains fatal error. It is to be discarded.
383 * Send an ABORT, with causes if there is any.
386 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
387 (__u8
*)(err_chunk
->chunk_hdr
) +
388 sizeof(struct sctp_chunkhdr
),
389 ntohs(err_chunk
->chunk_hdr
->length
) -
390 sizeof(struct sctp_chunkhdr
));
392 sctp_chunk_free(err_chunk
);
395 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
396 SCTP_PACKET(packet
));
397 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
398 return SCTP_DISPOSITION_CONSUME
;
400 return SCTP_DISPOSITION_NOMEM
;
403 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
,
408 /* Grab the INIT header. */
409 chunk
->subh
.init_hdr
= (struct sctp_inithdr
*)chunk
->skb
->data
;
411 /* Tag the variable length parameters. */
412 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(struct sctp_inithdr
));
414 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
418 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
,
419 sctp_scope(sctp_source(chunk
)),
423 /* The call, sctp_process_init(), can fail on memory allocation. */
424 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
),
425 (struct sctp_init_chunk
*)chunk
->chunk_hdr
,
429 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
431 /* If there are errors need to be reported for unknown parameters,
432 * make sure to reserve enough room in the INIT ACK for them.
436 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
437 sizeof(struct sctp_chunkhdr
);
439 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
443 /* If there are errors need to be reported for unknown parameters,
444 * include them in the outgoing INIT ACK as "Unrecognized parameter"
448 /* Get the "Unrecognized parameter" parameter(s) out of the
449 * ERROR chunk generated by sctp_verify_init(). Since the
450 * error cause code for "unknown parameter" and the
451 * "Unrecognized parameter" type is the same, we can
452 * construct the parameters in INIT ACK by copying the
455 unk_param
= (struct sctp_unrecognized_param
*)
456 ((__u8
*)(err_chunk
->chunk_hdr
) +
457 sizeof(struct sctp_chunkhdr
));
458 /* Replace the cause code with the "Unrecognized parameter"
461 sctp_addto_chunk(repl
, len
, unk_param
);
462 sctp_chunk_free(err_chunk
);
465 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
467 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
470 * Note: After sending out INIT ACK with the State Cookie parameter,
471 * "Z" MUST NOT allocate any resources, nor keep any states for the
472 * new association. Otherwise, "Z" will be vulnerable to resource
475 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
477 return SCTP_DISPOSITION_DELETE_TCB
;
480 sctp_association_free(new_asoc
);
483 sctp_chunk_free(err_chunk
);
484 return SCTP_DISPOSITION_NOMEM
;
488 * Respond to a normal INIT ACK chunk.
489 * We are the side that is initiating the association.
491 * Section: 5.1 Normal Establishment of an Association, C
492 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
493 * timer and leave COOKIE-WAIT state. "A" shall then send the State
494 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
495 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
497 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
498 * DATA chunks, but it MUST be the first chunk in the packet and
499 * until the COOKIE ACK is returned the sender MUST NOT send any
500 * other packets to the peer.
502 * Verification Tag: 3.3.3
503 * If the value of the Initiate Tag in a received INIT ACK chunk is
504 * found to be 0, the receiver MUST treat it as an error and close the
505 * association by transmitting an ABORT.
508 * (endpoint, asoc, chunk)
511 * (asoc, reply_msg, msg_up, timers, counters)
513 * The return value is the disposition of the chunk.
515 enum sctp_disposition
sctp_sf_do_5_1C_ack(struct net
*net
,
516 const struct sctp_endpoint
*ep
,
517 const struct sctp_association
*asoc
,
518 const union sctp_subtype type
,
520 struct sctp_cmd_seq
*commands
)
522 struct sctp_init_chunk
*initchunk
;
523 struct sctp_chunk
*chunk
= arg
;
524 struct sctp_chunk
*err_chunk
;
525 struct sctp_packet
*packet
;
527 if (!sctp_vtag_verify(chunk
, asoc
))
528 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
531 * An endpoint MUST NOT bundle INIT, INIT ACK or
532 * SHUTDOWN COMPLETE with any other chunks.
534 if (!chunk
->singleton
)
535 return sctp_sf_violation_chunk(net
, ep
, asoc
, type
, arg
, commands
);
537 /* Make sure that the INIT-ACK chunk has a valid length */
538 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_initack_chunk
)))
539 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
541 /* Grab the INIT header. */
542 chunk
->subh
.init_hdr
= (struct sctp_inithdr
*)chunk
->skb
->data
;
544 /* Verify the INIT chunk before processing it. */
546 if (!sctp_verify_init(net
, ep
, asoc
, chunk
->chunk_hdr
->type
,
547 (struct sctp_init_chunk
*)chunk
->chunk_hdr
, chunk
,
550 enum sctp_error error
= SCTP_ERROR_NO_RESOURCE
;
552 /* This chunk contains fatal error. It is to be discarded.
553 * Send an ABORT, with causes. If there are no causes,
554 * then there wasn't enough memory. Just terminate
558 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
559 (__u8
*)(err_chunk
->chunk_hdr
) +
560 sizeof(struct sctp_chunkhdr
),
561 ntohs(err_chunk
->chunk_hdr
->length
) -
562 sizeof(struct sctp_chunkhdr
));
564 sctp_chunk_free(err_chunk
);
567 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
568 SCTP_PACKET(packet
));
569 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
570 error
= SCTP_ERROR_INV_PARAM
;
574 /* SCTP-AUTH, Section 6.3:
575 * It should be noted that if the receiver wants to tear
576 * down an association in an authenticated way only, the
577 * handling of malformed packets should not result in
578 * tearing down the association.
580 * This means that if we only want to abort associations
581 * in an authenticated way (i.e AUTH+ABORT), then we
582 * can't destroy this association just because the packet
585 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
586 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
588 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
589 return sctp_stop_t1_and_abort(net
, commands
, error
, ECONNREFUSED
,
590 asoc
, chunk
->transport
);
593 /* Tag the variable length parameters. Note that we never
594 * convert the parameters in an INIT chunk.
596 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(struct sctp_inithdr
));
598 initchunk
= (struct sctp_init_chunk
*)chunk
->chunk_hdr
;
600 sctp_add_cmd_sf(commands
, SCTP_CMD_PEER_INIT
,
601 SCTP_PEER_INIT(initchunk
));
603 /* Reset init error count upon receipt of INIT-ACK. */
604 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
606 /* 5.1 C) "A" shall stop the T1-init timer and leave
607 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
608 * timer, and enter the COOKIE-ECHOED state.
610 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
611 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
612 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
613 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
614 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
615 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED
));
617 /* SCTP-AUTH: generate the association shared keys so that
618 * we can potentially sign the COOKIE-ECHO.
620 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_SHKEY
, SCTP_NULL());
622 /* 5.1 C) "A" shall then send the State Cookie received in the
623 * INIT ACK chunk in a COOKIE ECHO chunk, ...
625 /* If there is any errors to report, send the ERROR chunk generated
626 * for unknown parameters as well.
628 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_COOKIE_ECHO
,
629 SCTP_CHUNK(err_chunk
));
631 return SCTP_DISPOSITION_CONSUME
;
634 static bool sctp_auth_chunk_verify(struct net
*net
, struct sctp_chunk
*chunk
,
635 const struct sctp_association
*asoc
)
637 struct sctp_chunk auth
;
639 if (!chunk
->auth_chunk
)
642 /* SCTP-AUTH: auth_chunk pointer is only set when the cookie-echo
643 * is supposed to be authenticated and we have to do delayed
644 * authentication. We've just recreated the association using
645 * the information in the cookie and now it's much easier to
646 * do the authentication.
649 /* Make sure that we and the peer are AUTH capable */
650 if (!net
->sctp
.auth_enable
|| !asoc
->peer
.auth_capable
)
653 /* set-up our fake chunk so that we can process it */
654 auth
.skb
= chunk
->auth_chunk
;
655 auth
.asoc
= chunk
->asoc
;
656 auth
.sctp_hdr
= chunk
->sctp_hdr
;
657 auth
.chunk_hdr
= (struct sctp_chunkhdr
*)
658 skb_push(chunk
->auth_chunk
,
659 sizeof(struct sctp_chunkhdr
));
660 skb_pull(chunk
->auth_chunk
, sizeof(struct sctp_chunkhdr
));
661 auth
.transport
= chunk
->transport
;
663 return sctp_sf_authenticate(asoc
, &auth
) == SCTP_IERROR_NO_ERROR
;
667 * Respond to a normal COOKIE ECHO chunk.
668 * We are the side that is being asked for an association.
670 * Section: 5.1 Normal Establishment of an Association, D
671 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
672 * with a COOKIE ACK chunk after building a TCB and moving to
673 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
674 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
675 * chunk MUST be the first chunk in the packet.
677 * IMPLEMENTATION NOTE: An implementation may choose to send the
678 * Communication Up notification to the SCTP user upon reception
679 * of a valid COOKIE ECHO chunk.
681 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
682 * D) Rules for packet carrying a COOKIE ECHO
684 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
685 * Initial Tag received in the INIT ACK.
687 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
690 * (endpoint, asoc, chunk)
693 * (asoc, reply_msg, msg_up, timers, counters)
695 * The return value is the disposition of the chunk.
697 enum sctp_disposition
sctp_sf_do_5_1D_ce(struct net
*net
,
698 const struct sctp_endpoint
*ep
,
699 const struct sctp_association
*asoc
,
700 const union sctp_subtype type
,
702 struct sctp_cmd_seq
*commands
)
704 struct sctp_ulpevent
*ev
, *ai_ev
= NULL
, *auth_ev
= NULL
;
705 struct sctp_association
*new_asoc
;
706 struct sctp_init_chunk
*peer_init
;
707 struct sctp_chunk
*chunk
= arg
;
708 struct sctp_chunk
*err_chk_p
;
709 struct sctp_chunk
*repl
;
713 if (asoc
&& !sctp_vtag_verify(chunk
, asoc
))
714 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
716 /* If the packet is an OOTB packet which is temporarily on the
717 * control endpoint, respond with an ABORT.
719 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
) {
720 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
721 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
724 /* Make sure that the COOKIE_ECHO chunk has a valid length.
725 * In this case, we check that we have enough for at least a
726 * chunk header. More detailed verification is done
727 * in sctp_unpack_cookie().
729 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
730 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
733 /* If the endpoint is not listening or if the number of associations
734 * on the TCP-style socket exceed the max backlog, respond with an
738 if (!sctp_sstate(sk
, LISTENING
) ||
739 (sctp_style(sk
, TCP
) && sk_acceptq_is_full(sk
)))
740 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
742 /* "Decode" the chunk. We have no optional parameters so we
745 chunk
->subh
.cookie_hdr
=
746 (struct sctp_signed_cookie
*)chunk
->skb
->data
;
747 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
748 sizeof(struct sctp_chunkhdr
)))
751 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
752 * "Z" will reply with a COOKIE ACK chunk after building a TCB
753 * and moving to the ESTABLISHED state.
755 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
759 * If the re-build failed, what is the proper error path
762 * [We should abort the association. --piggy]
765 /* FIXME: Several errors are possible. A bad cookie should
766 * be silently discarded, but think about logging it too.
769 case -SCTP_IERROR_NOMEM
:
772 case -SCTP_IERROR_STALE_COOKIE
:
773 sctp_send_stale_cookie_err(net
, ep
, asoc
, chunk
, commands
,
775 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
777 case -SCTP_IERROR_BAD_SIG
:
779 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
784 /* Delay state machine commands until later.
786 * Re-build the bind address for the association is done in
787 * the sctp_unpack_cookie() already.
789 /* This is a brand-new association, so these are not yet side
790 * effects--it is safe to run them here.
792 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
794 if (!sctp_process_init(new_asoc
, chunk
,
795 &chunk
->subh
.cookie_hdr
->c
.peer_addr
,
796 peer_init
, GFP_ATOMIC
))
799 /* SCTP-AUTH: Now that we've populate required fields in
800 * sctp_process_init, set up the association shared keys as
801 * necessary so that we can potentially authenticate the ACK
803 error
= sctp_auth_asoc_init_active_key(new_asoc
, GFP_ATOMIC
);
807 if (!sctp_auth_chunk_verify(net
, chunk
, new_asoc
)) {
808 sctp_association_free(new_asoc
);
809 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
812 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
816 /* RFC 2960 5.1 Normal Establishment of an Association
818 * D) IMPLEMENTATION NOTE: An implementation may choose to
819 * send the Communication Up notification to the SCTP user
820 * upon reception of a valid COOKIE ECHO chunk.
822 ev
= sctp_ulpevent_make_assoc_change(new_asoc
, 0, SCTP_COMM_UP
, 0,
823 new_asoc
->c
.sinit_num_ostreams
,
824 new_asoc
->c
.sinit_max_instreams
,
829 /* Sockets API Draft Section 5.3.1.6
830 * When a peer sends a Adaptation Layer Indication parameter , SCTP
831 * delivers this notification to inform the application that of the
832 * peers requested adaptation layer.
834 if (new_asoc
->peer
.adaptation_ind
) {
835 ai_ev
= sctp_ulpevent_make_adaptation_indication(new_asoc
,
841 if (!new_asoc
->peer
.auth_capable
) {
842 auth_ev
= sctp_ulpevent_make_authkey(new_asoc
, 0,
849 /* Add all the state machine commands now since we've created
850 * everything. This way we don't introduce memory corruptions
851 * during side-effect processing and correctly count established
854 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
855 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
856 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
857 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
858 SCTP_INC_STATS(net
, SCTP_MIB_PASSIVEESTABS
);
859 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
861 if (new_asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
862 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
863 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
865 /* This will send the COOKIE ACK */
866 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
868 /* Queue the ASSOC_CHANGE event */
869 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
871 /* Send up the Adaptation Layer Indication event */
873 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
874 SCTP_ULPEVENT(ai_ev
));
877 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
878 SCTP_ULPEVENT(auth_ev
));
880 return SCTP_DISPOSITION_CONSUME
;
883 sctp_ulpevent_free(ai_ev
);
885 sctp_ulpevent_free(ev
);
887 sctp_chunk_free(repl
);
889 sctp_association_free(new_asoc
);
891 return SCTP_DISPOSITION_NOMEM
;
895 * Respond to a normal COOKIE ACK chunk.
896 * We are the side that is asking for an association.
898 * RFC 2960 5.1 Normal Establishment of an Association
900 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
901 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
902 * timer. It may also notify its ULP about the successful
903 * establishment of the association with a Communication Up
904 * notification (see Section 10).
908 * (endpoint, asoc, chunk)
911 * (asoc, reply_msg, msg_up, timers, counters)
913 * The return value is the disposition of the chunk.
915 enum sctp_disposition
sctp_sf_do_5_1E_ca(struct net
*net
,
916 const struct sctp_endpoint
*ep
,
917 const struct sctp_association
*asoc
,
918 const union sctp_subtype type
,
920 struct sctp_cmd_seq
*commands
)
922 struct sctp_chunk
*chunk
= arg
;
923 struct sctp_ulpevent
*ev
;
925 if (!sctp_vtag_verify(chunk
, asoc
))
926 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
928 /* Verify that the chunk length for the COOKIE-ACK is OK.
929 * If we don't do this, any bundled chunks may be junked.
931 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
932 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
935 /* Reset init error count upon receipt of COOKIE-ACK,
936 * to avoid problems with the management of this
937 * counter in stale cookie situations when a transition back
938 * from the COOKIE-ECHOED state to the COOKIE-WAIT
939 * state is performed.
941 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
943 /* Set peer label for connection. */
944 security_inet_conn_established(ep
->base
.sk
, chunk
->skb
);
946 /* RFC 2960 5.1 Normal Establishment of an Association
948 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
949 * from the COOKIE-ECHOED state to the ESTABLISHED state,
950 * stopping the T1-cookie timer.
952 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
953 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
954 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
955 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
956 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
957 SCTP_INC_STATS(net
, SCTP_MIB_ACTIVEESTABS
);
958 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
959 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
960 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
961 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
963 /* It may also notify its ULP about the successful
964 * establishment of the association with a Communication Up
965 * notification (see Section 10).
967 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_COMM_UP
,
968 0, asoc
->c
.sinit_num_ostreams
,
969 asoc
->c
.sinit_max_instreams
,
975 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
977 /* Sockets API Draft Section 5.3.1.6
978 * When a peer sends a Adaptation Layer Indication parameter , SCTP
979 * delivers this notification to inform the application that of the
980 * peers requested adaptation layer.
982 if (asoc
->peer
.adaptation_ind
) {
983 ev
= sctp_ulpevent_make_adaptation_indication(asoc
, GFP_ATOMIC
);
987 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
991 if (!asoc
->peer
.auth_capable
) {
992 ev
= sctp_ulpevent_make_authkey(asoc
, 0, SCTP_AUTH_NO_AUTH
,
996 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1000 return SCTP_DISPOSITION_CONSUME
;
1002 return SCTP_DISPOSITION_NOMEM
;
1005 /* Generate and sendout a heartbeat packet. */
1006 static enum sctp_disposition
sctp_sf_heartbeat(
1007 const struct sctp_endpoint
*ep
,
1008 const struct sctp_association
*asoc
,
1009 const union sctp_subtype type
,
1011 struct sctp_cmd_seq
*commands
)
1013 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
1014 struct sctp_chunk
*reply
;
1016 /* Send a heartbeat to our peer. */
1017 reply
= sctp_make_heartbeat(asoc
, transport
, 0);
1019 return SCTP_DISPOSITION_NOMEM
;
1021 /* Set rto_pending indicating that an RTT measurement
1022 * is started with this heartbeat chunk.
1024 sctp_add_cmd_sf(commands
, SCTP_CMD_RTO_PENDING
,
1025 SCTP_TRANSPORT(transport
));
1027 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
1028 return SCTP_DISPOSITION_CONSUME
;
1031 /* Generate a HEARTBEAT packet on the given transport. */
1032 enum sctp_disposition
sctp_sf_sendbeat_8_3(struct net
*net
,
1033 const struct sctp_endpoint
*ep
,
1034 const struct sctp_association
*asoc
,
1035 const union sctp_subtype type
,
1037 struct sctp_cmd_seq
*commands
)
1039 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
1041 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
1042 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
1043 SCTP_ERROR(ETIMEDOUT
));
1044 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
1045 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
1046 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
1047 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
1048 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
1049 return SCTP_DISPOSITION_DELETE_TCB
;
1053 * The Sender-specific Heartbeat Info field should normally include
1054 * information about the sender's current time when this HEARTBEAT
1055 * chunk is sent and the destination transport address to which this
1056 * HEARTBEAT is sent (see Section 8.3).
1059 if (transport
->param_flags
& SPP_HB_ENABLE
) {
1060 if (SCTP_DISPOSITION_NOMEM
==
1061 sctp_sf_heartbeat(ep
, asoc
, type
, arg
,
1063 return SCTP_DISPOSITION_NOMEM
;
1065 /* Set transport error counter and association error counter
1066 * when sending heartbeat.
1068 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
1069 SCTP_TRANSPORT(transport
));
1071 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_IDLE
,
1072 SCTP_TRANSPORT(transport
));
1073 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMER_UPDATE
,
1074 SCTP_TRANSPORT(transport
));
1076 return SCTP_DISPOSITION_CONSUME
;
1079 /* resend asoc strreset_chunk. */
1080 enum sctp_disposition
sctp_sf_send_reconf(struct net
*net
,
1081 const struct sctp_endpoint
*ep
,
1082 const struct sctp_association
*asoc
,
1083 const union sctp_subtype type
,
1085 struct sctp_cmd_seq
*commands
)
1087 struct sctp_transport
*transport
= arg
;
1089 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
1090 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
1091 SCTP_ERROR(ETIMEDOUT
));
1092 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
1093 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
1094 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
1095 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
1096 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
1097 return SCTP_DISPOSITION_DELETE_TCB
;
1100 sctp_chunk_hold(asoc
->strreset_chunk
);
1101 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1102 SCTP_CHUNK(asoc
->strreset_chunk
));
1103 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
1105 return SCTP_DISPOSITION_CONSUME
;
1108 /* send hb chunk with padding for PLPMUTD. */
1109 enum sctp_disposition
sctp_sf_send_probe(struct net
*net
,
1110 const struct sctp_endpoint
*ep
,
1111 const struct sctp_association
*asoc
,
1112 const union sctp_subtype type
,
1114 struct sctp_cmd_seq
*commands
)
1116 struct sctp_transport
*transport
= (struct sctp_transport
*)arg
;
1117 struct sctp_chunk
*reply
;
1119 if (!sctp_transport_pl_enabled(transport
))
1120 return SCTP_DISPOSITION_CONSUME
;
1122 if (sctp_transport_pl_send(transport
)) {
1123 reply
= sctp_make_heartbeat(asoc
, transport
, transport
->pl
.probe_size
);
1125 return SCTP_DISPOSITION_NOMEM
;
1126 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
1128 sctp_add_cmd_sf(commands
, SCTP_CMD_PROBE_TIMER_UPDATE
,
1129 SCTP_TRANSPORT(transport
));
1131 return SCTP_DISPOSITION_CONSUME
;
1135 * Process an heartbeat request.
1137 * Section: 8.3 Path Heartbeat
1138 * The receiver of the HEARTBEAT should immediately respond with a
1139 * HEARTBEAT ACK that contains the Heartbeat Information field copied
1140 * from the received HEARTBEAT chunk.
1142 * Verification Tag: 8.5 Verification Tag [Normal verification]
1143 * When receiving an SCTP packet, the endpoint MUST ensure that the
1144 * value in the Verification Tag field of the received SCTP packet
1145 * matches its own Tag. If the received Verification Tag value does not
1146 * match the receiver's own tag value, the receiver shall silently
1147 * discard the packet and shall not process it any further except for
1148 * those cases listed in Section 8.5.1 below.
1151 * (endpoint, asoc, chunk)
1154 * (asoc, reply_msg, msg_up, timers, counters)
1156 * The return value is the disposition of the chunk.
1158 enum sctp_disposition
sctp_sf_beat_8_3(struct net
*net
,
1159 const struct sctp_endpoint
*ep
,
1160 const struct sctp_association
*asoc
,
1161 const union sctp_subtype type
,
1162 void *arg
, struct sctp_cmd_seq
*commands
)
1164 struct sctp_paramhdr
*param_hdr
;
1165 struct sctp_chunk
*chunk
= arg
;
1166 struct sctp_chunk
*reply
;
1169 if (!sctp_vtag_verify(chunk
, asoc
))
1170 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1172 /* Make sure that the HEARTBEAT chunk has a valid length. */
1173 if (!sctp_chunk_length_valid(chunk
,
1174 sizeof(struct sctp_heartbeat_chunk
)))
1175 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1178 /* 8.3 The receiver of the HEARTBEAT should immediately
1179 * respond with a HEARTBEAT ACK that contains the Heartbeat
1180 * Information field copied from the received HEARTBEAT chunk.
1182 chunk
->subh
.hb_hdr
= (struct sctp_heartbeathdr
*)chunk
->skb
->data
;
1183 param_hdr
= (struct sctp_paramhdr
*)chunk
->subh
.hb_hdr
;
1184 paylen
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(struct sctp_chunkhdr
);
1186 if (ntohs(param_hdr
->length
) > paylen
)
1187 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
1188 param_hdr
, commands
);
1190 if (!pskb_pull(chunk
->skb
, paylen
))
1193 reply
= sctp_make_heartbeat_ack(asoc
, chunk
, param_hdr
, paylen
);
1197 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
1198 return SCTP_DISPOSITION_CONSUME
;
1201 return SCTP_DISPOSITION_NOMEM
;
1205 * Process the returning HEARTBEAT ACK.
1207 * Section: 8.3 Path Heartbeat
1208 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
1209 * should clear the error counter of the destination transport
1210 * address to which the HEARTBEAT was sent, and mark the destination
1211 * transport address as active if it is not so marked. The endpoint may
1212 * optionally report to the upper layer when an inactive destination
1213 * address is marked as active due to the reception of the latest
1214 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
1215 * clear the association overall error count as well (as defined
1218 * The receiver of the HEARTBEAT ACK should also perform an RTT
1219 * measurement for that destination transport address using the time
1220 * value carried in the HEARTBEAT ACK chunk.
1222 * Verification Tag: 8.5 Verification Tag [Normal verification]
1225 * (endpoint, asoc, chunk)
1228 * (asoc, reply_msg, msg_up, timers, counters)
1230 * The return value is the disposition of the chunk.
1232 enum sctp_disposition
sctp_sf_backbeat_8_3(struct net
*net
,
1233 const struct sctp_endpoint
*ep
,
1234 const struct sctp_association
*asoc
,
1235 const union sctp_subtype type
,
1237 struct sctp_cmd_seq
*commands
)
1239 struct sctp_sender_hb_info
*hbinfo
;
1240 struct sctp_chunk
*chunk
= arg
;
1241 struct sctp_transport
*link
;
1242 unsigned long max_interval
;
1243 union sctp_addr from_addr
;
1245 if (!sctp_vtag_verify(chunk
, asoc
))
1246 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1248 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1249 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
) +
1251 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1254 hbinfo
= (struct sctp_sender_hb_info
*)chunk
->skb
->data
;
1255 /* Make sure that the length of the parameter is what we expect */
1256 if (ntohs(hbinfo
->param_hdr
.length
) != sizeof(*hbinfo
))
1257 return SCTP_DISPOSITION_DISCARD
;
1259 from_addr
= hbinfo
->daddr
;
1260 link
= sctp_assoc_lookup_paddr(asoc
, &from_addr
);
1262 /* This should never happen, but lets log it if so. */
1263 if (unlikely(!link
)) {
1264 if (from_addr
.sa
.sa_family
== AF_INET6
) {
1265 net_warn_ratelimited("%s association %p could not find address %pI6\n",
1268 &from_addr
.v6
.sin6_addr
);
1270 net_warn_ratelimited("%s association %p could not find address %pI4\n",
1273 &from_addr
.v4
.sin_addr
.s_addr
);
1275 return SCTP_DISPOSITION_DISCARD
;
1278 /* Validate the 64-bit random nonce. */
1279 if (hbinfo
->hb_nonce
!= link
->hb_nonce
)
1280 return SCTP_DISPOSITION_DISCARD
;
1282 if (hbinfo
->probe_size
) {
1283 if (hbinfo
->probe_size
!= link
->pl
.probe_size
||
1284 !sctp_transport_pl_enabled(link
))
1285 return SCTP_DISPOSITION_DISCARD
;
1287 if (sctp_transport_pl_recv(link
))
1288 return SCTP_DISPOSITION_CONSUME
;
1290 return sctp_sf_send_probe(net
, ep
, asoc
, type
, link
, commands
);
1293 max_interval
= link
->hbinterval
+ link
->rto
;
1295 /* Check if the timestamp looks valid. */
1296 if (time_after(hbinfo
->sent_at
, jiffies
) ||
1297 time_after(jiffies
, hbinfo
->sent_at
+ max_interval
)) {
1298 pr_debug("%s: HEARTBEAT ACK with invalid timestamp received "
1299 "for transport:%p\n", __func__
, link
);
1301 return SCTP_DISPOSITION_DISCARD
;
1304 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1305 * the HEARTBEAT should clear the error counter of the
1306 * destination transport address to which the HEARTBEAT was
1307 * sent and mark the destination transport address as active if
1308 * it is not so marked.
1310 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_ON
, SCTP_TRANSPORT(link
));
1312 return SCTP_DISPOSITION_CONSUME
;
1315 /* Helper function to send out an abort for the restart
1318 static int sctp_sf_send_restart_abort(struct net
*net
, union sctp_addr
*ssa
,
1319 struct sctp_chunk
*init
,
1320 struct sctp_cmd_seq
*commands
)
1322 struct sctp_af
*af
= sctp_get_af_specific(ssa
->v4
.sin_family
);
1323 union sctp_addr_param
*addrparm
;
1324 struct sctp_errhdr
*errhdr
;
1325 char buffer
[sizeof(*errhdr
) + sizeof(*addrparm
)];
1326 struct sctp_endpoint
*ep
;
1327 struct sctp_packet
*pkt
;
1330 /* Build the error on the stack. We are way to malloc crazy
1331 * throughout the code today.
1333 errhdr
= (struct sctp_errhdr
*)buffer
;
1334 addrparm
= (union sctp_addr_param
*)errhdr
->variable
;
1336 /* Copy into a parm format. */
1337 len
= af
->to_addr_param(ssa
, addrparm
);
1338 len
+= sizeof(*errhdr
);
1340 errhdr
->cause
= SCTP_ERROR_RESTART
;
1341 errhdr
->length
= htons(len
);
1343 /* Assign to the control socket. */
1344 ep
= sctp_sk(net
->sctp
.ctl_sock
)->ep
;
1346 /* Association is NULL since this may be a restart attack and we
1347 * want to send back the attacker's vtag.
1349 pkt
= sctp_abort_pkt_new(net
, ep
, NULL
, init
, errhdr
, len
);
1353 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
, SCTP_PACKET(pkt
));
1355 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
1357 /* Discard the rest of the inbound packet. */
1358 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
1361 /* Even if there is no memory, treat as a failure so
1362 * the packet will get dropped.
1367 static bool list_has_sctp_addr(const struct list_head
*list
,
1368 union sctp_addr
*ipaddr
)
1370 struct sctp_transport
*addr
;
1372 list_for_each_entry(addr
, list
, transports
) {
1373 if (sctp_cmp_addr_exact(ipaddr
, &addr
->ipaddr
))
1379 /* A restart is occurring, check to make sure no new addresses
1380 * are being added as we may be under a takeover attack.
1382 static int sctp_sf_check_restart_addrs(const struct sctp_association
*new_asoc
,
1383 const struct sctp_association
*asoc
,
1384 struct sctp_chunk
*init
,
1385 struct sctp_cmd_seq
*commands
)
1387 struct net
*net
= new_asoc
->base
.net
;
1388 struct sctp_transport
*new_addr
;
1391 /* Implementor's Guide - Section 5.2.2
1393 * Before responding the endpoint MUST check to see if the
1394 * unexpected INIT adds new addresses to the association. If new
1395 * addresses are added to the association, the endpoint MUST respond
1399 /* Search through all current addresses and make sure
1400 * we aren't adding any new ones.
1402 list_for_each_entry(new_addr
, &new_asoc
->peer
.transport_addr_list
,
1404 if (!list_has_sctp_addr(&asoc
->peer
.transport_addr_list
,
1405 &new_addr
->ipaddr
)) {
1406 sctp_sf_send_restart_abort(net
, &new_addr
->ipaddr
, init
,
1413 /* Return success if all addresses were found. */
1417 /* Populate the verification/tie tags based on overlapping INIT
1420 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1422 static void sctp_tietags_populate(struct sctp_association
*new_asoc
,
1423 const struct sctp_association
*asoc
)
1425 switch (asoc
->state
) {
1427 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1429 case SCTP_STATE_COOKIE_WAIT
:
1430 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1431 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1432 new_asoc
->c
.peer_ttag
= 0;
1435 case SCTP_STATE_COOKIE_ECHOED
:
1436 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1437 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1438 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1441 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1442 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1445 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1446 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1450 /* Other parameters for the endpoint SHOULD be copied from the
1451 * existing parameters of the association (e.g. number of
1452 * outbound streams) into the INIT ACK and cookie.
1454 new_asoc
->rwnd
= asoc
->rwnd
;
1455 new_asoc
->c
.sinit_num_ostreams
= asoc
->c
.sinit_num_ostreams
;
1456 new_asoc
->c
.sinit_max_instreams
= asoc
->c
.sinit_max_instreams
;
1457 new_asoc
->c
.initial_tsn
= asoc
->c
.initial_tsn
;
1461 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1464 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1466 * Returns value representing action to be taken. These action values
1467 * correspond to Action/Description values in RFC 2960, Table 2.
1469 static char sctp_tietags_compare(struct sctp_association
*new_asoc
,
1470 const struct sctp_association
*asoc
)
1472 /* In this case, the peer may have restarted. */
1473 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1474 (asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) &&
1475 (asoc
->c
.my_vtag
== new_asoc
->c
.my_ttag
) &&
1476 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_ttag
))
1479 /* Collision case B. */
1480 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1481 ((asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) ||
1482 (0 == asoc
->c
.peer_vtag
))) {
1486 /* Collision case D. */
1487 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1488 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
))
1491 /* Collision case C. */
1492 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1493 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
) &&
1494 (0 == new_asoc
->c
.my_ttag
) &&
1495 (0 == new_asoc
->c
.peer_ttag
))
1498 /* No match to any of the special cases; discard this packet. */
1502 /* Common helper routine for both duplicate and simultaneous INIT
1505 static enum sctp_disposition
sctp_sf_do_unexpected_init(
1507 const struct sctp_endpoint
*ep
,
1508 const struct sctp_association
*asoc
,
1509 const union sctp_subtype type
,
1511 struct sctp_cmd_seq
*commands
)
1513 struct sctp_chunk
*chunk
= arg
, *repl
, *err_chunk
;
1514 struct sctp_unrecognized_param
*unk_param
;
1515 struct sctp_association
*new_asoc
;
1516 enum sctp_disposition retval
;
1517 struct sctp_packet
*packet
;
1520 /* Update socket peer label if first association. */
1521 if (security_sctp_assoc_request((struct sctp_endpoint
*)ep
,
1523 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1526 * An endpoint MUST NOT bundle INIT, INIT ACK or
1527 * SHUTDOWN COMPLETE with any other chunks.
1530 * Furthermore, we require that the receiver of an INIT chunk MUST
1531 * enforce these rules by silently discarding an arriving packet
1532 * with an INIT chunk that is bundled with other chunks.
1534 if (!chunk
->singleton
)
1535 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1537 /* Make sure that the INIT chunk has a valid length. */
1538 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_init_chunk
)))
1539 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1541 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1544 if (chunk
->sctp_hdr
->vtag
!= 0)
1545 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
1547 if (SCTP_INPUT_CB(chunk
->skb
)->encap_port
!= chunk
->transport
->encap_port
)
1548 return sctp_sf_new_encap_port(net
, ep
, asoc
, type
, arg
, commands
);
1550 /* Grab the INIT header. */
1551 chunk
->subh
.init_hdr
= (struct sctp_inithdr
*)chunk
->skb
->data
;
1553 /* Tag the variable length parameters. */
1554 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(struct sctp_inithdr
));
1556 /* Verify the INIT chunk before processing it. */
1558 if (!sctp_verify_init(net
, ep
, asoc
, chunk
->chunk_hdr
->type
,
1559 (struct sctp_init_chunk
*)chunk
->chunk_hdr
, chunk
,
1561 /* This chunk contains fatal error. It is to be discarded.
1562 * Send an ABORT, with causes if there is any.
1565 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
1566 (__u8
*)(err_chunk
->chunk_hdr
) +
1567 sizeof(struct sctp_chunkhdr
),
1568 ntohs(err_chunk
->chunk_hdr
->length
) -
1569 sizeof(struct sctp_chunkhdr
));
1572 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
1573 SCTP_PACKET(packet
));
1574 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
1575 retval
= SCTP_DISPOSITION_CONSUME
;
1577 retval
= SCTP_DISPOSITION_NOMEM
;
1581 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
,
1587 * Other parameters for the endpoint SHOULD be copied from the
1588 * existing parameters of the association (e.g. number of
1589 * outbound streams) into the INIT ACK and cookie.
1590 * FIXME: We are copying parameters from the endpoint not the
1593 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
1597 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
,
1598 sctp_scope(sctp_source(chunk
)), GFP_ATOMIC
) < 0)
1601 /* In the outbound INIT ACK the endpoint MUST copy its current
1602 * Verification Tag and Peers Verification tag into a reserved
1603 * place (local tie-tag and per tie-tag) within the state cookie.
1605 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
),
1606 (struct sctp_init_chunk
*)chunk
->chunk_hdr
,
1610 /* Make sure no new addresses are being added during the
1611 * restart. Do not do this check for COOKIE-WAIT state,
1612 * since there are no peer addresses to check against.
1613 * Upon return an ABORT will have been sent if needed.
1615 if (!sctp_state(asoc
, COOKIE_WAIT
)) {
1616 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
,
1618 retval
= SCTP_DISPOSITION_CONSUME
;
1623 sctp_tietags_populate(new_asoc
, asoc
);
1625 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1627 /* If there are errors need to be reported for unknown parameters,
1628 * make sure to reserve enough room in the INIT ACK for them.
1632 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
1633 sizeof(struct sctp_chunkhdr
);
1636 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
1640 /* If there are errors need to be reported for unknown parameters,
1641 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1645 /* Get the "Unrecognized parameter" parameter(s) out of the
1646 * ERROR chunk generated by sctp_verify_init(). Since the
1647 * error cause code for "unknown parameter" and the
1648 * "Unrecognized parameter" type is the same, we can
1649 * construct the parameters in INIT ACK by copying the
1650 * ERROR causes over.
1652 unk_param
= (struct sctp_unrecognized_param
*)
1653 ((__u8
*)(err_chunk
->chunk_hdr
) +
1654 sizeof(struct sctp_chunkhdr
));
1655 /* Replace the cause code with the "Unrecognized parameter"
1658 sctp_addto_chunk(repl
, len
, unk_param
);
1661 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
1662 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1665 * Note: After sending out INIT ACK with the State Cookie parameter,
1666 * "Z" MUST NOT allocate any resources for this new association.
1667 * Otherwise, "Z" will be vulnerable to resource attacks.
1669 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
1670 retval
= SCTP_DISPOSITION_CONSUME
;
1675 retval
= SCTP_DISPOSITION_NOMEM
;
1678 sctp_association_free(new_asoc
);
1681 sctp_chunk_free(err_chunk
);
1686 * Handle simultaneous INIT.
1687 * This means we started an INIT and then we got an INIT request from
1690 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1691 * This usually indicates an initialization collision, i.e., each
1692 * endpoint is attempting, at about the same time, to establish an
1693 * association with the other endpoint.
1695 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1696 * endpoint MUST respond with an INIT ACK using the same parameters it
1697 * sent in its original INIT chunk (including its Verification Tag,
1698 * unchanged). These original parameters are combined with those from the
1699 * newly received INIT chunk. The endpoint shall also generate a State
1700 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1701 * INIT to calculate the State Cookie.
1703 * After that, the endpoint MUST NOT change its state, the T1-init
1704 * timer shall be left running and the corresponding TCB MUST NOT be
1705 * destroyed. The normal procedures for handling State Cookies when
1706 * a TCB exists will resolve the duplicate INITs to a single association.
1708 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1709 * its Tie-Tags with the Tag information of itself and its peer (see
1710 * section 5.2.2 for a description of the Tie-Tags).
1712 * Verification Tag: Not explicit, but an INIT can not have a valid
1713 * verification tag, so we skip the check.
1716 * (endpoint, asoc, chunk)
1719 * (asoc, reply_msg, msg_up, timers, counters)
1721 * The return value is the disposition of the chunk.
1723 enum sctp_disposition
sctp_sf_do_5_2_1_siminit(
1725 const struct sctp_endpoint
*ep
,
1726 const struct sctp_association
*asoc
,
1727 const union sctp_subtype type
,
1729 struct sctp_cmd_seq
*commands
)
1731 /* Call helper to do the real work for both simultaneous and
1732 * duplicate INIT chunk handling.
1734 return sctp_sf_do_unexpected_init(net
, ep
, asoc
, type
, arg
, commands
);
1738 * Handle duplicated INIT messages. These are usually delayed
1741 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1742 * COOKIE-ECHOED and COOKIE-WAIT
1744 * Unless otherwise stated, upon reception of an unexpected INIT for
1745 * this association, the endpoint shall generate an INIT ACK with a
1746 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1747 * current Verification Tag and peer's Verification Tag into a reserved
1748 * place within the state cookie. We shall refer to these locations as
1749 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1750 * containing this INIT ACK MUST carry a Verification Tag value equal to
1751 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1752 * MUST contain a new Initiation Tag (randomly generated see Section
1753 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1754 * existing parameters of the association (e.g. number of outbound
1755 * streams) into the INIT ACK and cookie.
1757 * After sending out the INIT ACK, the endpoint shall take no further
1758 * actions, i.e., the existing association, including its current state,
1759 * and the corresponding TCB MUST NOT be changed.
1761 * Note: Only when a TCB exists and the association is not in a COOKIE-
1762 * WAIT state are the Tie-Tags populated. For a normal association INIT
1763 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1764 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1765 * State Cookie are populated as specified in section 5.2.1.
1767 * Verification Tag: Not specified, but an INIT has no way of knowing
1768 * what the verification tag could be, so we ignore it.
1771 * (endpoint, asoc, chunk)
1774 * (asoc, reply_msg, msg_up, timers, counters)
1776 * The return value is the disposition of the chunk.
1778 enum sctp_disposition
sctp_sf_do_5_2_2_dupinit(
1780 const struct sctp_endpoint
*ep
,
1781 const struct sctp_association
*asoc
,
1782 const union sctp_subtype type
,
1784 struct sctp_cmd_seq
*commands
)
1786 /* Call helper to do the real work for both simultaneous and
1787 * duplicate INIT chunk handling.
1789 return sctp_sf_do_unexpected_init(net
, ep
, asoc
, type
, arg
, commands
);
1794 * Unexpected INIT-ACK handler.
1797 * If an INIT ACK received by an endpoint in any state other than the
1798 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1799 * An unexpected INIT ACK usually indicates the processing of an old or
1800 * duplicated INIT chunk.
1802 enum sctp_disposition
sctp_sf_do_5_2_3_initack(
1804 const struct sctp_endpoint
*ep
,
1805 const struct sctp_association
*asoc
,
1806 const union sctp_subtype type
,
1808 struct sctp_cmd_seq
*commands
)
1810 /* Per the above section, we'll discard the chunk if we have an
1811 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1813 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
)
1814 return sctp_sf_ootb(net
, ep
, asoc
, type
, arg
, commands
);
1816 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
1819 static int sctp_sf_do_assoc_update(struct sctp_association
*asoc
,
1820 struct sctp_association
*new,
1821 struct sctp_cmd_seq
*cmds
)
1823 struct net
*net
= asoc
->base
.net
;
1824 struct sctp_chunk
*abort
;
1826 if (!sctp_assoc_update(asoc
, new))
1829 abort
= sctp_make_abort(asoc
, NULL
, sizeof(struct sctp_errhdr
));
1831 sctp_init_cause(abort
, SCTP_ERROR_RSRC_LOW
, 0);
1832 sctp_add_cmd_sf(cmds
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
1834 sctp_add_cmd_sf(cmds
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(ECONNABORTED
));
1835 sctp_add_cmd_sf(cmds
, SCTP_CMD_ASSOC_FAILED
,
1836 SCTP_PERR(SCTP_ERROR_RSRC_LOW
));
1837 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
1838 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
1843 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1846 * A) In this case, the peer may have restarted.
1848 static enum sctp_disposition
sctp_sf_do_dupcook_a(
1850 const struct sctp_endpoint
*ep
,
1851 const struct sctp_association
*asoc
,
1852 struct sctp_chunk
*chunk
,
1853 struct sctp_cmd_seq
*commands
,
1854 struct sctp_association
*new_asoc
)
1856 struct sctp_init_chunk
*peer_init
;
1857 enum sctp_disposition disposition
;
1858 struct sctp_ulpevent
*ev
;
1859 struct sctp_chunk
*repl
;
1860 struct sctp_chunk
*err
;
1862 /* new_asoc is a brand-new association, so these are not yet
1863 * side effects--it is safe to run them here.
1865 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1867 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
), peer_init
,
1871 if (sctp_auth_asoc_init_active_key(new_asoc
, GFP_ATOMIC
))
1874 if (!sctp_auth_chunk_verify(net
, chunk
, new_asoc
))
1875 return SCTP_DISPOSITION_DISCARD
;
1877 /* Make sure no new addresses are being added during the
1878 * restart. Though this is a pretty complicated attack
1879 * since you'd have to get inside the cookie.
1881 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
, commands
))
1882 return SCTP_DISPOSITION_CONSUME
;
1884 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1885 * the peer has restarted (Action A), it MUST NOT setup a new
1886 * association but instead resend the SHUTDOWN ACK and send an ERROR
1887 * chunk with a "Cookie Received while Shutting Down" error cause to
1890 if (sctp_state(asoc
, SHUTDOWN_ACK_SENT
)) {
1891 disposition
= __sctp_sf_do_9_2_reshutack(net
, ep
, asoc
,
1892 SCTP_ST_CHUNK(chunk
->chunk_hdr
->type
),
1894 if (SCTP_DISPOSITION_NOMEM
== disposition
)
1897 err
= sctp_make_op_error(asoc
, chunk
,
1898 SCTP_ERROR_COOKIE_IN_SHUTDOWN
,
1901 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1904 return SCTP_DISPOSITION_CONSUME
;
1907 /* For now, stop pending T3-rtx and SACK timers, fail any unsent/unacked
1908 * data. Consider the optional choice of resending of this data.
1910 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
1911 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1912 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK
));
1913 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_OUTQUEUE
, SCTP_NULL());
1915 /* Stop pending T4-rto timer, teardown ASCONF queue, ASCONF-ACK queue
1916 * and ASCONF-ACK cache.
1918 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1919 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
1920 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_ASCONF_QUEUE
, SCTP_NULL());
1922 /* Update the content of current association. */
1923 if (sctp_sf_do_assoc_update((struct sctp_association
*)asoc
, new_asoc
, commands
))
1926 repl
= sctp_make_cookie_ack(asoc
, chunk
);
1930 /* Report association restart to upper layer. */
1931 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_RESTART
, 0,
1932 asoc
->c
.sinit_num_ostreams
,
1933 asoc
->c
.sinit_max_instreams
,
1938 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
1939 if ((sctp_state(asoc
, SHUTDOWN_PENDING
) ||
1940 sctp_state(asoc
, SHUTDOWN_SENT
)) &&
1941 (sctp_sstate(asoc
->base
.sk
, CLOSING
) ||
1942 sock_flag(asoc
->base
.sk
, SOCK_DEAD
))) {
1943 /* If the socket has been closed by user, don't
1944 * transition to ESTABLISHED. Instead trigger SHUTDOWN
1945 * bundled with COOKIE_ACK.
1947 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1948 return sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
,
1949 SCTP_ST_CHUNK(0), repl
,
1952 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1953 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1954 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1956 return SCTP_DISPOSITION_CONSUME
;
1959 sctp_chunk_free(repl
);
1961 return SCTP_DISPOSITION_NOMEM
;
1964 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1967 * B) In this case, both sides may be attempting to start an association
1968 * at about the same time but the peer endpoint started its INIT
1969 * after responding to the local endpoint's INIT
1971 /* This case represents an initialization collision. */
1972 static enum sctp_disposition
sctp_sf_do_dupcook_b(
1974 const struct sctp_endpoint
*ep
,
1975 const struct sctp_association
*asoc
,
1976 struct sctp_chunk
*chunk
,
1977 struct sctp_cmd_seq
*commands
,
1978 struct sctp_association
*new_asoc
)
1980 struct sctp_init_chunk
*peer_init
;
1981 struct sctp_chunk
*repl
;
1983 /* new_asoc is a brand-new association, so these are not yet
1984 * side effects--it is safe to run them here.
1986 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1987 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
), peer_init
,
1991 if (sctp_auth_asoc_init_active_key(new_asoc
, GFP_ATOMIC
))
1994 if (!sctp_auth_chunk_verify(net
, chunk
, new_asoc
))
1995 return SCTP_DISPOSITION_DISCARD
;
1997 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1998 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1999 if (asoc
->state
< SCTP_STATE_ESTABLISHED
)
2000 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
2001 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
2003 /* Update the content of current association. */
2004 if (sctp_sf_do_assoc_update((struct sctp_association
*)asoc
, new_asoc
, commands
))
2007 repl
= sctp_make_cookie_ack(asoc
, chunk
);
2011 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
2013 /* RFC 2960 5.1 Normal Establishment of an Association
2015 * D) IMPLEMENTATION NOTE: An implementation may choose to
2016 * send the Communication Up notification to the SCTP user
2017 * upon reception of a valid COOKIE ECHO chunk.
2019 * Sadly, this needs to be implemented as a side-effect, because
2020 * we are not guaranteed to have set the association id of the real
2021 * association and so these notifications need to be delayed until
2022 * the association id is allocated.
2025 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_CHANGE
, SCTP_U8(SCTP_COMM_UP
));
2027 /* Sockets API Draft Section 5.3.1.6
2028 * When a peer sends a Adaptation Layer Indication parameter , SCTP
2029 * delivers this notification to inform the application that of the
2030 * peers requested adaptation layer.
2032 * This also needs to be done as a side effect for the same reason as
2035 if (asoc
->peer
.adaptation_ind
)
2036 sctp_add_cmd_sf(commands
, SCTP_CMD_ADAPTATION_IND
, SCTP_NULL());
2038 if (!asoc
->peer
.auth_capable
)
2039 sctp_add_cmd_sf(commands
, SCTP_CMD_PEER_NO_AUTH
, SCTP_NULL());
2041 return SCTP_DISPOSITION_CONSUME
;
2044 return SCTP_DISPOSITION_NOMEM
;
2047 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
2050 * C) In this case, the local endpoint's cookie has arrived late.
2051 * Before it arrived, the local endpoint sent an INIT and received an
2052 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
2053 * but a new tag of its own.
2055 /* This case represents an initialization collision. */
2056 static enum sctp_disposition
sctp_sf_do_dupcook_c(
2058 const struct sctp_endpoint
*ep
,
2059 const struct sctp_association
*asoc
,
2060 struct sctp_chunk
*chunk
,
2061 struct sctp_cmd_seq
*commands
,
2062 struct sctp_association
*new_asoc
)
2064 /* The cookie should be silently discarded.
2065 * The endpoint SHOULD NOT change states and should leave
2066 * any timers running.
2068 return SCTP_DISPOSITION_DISCARD
;
2071 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
2075 * D) When both local and remote tags match the endpoint should always
2076 * enter the ESTABLISHED state, if it has not already done so.
2078 /* This case represents an initialization collision. */
2079 static enum sctp_disposition
sctp_sf_do_dupcook_d(
2081 const struct sctp_endpoint
*ep
,
2082 const struct sctp_association
*asoc
,
2083 struct sctp_chunk
*chunk
,
2084 struct sctp_cmd_seq
*commands
,
2085 struct sctp_association
*new_asoc
)
2087 struct sctp_ulpevent
*ev
= NULL
, *ai_ev
= NULL
, *auth_ev
= NULL
;
2088 struct sctp_chunk
*repl
;
2090 /* Clarification from Implementor's Guide:
2091 * D) When both local and remote tags match the endpoint should
2092 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
2093 * It should stop any cookie timer that may be running and send
2097 if (!sctp_auth_chunk_verify(net
, chunk
, asoc
))
2098 return SCTP_DISPOSITION_DISCARD
;
2100 /* Don't accidentally move back into established state. */
2101 if (asoc
->state
< SCTP_STATE_ESTABLISHED
) {
2102 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2103 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
2104 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2105 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
2106 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
2107 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
,
2110 /* RFC 2960 5.1 Normal Establishment of an Association
2112 * D) IMPLEMENTATION NOTE: An implementation may choose
2113 * to send the Communication Up notification to the
2114 * SCTP user upon reception of a valid COOKIE
2117 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0,
2119 asoc
->c
.sinit_num_ostreams
,
2120 asoc
->c
.sinit_max_instreams
,
2125 /* Sockets API Draft Section 5.3.1.6
2126 * When a peer sends a Adaptation Layer Indication parameter,
2127 * SCTP delivers this notification to inform the application
2128 * that of the peers requested adaptation layer.
2130 if (asoc
->peer
.adaptation_ind
) {
2131 ai_ev
= sctp_ulpevent_make_adaptation_indication(asoc
,
2138 if (!asoc
->peer
.auth_capable
) {
2139 auth_ev
= sctp_ulpevent_make_authkey(asoc
, 0,
2147 repl
= sctp_make_cookie_ack(asoc
, chunk
);
2151 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
2154 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
2157 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
2158 SCTP_ULPEVENT(ai_ev
));
2160 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
2161 SCTP_ULPEVENT(auth_ev
));
2163 return SCTP_DISPOSITION_CONSUME
;
2167 sctp_ulpevent_free(auth_ev
);
2169 sctp_ulpevent_free(ai_ev
);
2171 sctp_ulpevent_free(ev
);
2172 return SCTP_DISPOSITION_NOMEM
;
2176 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
2177 * chunk was retransmitted and then delayed in the network.
2179 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
2181 * Verification Tag: None. Do cookie validation.
2184 * (endpoint, asoc, chunk)
2187 * (asoc, reply_msg, msg_up, timers, counters)
2189 * The return value is the disposition of the chunk.
2191 enum sctp_disposition
sctp_sf_do_5_2_4_dupcook(
2193 const struct sctp_endpoint
*ep
,
2194 const struct sctp_association
*asoc
,
2195 const union sctp_subtype type
,
2197 struct sctp_cmd_seq
*commands
)
2199 struct sctp_association
*new_asoc
;
2200 struct sctp_chunk
*chunk
= arg
;
2201 enum sctp_disposition retval
;
2202 struct sctp_chunk
*err_chk_p
;
2206 /* Make sure that the chunk has a valid length from the protocol
2207 * perspective. In this case check to make sure we have at least
2208 * enough for the chunk header. Cookie length verification is
2211 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
))) {
2212 if (!sctp_vtag_verify(chunk
, asoc
))
2214 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
, commands
);
2217 /* "Decode" the chunk. We have no optional parameters so we
2218 * are in good shape.
2220 chunk
->subh
.cookie_hdr
= (struct sctp_signed_cookie
*)chunk
->skb
->data
;
2221 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
2222 sizeof(struct sctp_chunkhdr
)))
2225 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
2226 * of a duplicate COOKIE ECHO match the Verification Tags of the
2227 * current association, consider the State Cookie valid even if
2228 * the lifespan is exceeded.
2230 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
2234 * If the re-build failed, what is the proper error path
2237 * [We should abort the association. --piggy]
2240 /* FIXME: Several errors are possible. A bad cookie should
2241 * be silently discarded, but think about logging it too.
2244 case -SCTP_IERROR_NOMEM
:
2247 case -SCTP_IERROR_STALE_COOKIE
:
2248 sctp_send_stale_cookie_err(net
, ep
, asoc
, chunk
, commands
,
2250 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2251 case -SCTP_IERROR_BAD_SIG
:
2253 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2257 /* Update socket peer label if first association. */
2258 if (security_sctp_assoc_request((struct sctp_endpoint
*)ep
,
2260 sctp_association_free(new_asoc
);
2261 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2264 /* Set temp so that it won't be added into hashtable */
2267 /* Compare the tie_tag in cookie with the verification tag of
2268 * current association.
2270 action
= sctp_tietags_compare(new_asoc
, asoc
);
2273 case 'A': /* Association restart. */
2274 retval
= sctp_sf_do_dupcook_a(net
, ep
, asoc
, chunk
, commands
,
2278 case 'B': /* Collision case B. */
2279 retval
= sctp_sf_do_dupcook_b(net
, ep
, asoc
, chunk
, commands
,
2283 case 'C': /* Collision case C. */
2284 retval
= sctp_sf_do_dupcook_c(net
, ep
, asoc
, chunk
, commands
,
2288 case 'D': /* Collision case D. */
2289 retval
= sctp_sf_do_dupcook_d(net
, ep
, asoc
, chunk
, commands
,
2293 default: /* Discard packet for all others. */
2294 retval
= sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2298 /* Delete the temporary new association. */
2299 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_ASOC
, SCTP_ASOC(new_asoc
));
2300 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
2302 /* Restore association pointer to provide SCTP command interpreter
2303 * with a valid context in case it needs to manipulate
2305 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_ASOC
,
2306 SCTP_ASOC((struct sctp_association
*)asoc
));
2311 return SCTP_DISPOSITION_NOMEM
;
2315 * Process an ABORT. (SHUTDOWN-PENDING state)
2317 * See sctp_sf_do_9_1_abort().
2319 enum sctp_disposition
sctp_sf_shutdown_pending_abort(
2321 const struct sctp_endpoint
*ep
,
2322 const struct sctp_association
*asoc
,
2323 const union sctp_subtype type
,
2325 struct sctp_cmd_seq
*commands
)
2327 struct sctp_chunk
*chunk
= arg
;
2329 if (!sctp_vtag_verify_either(chunk
, asoc
))
2330 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2332 /* Make sure that the ABORT chunk has a valid length.
2333 * Since this is an ABORT chunk, we have to discard it
2334 * because of the following text:
2335 * RFC 2960, Section 3.3.7
2336 * If an endpoint receives an ABORT with a format error or for an
2337 * association that doesn't exist, it MUST silently discard it.
2338 * Because the length is "invalid", we can't really discard just
2339 * as we do not know its true length. So, to be safe, discard the
2342 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_abort_chunk
)))
2343 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2345 /* ADD-IP: Special case for ABORT chunks
2346 * F4) One special consideration is that ABORT Chunks arriving
2347 * destined to the IP address being deleted MUST be
2348 * ignored (see Section 5.3.1 for further details).
2350 if (SCTP_ADDR_DEL
==
2351 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2352 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2354 if (!sctp_err_chunk_valid(chunk
))
2355 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2357 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2361 * Process an ABORT. (SHUTDOWN-SENT state)
2363 * See sctp_sf_do_9_1_abort().
2365 enum sctp_disposition
sctp_sf_shutdown_sent_abort(
2367 const struct sctp_endpoint
*ep
,
2368 const struct sctp_association
*asoc
,
2369 const union sctp_subtype type
,
2371 struct sctp_cmd_seq
*commands
)
2373 struct sctp_chunk
*chunk
= arg
;
2375 if (!sctp_vtag_verify_either(chunk
, asoc
))
2376 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2378 /* Make sure that the ABORT chunk has a valid length.
2379 * Since this is an ABORT chunk, we have to discard it
2380 * because of the following text:
2381 * RFC 2960, Section 3.3.7
2382 * If an endpoint receives an ABORT with a format error or for an
2383 * association that doesn't exist, it MUST silently discard it.
2384 * Because the length is "invalid", we can't really discard just
2385 * as we do not know its true length. So, to be safe, discard the
2388 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_abort_chunk
)))
2389 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2391 /* ADD-IP: Special case for ABORT chunks
2392 * F4) One special consideration is that ABORT Chunks arriving
2393 * destined to the IP address being deleted MUST be
2394 * ignored (see Section 5.3.1 for further details).
2396 if (SCTP_ADDR_DEL
==
2397 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2398 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2400 if (!sctp_err_chunk_valid(chunk
))
2401 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2403 /* Stop the T2-shutdown timer. */
2404 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2405 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2407 /* Stop the T5-shutdown guard timer. */
2408 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2409 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
2411 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2415 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2417 * See sctp_sf_do_9_1_abort().
2419 enum sctp_disposition
sctp_sf_shutdown_ack_sent_abort(
2421 const struct sctp_endpoint
*ep
,
2422 const struct sctp_association
*asoc
,
2423 const union sctp_subtype type
,
2425 struct sctp_cmd_seq
*commands
)
2427 /* The same T2 timer, so we should be able to use
2428 * common function with the SHUTDOWN-SENT state.
2430 return sctp_sf_shutdown_sent_abort(net
, ep
, asoc
, type
, arg
, commands
);
2434 * Handle an Error received in COOKIE_ECHOED state.
2436 * Only handle the error type of stale COOKIE Error, the other errors will
2440 * (endpoint, asoc, chunk)
2443 * (asoc, reply_msg, msg_up, timers, counters)
2445 * The return value is the disposition of the chunk.
2447 enum sctp_disposition
sctp_sf_cookie_echoed_err(
2449 const struct sctp_endpoint
*ep
,
2450 const struct sctp_association
*asoc
,
2451 const union sctp_subtype type
,
2453 struct sctp_cmd_seq
*commands
)
2455 struct sctp_chunk
*chunk
= arg
;
2456 struct sctp_errhdr
*err
;
2458 if (!sctp_vtag_verify(chunk
, asoc
))
2459 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2461 /* Make sure that the ERROR chunk has a valid length.
2462 * The parameter walking depends on this as well.
2464 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_operr_chunk
)))
2465 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2468 /* Process the error here */
2469 /* FUTURE FIXME: When PR-SCTP related and other optional
2470 * parms are emitted, this will have to change to handle multiple
2473 sctp_walk_errors(err
, chunk
->chunk_hdr
) {
2474 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
)
2475 return sctp_sf_do_5_2_6_stale(net
, ep
, asoc
, type
,
2479 /* It is possible to have malformed error causes, and that
2480 * will cause us to end the walk early. However, since
2481 * we are discarding the packet, there should be no adverse
2484 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2488 * Handle a Stale COOKIE Error
2490 * Section: 5.2.6 Handle Stale COOKIE Error
2491 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2492 * one of the following three alternatives.
2494 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2495 * Preservative parameter requesting an extension to the lifetime of
2496 * the State Cookie. When calculating the time extension, an
2497 * implementation SHOULD use the RTT information measured based on the
2498 * previous COOKIE ECHO / ERROR exchange, and should add no more
2499 * than 1 second beyond the measured RTT, due to long State Cookie
2500 * lifetimes making the endpoint more subject to a replay attack.
2502 * Verification Tag: Not explicit, but safe to ignore.
2505 * (endpoint, asoc, chunk)
2508 * (asoc, reply_msg, msg_up, timers, counters)
2510 * The return value is the disposition of the chunk.
2512 static enum sctp_disposition
sctp_sf_do_5_2_6_stale(
2514 const struct sctp_endpoint
*ep
,
2515 const struct sctp_association
*asoc
,
2516 const union sctp_subtype type
,
2518 struct sctp_cmd_seq
*commands
)
2520 int attempts
= asoc
->init_err_counter
+ 1;
2521 struct sctp_chunk
*chunk
= arg
, *reply
;
2522 struct sctp_cookie_preserve_param bht
;
2523 struct sctp_bind_addr
*bp
;
2524 struct sctp_errhdr
*err
;
2527 if (attempts
> asoc
->max_init_attempts
) {
2528 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
2529 SCTP_ERROR(ETIMEDOUT
));
2530 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2531 SCTP_PERR(SCTP_ERROR_STALE_COOKIE
));
2532 return SCTP_DISPOSITION_DELETE_TCB
;
2535 err
= (struct sctp_errhdr
*)(chunk
->skb
->data
);
2537 /* When calculating the time extension, an implementation
2538 * SHOULD use the RTT information measured based on the
2539 * previous COOKIE ECHO / ERROR exchange, and should add no
2540 * more than 1 second beyond the measured RTT, due to long
2541 * State Cookie lifetimes making the endpoint more subject to
2543 * Measure of Staleness's unit is usec. (1/1000000 sec)
2544 * Suggested Cookie Life-span Increment's unit is msec.
2546 * In general, if you use the suggested cookie life, the value
2547 * found in the field of measure of staleness should be doubled
2548 * to give ample time to retransmit the new cookie and thus
2549 * yield a higher probability of success on the reattempt.
2551 stale
= ntohl(*(__be32
*)((u8
*)err
+ sizeof(*err
)));
2552 stale
= (stale
* 2) / 1000;
2554 bht
.param_hdr
.type
= SCTP_PARAM_COOKIE_PRESERVATIVE
;
2555 bht
.param_hdr
.length
= htons(sizeof(bht
));
2556 bht
.lifespan_increment
= htonl(stale
);
2558 /* Build that new INIT chunk. */
2559 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
2560 reply
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, sizeof(bht
));
2564 sctp_addto_chunk(reply
, sizeof(bht
), &bht
);
2566 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2567 sctp_add_cmd_sf(commands
, SCTP_CMD_CLEAR_INIT_TAG
, SCTP_NULL());
2569 /* Stop pending T3-rtx and heartbeat timers */
2570 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
2571 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
2573 /* Delete non-primary peer ip addresses since we are transitioning
2574 * back to the COOKIE-WAIT state
2576 sctp_add_cmd_sf(commands
, SCTP_CMD_DEL_NON_PRIMARY
, SCTP_NULL());
2578 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2581 sctp_add_cmd_sf(commands
, SCTP_CMD_T1_RETRAN
,
2582 SCTP_TRANSPORT(asoc
->peer
.primary_path
));
2584 /* Cast away the const modifier, as we want to just
2585 * rerun it through as a sideffect.
2587 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_INC
, SCTP_NULL());
2589 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2590 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
2591 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2592 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
2593 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
2594 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2596 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2598 return SCTP_DISPOSITION_CONSUME
;
2601 return SCTP_DISPOSITION_NOMEM
;
2608 * After checking the Verification Tag, the receiving endpoint shall
2609 * remove the association from its record, and shall report the
2610 * termination to its upper layer.
2612 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2613 * B) Rules for packet carrying ABORT:
2615 * - The endpoint shall always fill in the Verification Tag field of the
2616 * outbound packet with the destination endpoint's tag value if it
2619 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2620 * MUST follow the procedure described in Section 8.4.
2622 * - The receiver MUST accept the packet if the Verification Tag
2623 * matches either its own tag, OR the tag of its peer. Otherwise, the
2624 * receiver MUST silently discard the packet and take no further
2628 * (endpoint, asoc, chunk)
2631 * (asoc, reply_msg, msg_up, timers, counters)
2633 * The return value is the disposition of the chunk.
2635 enum sctp_disposition
sctp_sf_do_9_1_abort(
2637 const struct sctp_endpoint
*ep
,
2638 const struct sctp_association
*asoc
,
2639 const union sctp_subtype type
,
2641 struct sctp_cmd_seq
*commands
)
2643 struct sctp_chunk
*chunk
= arg
;
2645 if (!sctp_vtag_verify_either(chunk
, asoc
))
2646 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2648 /* Make sure that the ABORT chunk has a valid length.
2649 * Since this is an ABORT chunk, we have to discard it
2650 * because of the following text:
2651 * RFC 2960, Section 3.3.7
2652 * If an endpoint receives an ABORT with a format error or for an
2653 * association that doesn't exist, it MUST silently discard it.
2654 * Because the length is "invalid", we can't really discard just
2655 * as we do not know its true length. So, to be safe, discard the
2658 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_abort_chunk
)))
2659 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2661 /* ADD-IP: Special case for ABORT chunks
2662 * F4) One special consideration is that ABORT Chunks arriving
2663 * destined to the IP address being deleted MUST be
2664 * ignored (see Section 5.3.1 for further details).
2666 if (SCTP_ADDR_DEL
==
2667 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2668 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2670 if (!sctp_err_chunk_valid(chunk
))
2671 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2673 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2676 static enum sctp_disposition
__sctp_sf_do_9_1_abort(
2678 const struct sctp_endpoint
*ep
,
2679 const struct sctp_association
*asoc
,
2680 const union sctp_subtype type
,
2682 struct sctp_cmd_seq
*commands
)
2684 __be16 error
= SCTP_ERROR_NO_ERROR
;
2685 struct sctp_chunk
*chunk
= arg
;
2688 /* See if we have an error cause code in the chunk. */
2689 len
= ntohs(chunk
->chunk_hdr
->length
);
2690 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2691 error
= ((struct sctp_errhdr
*)chunk
->skb
->data
)->cause
;
2693 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(ECONNRESET
));
2694 /* ASSOC_FAILED will DELETE_TCB. */
2695 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
, SCTP_PERR(error
));
2696 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
2697 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
2699 return SCTP_DISPOSITION_ABORT
;
2703 * Process an ABORT. (COOKIE-WAIT state)
2705 * See sctp_sf_do_9_1_abort() above.
2707 enum sctp_disposition
sctp_sf_cookie_wait_abort(
2709 const struct sctp_endpoint
*ep
,
2710 const struct sctp_association
*asoc
,
2711 const union sctp_subtype type
,
2713 struct sctp_cmd_seq
*commands
)
2715 __be16 error
= SCTP_ERROR_NO_ERROR
;
2716 struct sctp_chunk
*chunk
= arg
;
2719 if (!sctp_vtag_verify_either(chunk
, asoc
))
2720 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2722 /* Make sure that the ABORT chunk has a valid length.
2723 * Since this is an ABORT chunk, we have to discard it
2724 * because of the following text:
2725 * RFC 2960, Section 3.3.7
2726 * If an endpoint receives an ABORT with a format error or for an
2727 * association that doesn't exist, it MUST silently discard it.
2728 * Because the length is "invalid", we can't really discard just
2729 * as we do not know its true length. So, to be safe, discard the
2732 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_abort_chunk
)))
2733 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2735 /* See if we have an error cause code in the chunk. */
2736 len
= ntohs(chunk
->chunk_hdr
->length
);
2737 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2738 error
= ((struct sctp_errhdr
*)chunk
->skb
->data
)->cause
;
2740 return sctp_stop_t1_and_abort(net
, commands
, error
, ECONNREFUSED
, asoc
,
2745 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2747 enum sctp_disposition
sctp_sf_cookie_wait_icmp_abort(
2749 const struct sctp_endpoint
*ep
,
2750 const struct sctp_association
*asoc
,
2751 const union sctp_subtype type
,
2753 struct sctp_cmd_seq
*commands
)
2755 return sctp_stop_t1_and_abort(net
, commands
, SCTP_ERROR_NO_ERROR
,
2757 (struct sctp_transport
*)arg
);
2761 * Process an ABORT. (COOKIE-ECHOED state)
2763 enum sctp_disposition
sctp_sf_cookie_echoed_abort(
2765 const struct sctp_endpoint
*ep
,
2766 const struct sctp_association
*asoc
,
2767 const union sctp_subtype type
,
2769 struct sctp_cmd_seq
*commands
)
2771 /* There is a single T1 timer, so we should be able to use
2772 * common function with the COOKIE-WAIT state.
2774 return sctp_sf_cookie_wait_abort(net
, ep
, asoc
, type
, arg
, commands
);
2778 * Stop T1 timer and abort association with "INIT failed".
2780 * This is common code called by several sctp_sf_*_abort() functions above.
2782 static enum sctp_disposition
sctp_stop_t1_and_abort(
2784 struct sctp_cmd_seq
*commands
,
2785 __be16 error
, int sk_err
,
2786 const struct sctp_association
*asoc
,
2787 struct sctp_transport
*transport
)
2789 pr_debug("%s: ABORT received (INIT)\n", __func__
);
2791 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2792 SCTP_STATE(SCTP_STATE_CLOSED
));
2793 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
2794 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2795 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2796 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(sk_err
));
2797 /* CMD_INIT_FAILED will DELETE_TCB. */
2798 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2801 return SCTP_DISPOSITION_ABORT
;
2805 * sctp_sf_do_9_2_shut
2808 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2809 * - enter the SHUTDOWN-RECEIVED state,
2811 * - stop accepting new data from its SCTP user
2813 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2814 * that all its outstanding DATA chunks have been received by the
2817 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2818 * send a SHUTDOWN in response to a ULP request. And should discard
2819 * subsequent SHUTDOWN chunks.
2821 * If there are still outstanding DATA chunks left, the SHUTDOWN
2822 * receiver shall continue to follow normal data transmission
2823 * procedures defined in Section 6 until all outstanding DATA chunks
2824 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2825 * new data from its SCTP user.
2827 * Verification Tag: 8.5 Verification Tag [Normal verification]
2830 * (endpoint, asoc, chunk)
2833 * (asoc, reply_msg, msg_up, timers, counters)
2835 * The return value is the disposition of the chunk.
2837 enum sctp_disposition
sctp_sf_do_9_2_shutdown(
2839 const struct sctp_endpoint
*ep
,
2840 const struct sctp_association
*asoc
,
2841 const union sctp_subtype type
,
2843 struct sctp_cmd_seq
*commands
)
2845 enum sctp_disposition disposition
;
2846 struct sctp_chunk
*chunk
= arg
;
2847 struct sctp_shutdownhdr
*sdh
;
2848 struct sctp_ulpevent
*ev
;
2851 if (!sctp_vtag_verify(chunk
, asoc
))
2852 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2854 /* Make sure that the SHUTDOWN chunk has a valid length. */
2855 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_shutdown_chunk
)))
2856 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2859 /* Convert the elaborate header. */
2860 sdh
= (struct sctp_shutdownhdr
*)chunk
->skb
->data
;
2861 skb_pull(chunk
->skb
, sizeof(*sdh
));
2862 chunk
->subh
.shutdown_hdr
= sdh
;
2863 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2865 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2866 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__
, ctsn
,
2867 asoc
->ctsn_ack_point
);
2869 return SCTP_DISPOSITION_DISCARD
;
2872 /* If Cumulative TSN Ack beyond the max tsn currently
2873 * send, terminating the association and respond to the
2874 * sender with an ABORT.
2876 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2877 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
2879 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2880 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2881 * inform the application that it should cease sending data.
2883 ev
= sctp_ulpevent_make_shutdown_event(asoc
, 0, GFP_ATOMIC
);
2885 disposition
= SCTP_DISPOSITION_NOMEM
;
2888 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
2890 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2891 * - enter the SHUTDOWN-RECEIVED state,
2892 * - stop accepting new data from its SCTP user
2894 * [This is implicit in the new state.]
2896 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2897 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED
));
2898 disposition
= SCTP_DISPOSITION_CONSUME
;
2900 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
2901 disposition
= sctp_sf_do_9_2_shutdown_ack(net
, ep
, asoc
, type
,
2905 if (SCTP_DISPOSITION_NOMEM
== disposition
)
2908 /* - verify, by checking the Cumulative TSN Ack field of the
2909 * chunk, that all its outstanding DATA chunks have been
2910 * received by the SHUTDOWN sender.
2912 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2913 SCTP_BE32(chunk
->subh
.shutdown_hdr
->cum_tsn_ack
));
2920 * sctp_sf_do_9_2_shut_ctsn
2922 * Once an endpoint has reached the SHUTDOWN-RECEIVED state,
2923 * it MUST NOT send a SHUTDOWN in response to a ULP request.
2924 * The Cumulative TSN Ack of the received SHUTDOWN chunk
2925 * MUST be processed.
2927 enum sctp_disposition
sctp_sf_do_9_2_shut_ctsn(
2929 const struct sctp_endpoint
*ep
,
2930 const struct sctp_association
*asoc
,
2931 const union sctp_subtype type
,
2933 struct sctp_cmd_seq
*commands
)
2935 struct sctp_chunk
*chunk
= arg
;
2936 struct sctp_shutdownhdr
*sdh
;
2939 if (!sctp_vtag_verify(chunk
, asoc
))
2940 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2942 /* Make sure that the SHUTDOWN chunk has a valid length. */
2943 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_shutdown_chunk
)))
2944 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2947 sdh
= (struct sctp_shutdownhdr
*)chunk
->skb
->data
;
2948 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2950 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2951 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__
, ctsn
,
2952 asoc
->ctsn_ack_point
);
2954 return SCTP_DISPOSITION_DISCARD
;
2957 /* If Cumulative TSN Ack beyond the max tsn currently
2958 * send, terminating the association and respond to the
2959 * sender with an ABORT.
2961 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2962 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
2964 /* verify, by checking the Cumulative TSN Ack field of the
2965 * chunk, that all its outstanding DATA chunks have been
2966 * received by the SHUTDOWN sender.
2968 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2969 SCTP_BE32(sdh
->cum_tsn_ack
));
2971 return SCTP_DISPOSITION_CONSUME
;
2975 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2976 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2977 * transport addresses (either in the IP addresses or in the INIT chunk)
2978 * that belong to this association, it should discard the INIT chunk and
2979 * retransmit the SHUTDOWN ACK chunk.
2981 static enum sctp_disposition
2982 __sctp_sf_do_9_2_reshutack(struct net
*net
, const struct sctp_endpoint
*ep
,
2983 const struct sctp_association
*asoc
,
2984 const union sctp_subtype type
, void *arg
,
2985 struct sctp_cmd_seq
*commands
)
2987 struct sctp_chunk
*chunk
= arg
;
2988 struct sctp_chunk
*reply
;
2990 /* Make sure that the chunk has a valid length */
2991 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
2992 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2995 /* Since we are not going to really process this INIT, there
2996 * is no point in verifying chunk boundaries. Just generate
2999 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
3003 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
3004 * the T2-SHUTDOWN timer.
3006 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
3008 /* and restart the T2-shutdown timer. */
3009 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3010 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3012 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
3014 return SCTP_DISPOSITION_CONSUME
;
3016 return SCTP_DISPOSITION_NOMEM
;
3019 enum sctp_disposition
3020 sctp_sf_do_9_2_reshutack(struct net
*net
, const struct sctp_endpoint
*ep
,
3021 const struct sctp_association
*asoc
,
3022 const union sctp_subtype type
, void *arg
,
3023 struct sctp_cmd_seq
*commands
)
3025 struct sctp_chunk
*chunk
= arg
;
3027 if (!chunk
->singleton
)
3028 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3030 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_init_chunk
)))
3031 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3033 if (chunk
->sctp_hdr
->vtag
!= 0)
3034 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
3036 return __sctp_sf_do_9_2_reshutack(net
, ep
, asoc
, type
, arg
, commands
);
3040 * sctp_sf_do_ecn_cwr
3042 * Section: Appendix A: Explicit Congestion Notification
3046 * RFC 2481 details a specific bit for a sender to send in the header of
3047 * its next outbound TCP segment to indicate to its peer that it has
3048 * reduced its congestion window. This is termed the CWR bit. For
3049 * SCTP the same indication is made by including the CWR chunk.
3050 * This chunk contains one data element, i.e. the TSN number that
3051 * was sent in the ECNE chunk. This element represents the lowest
3052 * TSN number in the datagram that was originally marked with the
3055 * Verification Tag: 8.5 Verification Tag [Normal verification]
3057 * (endpoint, asoc, chunk)
3060 * (asoc, reply_msg, msg_up, timers, counters)
3062 * The return value is the disposition of the chunk.
3064 enum sctp_disposition
sctp_sf_do_ecn_cwr(struct net
*net
,
3065 const struct sctp_endpoint
*ep
,
3066 const struct sctp_association
*asoc
,
3067 const union sctp_subtype type
,
3069 struct sctp_cmd_seq
*commands
)
3071 struct sctp_chunk
*chunk
= arg
;
3072 struct sctp_cwrhdr
*cwr
;
3075 if (!sctp_vtag_verify(chunk
, asoc
))
3076 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3078 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_ecne_chunk
)))
3079 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3082 cwr
= (struct sctp_cwrhdr
*)chunk
->skb
->data
;
3083 skb_pull(chunk
->skb
, sizeof(*cwr
));
3085 lowest_tsn
= ntohl(cwr
->lowest_tsn
);
3087 /* Does this CWR ack the last sent congestion notification? */
3088 if (TSN_lte(asoc
->last_ecne_tsn
, lowest_tsn
)) {
3089 /* Stop sending ECNE. */
3090 sctp_add_cmd_sf(commands
,
3092 SCTP_U32(lowest_tsn
));
3094 return SCTP_DISPOSITION_CONSUME
;
3100 * Section: Appendix A: Explicit Congestion Notification
3104 * RFC 2481 details a specific bit for a receiver to send back in its
3105 * TCP acknowledgements to notify the sender of the Congestion
3106 * Experienced (CE) bit having arrived from the network. For SCTP this
3107 * same indication is made by including the ECNE chunk. This chunk
3108 * contains one data element, i.e. the lowest TSN associated with the IP
3109 * datagram marked with the CE bit.....
3111 * Verification Tag: 8.5 Verification Tag [Normal verification]
3113 * (endpoint, asoc, chunk)
3116 * (asoc, reply_msg, msg_up, timers, counters)
3118 * The return value is the disposition of the chunk.
3120 enum sctp_disposition
sctp_sf_do_ecne(struct net
*net
,
3121 const struct sctp_endpoint
*ep
,
3122 const struct sctp_association
*asoc
,
3123 const union sctp_subtype type
,
3124 void *arg
, struct sctp_cmd_seq
*commands
)
3126 struct sctp_chunk
*chunk
= arg
;
3127 struct sctp_ecnehdr
*ecne
;
3129 if (!sctp_vtag_verify(chunk
, asoc
))
3130 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3132 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_ecne_chunk
)))
3133 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3136 ecne
= (struct sctp_ecnehdr
*)chunk
->skb
->data
;
3137 skb_pull(chunk
->skb
, sizeof(*ecne
));
3139 /* If this is a newer ECNE than the last CWR packet we sent out */
3140 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_ECNE
,
3141 SCTP_U32(ntohl(ecne
->lowest_tsn
)));
3143 return SCTP_DISPOSITION_CONSUME
;
3147 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
3149 * The SCTP endpoint MUST always acknowledge the reception of each valid
3152 * The guidelines on delayed acknowledgement algorithm specified in
3153 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
3154 * acknowledgement SHOULD be generated for at least every second packet
3155 * (not every second DATA chunk) received, and SHOULD be generated within
3156 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
3157 * situations it may be beneficial for an SCTP transmitter to be more
3158 * conservative than the algorithms detailed in this document allow.
3159 * However, an SCTP transmitter MUST NOT be more aggressive than the
3160 * following algorithms allow.
3162 * A SCTP receiver MUST NOT generate more than one SACK for every
3163 * incoming packet, other than to update the offered window as the
3164 * receiving application consumes new data.
3166 * Verification Tag: 8.5 Verification Tag [Normal verification]
3169 * (endpoint, asoc, chunk)
3172 * (asoc, reply_msg, msg_up, timers, counters)
3174 * The return value is the disposition of the chunk.
3176 enum sctp_disposition
sctp_sf_eat_data_6_2(struct net
*net
,
3177 const struct sctp_endpoint
*ep
,
3178 const struct sctp_association
*asoc
,
3179 const union sctp_subtype type
,
3181 struct sctp_cmd_seq
*commands
)
3183 union sctp_arg force
= SCTP_NOFORCE();
3184 struct sctp_chunk
*chunk
= arg
;
3187 if (!sctp_vtag_verify(chunk
, asoc
)) {
3188 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3190 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3193 if (!sctp_chunk_length_valid(chunk
, sctp_datachk_len(&asoc
->stream
)))
3194 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3197 error
= sctp_eat_data(asoc
, chunk
, commands
);
3199 case SCTP_IERROR_NO_ERROR
:
3201 case SCTP_IERROR_HIGH_TSN
:
3202 case SCTP_IERROR_BAD_STREAM
:
3203 SCTP_INC_STATS(net
, SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
3204 goto discard_noforce
;
3205 case SCTP_IERROR_DUP_TSN
:
3206 case SCTP_IERROR_IGNORE_TSN
:
3207 SCTP_INC_STATS(net
, SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
3209 case SCTP_IERROR_NO_DATA
:
3210 return SCTP_DISPOSITION_ABORT
;
3211 case SCTP_IERROR_PROTO_VIOLATION
:
3212 return sctp_sf_abort_violation(net
, ep
, asoc
, chunk
, commands
,
3213 (u8
*)chunk
->subh
.data_hdr
,
3214 sctp_datahdr_len(&asoc
->stream
));
3219 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_SACK_IMM
)
3220 force
= SCTP_FORCE();
3222 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
]) {
3223 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3224 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
3227 /* If this is the last chunk in a packet, we need to count it
3228 * toward sack generation. Note that we need to SACK every
3229 * OTHER packet containing data chunks, EVEN IF WE DISCARD
3230 * THEM. We elect to NOT generate SACK's if the chunk fails
3231 * the verification tag test.
3233 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
3235 * The SCTP endpoint MUST always acknowledge the reception of
3236 * each valid DATA chunk.
3238 * The guidelines on delayed acknowledgement algorithm
3239 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
3240 * Specifically, an acknowledgement SHOULD be generated for at
3241 * least every second packet (not every second DATA chunk)
3242 * received, and SHOULD be generated within 200 ms of the
3243 * arrival of any unacknowledged DATA chunk. In some
3244 * situations it may be beneficial for an SCTP transmitter to
3245 * be more conservative than the algorithms detailed in this
3246 * document allow. However, an SCTP transmitter MUST NOT be
3247 * more aggressive than the following algorithms allow.
3249 if (chunk
->end_of_packet
)
3250 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, force
);
3252 return SCTP_DISPOSITION_CONSUME
;
3255 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
3257 * When a packet arrives with duplicate DATA chunk(s) and with
3258 * no new DATA chunk(s), the endpoint MUST immediately send a
3259 * SACK with no delay. If a packet arrives with duplicate
3260 * DATA chunk(s) bundled with new DATA chunks, the endpoint
3261 * MAY immediately send a SACK. Normally receipt of duplicate
3262 * DATA chunks will occur when the original SACK chunk was lost
3263 * and the peer's RTO has expired. The duplicate TSN number(s)
3264 * SHOULD be reported in the SACK as duplicate.
3266 /* In our case, we split the MAY SACK advice up whether or not
3267 * the last chunk is a duplicate.'
3269 if (chunk
->end_of_packet
)
3270 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3271 return SCTP_DISPOSITION_DISCARD
;
3274 if (chunk
->end_of_packet
)
3275 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, force
);
3277 return SCTP_DISPOSITION_DISCARD
;
3281 * sctp_sf_eat_data_fast_4_4
3284 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
3285 * DATA chunks without delay.
3287 * Verification Tag: 8.5 Verification Tag [Normal verification]
3289 * (endpoint, asoc, chunk)
3292 * (asoc, reply_msg, msg_up, timers, counters)
3294 * The return value is the disposition of the chunk.
3296 enum sctp_disposition
sctp_sf_eat_data_fast_4_4(
3298 const struct sctp_endpoint
*ep
,
3299 const struct sctp_association
*asoc
,
3300 const union sctp_subtype type
,
3302 struct sctp_cmd_seq
*commands
)
3304 struct sctp_chunk
*chunk
= arg
;
3307 if (!sctp_vtag_verify(chunk
, asoc
)) {
3308 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3310 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3313 if (!sctp_chunk_length_valid(chunk
, sctp_datachk_len(&asoc
->stream
)))
3314 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3317 error
= sctp_eat_data(asoc
, chunk
, commands
);
3319 case SCTP_IERROR_NO_ERROR
:
3320 case SCTP_IERROR_HIGH_TSN
:
3321 case SCTP_IERROR_DUP_TSN
:
3322 case SCTP_IERROR_IGNORE_TSN
:
3323 case SCTP_IERROR_BAD_STREAM
:
3325 case SCTP_IERROR_NO_DATA
:
3326 return SCTP_DISPOSITION_ABORT
;
3327 case SCTP_IERROR_PROTO_VIOLATION
:
3328 return sctp_sf_abort_violation(net
, ep
, asoc
, chunk
, commands
,
3329 (u8
*)chunk
->subh
.data_hdr
,
3330 sctp_datahdr_len(&asoc
->stream
));
3335 /* Go a head and force a SACK, since we are shutting down. */
3337 /* Implementor's Guide.
3339 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3340 * respond to each received packet containing one or more DATA chunk(s)
3341 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3343 if (chunk
->end_of_packet
) {
3344 /* We must delay the chunk creation since the cumulative
3345 * TSN has not been updated yet.
3347 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3348 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3349 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3350 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3353 return SCTP_DISPOSITION_CONSUME
;
3357 * Section: 6.2 Processing a Received SACK
3358 * D) Any time a SACK arrives, the endpoint performs the following:
3360 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
3361 * then drop the SACK. Since Cumulative TSN Ack is monotonically
3362 * increasing, a SACK whose Cumulative TSN Ack is less than the
3363 * Cumulative TSN Ack Point indicates an out-of-order SACK.
3365 * ii) Set rwnd equal to the newly received a_rwnd minus the number
3366 * of bytes still outstanding after processing the Cumulative TSN Ack
3367 * and the Gap Ack Blocks.
3369 * iii) If the SACK is missing a TSN that was previously
3370 * acknowledged via a Gap Ack Block (e.g., the data receiver
3371 * reneged on the data), then mark the corresponding DATA chunk
3372 * as available for retransmit: Mark it as missing for fast
3373 * retransmit as described in Section 7.2.4 and if no retransmit
3374 * timer is running for the destination address to which the DATA
3375 * chunk was originally transmitted, then T3-rtx is started for
3376 * that destination address.
3378 * Verification Tag: 8.5 Verification Tag [Normal verification]
3381 * (endpoint, asoc, chunk)
3384 * (asoc, reply_msg, msg_up, timers, counters)
3386 * The return value is the disposition of the chunk.
3388 enum sctp_disposition
sctp_sf_eat_sack_6_2(struct net
*net
,
3389 const struct sctp_endpoint
*ep
,
3390 const struct sctp_association
*asoc
,
3391 const union sctp_subtype type
,
3393 struct sctp_cmd_seq
*commands
)
3395 struct sctp_chunk
*chunk
= arg
;
3396 struct sctp_sackhdr
*sackh
;
3399 if (!sctp_vtag_verify(chunk
, asoc
))
3400 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3402 /* Make sure that the SACK chunk has a valid length. */
3403 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_sack_chunk
)))
3404 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3407 /* Pull the SACK chunk from the data buffer */
3408 sackh
= sctp_sm_pull_sack(chunk
);
3409 /* Was this a bogus SACK? */
3411 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3412 chunk
->subh
.sack_hdr
= sackh
;
3413 ctsn
= ntohl(sackh
->cum_tsn_ack
);
3415 /* If Cumulative TSN Ack beyond the max tsn currently
3416 * send, terminating the association and respond to the
3417 * sender with an ABORT.
3419 if (TSN_lte(asoc
->next_tsn
, ctsn
))
3420 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
3422 trace_sctp_probe(ep
, asoc
, chunk
);
3424 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
3425 * Ack Point, then drop the SACK. Since Cumulative TSN
3426 * Ack is monotonically increasing, a SACK whose
3427 * Cumulative TSN Ack is less than the Cumulative TSN Ack
3428 * Point indicates an out-of-order SACK.
3430 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
3431 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__
, ctsn
,
3432 asoc
->ctsn_ack_point
);
3434 return SCTP_DISPOSITION_DISCARD
;
3437 /* Return this SACK for further processing. */
3438 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_SACK
, SCTP_CHUNK(chunk
));
3440 /* Note: We do the rest of the work on the PROCESS_SACK
3443 return SCTP_DISPOSITION_CONSUME
;
3447 * Generate an ABORT in response to a packet.
3449 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
3451 * 8) The receiver should respond to the sender of the OOTB packet with
3452 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3453 * MUST fill in the Verification Tag field of the outbound packet
3454 * with the value found in the Verification Tag field of the OOTB
3455 * packet and set the T-bit in the Chunk Flags to indicate that the
3456 * Verification Tag is reflected. After sending this ABORT, the
3457 * receiver of the OOTB packet shall discard the OOTB packet and take
3458 * no further action.
3462 * The return value is the disposition of the chunk.
3464 static enum sctp_disposition
sctp_sf_tabort_8_4_8(
3466 const struct sctp_endpoint
*ep
,
3467 const struct sctp_association
*asoc
,
3468 const union sctp_subtype type
,
3470 struct sctp_cmd_seq
*commands
)
3472 struct sctp_packet
*packet
= NULL
;
3473 struct sctp_chunk
*chunk
= arg
;
3474 struct sctp_chunk
*abort
;
3476 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
3478 return SCTP_DISPOSITION_NOMEM
;
3480 /* Make an ABORT. The T bit will be set if the asoc
3483 abort
= sctp_make_abort(asoc
, chunk
, 0);
3485 sctp_ootb_pkt_free(packet
);
3486 return SCTP_DISPOSITION_NOMEM
;
3489 /* Reflect vtag if T-Bit is set */
3490 if (sctp_test_T_bit(abort
))
3491 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3493 /* Set the skb to the belonging sock for accounting. */
3494 abort
->skb
->sk
= ep
->base
.sk
;
3496 sctp_packet_append_chunk(packet
, abort
);
3498 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
, SCTP_PACKET(packet
));
3500 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
3502 sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3503 return SCTP_DISPOSITION_CONSUME
;
3506 /* Handling of SCTP Packets Containing an INIT Chunk Matching an
3507 * Existing Associations when the UDP encap port is incorrect.
3509 * From Section 4 at draft-tuexen-tsvwg-sctp-udp-encaps-cons-03.
3511 static enum sctp_disposition
sctp_sf_new_encap_port(
3513 const struct sctp_endpoint
*ep
,
3514 const struct sctp_association
*asoc
,
3515 const union sctp_subtype type
,
3517 struct sctp_cmd_seq
*commands
)
3519 struct sctp_packet
*packet
= NULL
;
3520 struct sctp_chunk
*chunk
= arg
;
3521 struct sctp_chunk
*abort
;
3523 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
3525 return SCTP_DISPOSITION_NOMEM
;
3527 abort
= sctp_make_new_encap_port(asoc
, chunk
);
3529 sctp_ootb_pkt_free(packet
);
3530 return SCTP_DISPOSITION_NOMEM
;
3533 abort
->skb
->sk
= ep
->base
.sk
;
3535 sctp_packet_append_chunk(packet
, abort
);
3537 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3538 SCTP_PACKET(packet
));
3540 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
3542 sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3543 return SCTP_DISPOSITION_CONSUME
;
3547 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
3548 * event as ULP notification for each cause included in the chunk.
3550 * API 5.3.1.3 - SCTP_REMOTE_ERROR
3552 * The return value is the disposition of the chunk.
3554 enum sctp_disposition
sctp_sf_operr_notify(struct net
*net
,
3555 const struct sctp_endpoint
*ep
,
3556 const struct sctp_association
*asoc
,
3557 const union sctp_subtype type
,
3559 struct sctp_cmd_seq
*commands
)
3561 struct sctp_chunk
*chunk
= arg
;
3562 struct sctp_errhdr
*err
;
3564 if (!sctp_vtag_verify(chunk
, asoc
))
3565 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3567 /* Make sure that the ERROR chunk has a valid length. */
3568 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_operr_chunk
)))
3569 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3571 sctp_walk_errors(err
, chunk
->chunk_hdr
);
3572 if ((void *)err
!= (void *)chunk
->chunk_end
)
3573 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3574 (void *)err
, commands
);
3576 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_OPERR
,
3579 return SCTP_DISPOSITION_CONSUME
;
3583 * Process an inbound SHUTDOWN ACK.
3586 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3587 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3588 * peer, and remove all record of the association.
3590 * The return value is the disposition.
3592 enum sctp_disposition
sctp_sf_do_9_2_final(struct net
*net
,
3593 const struct sctp_endpoint
*ep
,
3594 const struct sctp_association
*asoc
,
3595 const union sctp_subtype type
,
3597 struct sctp_cmd_seq
*commands
)
3599 struct sctp_chunk
*chunk
= arg
;
3600 struct sctp_chunk
*reply
;
3601 struct sctp_ulpevent
*ev
;
3603 if (!sctp_vtag_verify(chunk
, asoc
))
3604 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3606 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3607 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
3608 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3610 /* 10.2 H) SHUTDOWN COMPLETE notification
3612 * When SCTP completes the shutdown procedures (section 9.2) this
3613 * notification is passed to the upper layer.
3615 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
3616 0, 0, 0, NULL
, GFP_ATOMIC
);
3620 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3621 reply
= sctp_make_shutdown_complete(asoc
, chunk
);
3625 /* Do all the commands now (after allocation), so that we
3626 * have consistent state if memory allocation fails
3628 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
3630 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3631 * stop the T2-shutdown timer,
3633 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3634 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3636 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3637 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
3639 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
3640 SCTP_STATE(SCTP_STATE_CLOSED
));
3641 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
3642 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3643 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
3645 /* ...and remove all record of the association. */
3646 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
3647 return SCTP_DISPOSITION_DELETE_TCB
;
3650 sctp_ulpevent_free(ev
);
3652 return SCTP_DISPOSITION_NOMEM
;
3656 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3658 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3659 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3660 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3661 * packet must fill in the Verification Tag field of the outbound
3662 * packet with the Verification Tag received in the SHUTDOWN ACK and
3663 * set the T-bit in the Chunk Flags to indicate that the Verification
3666 * 8) The receiver should respond to the sender of the OOTB packet with
3667 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3668 * MUST fill in the Verification Tag field of the outbound packet
3669 * with the value found in the Verification Tag field of the OOTB
3670 * packet and set the T-bit in the Chunk Flags to indicate that the
3671 * Verification Tag is reflected. After sending this ABORT, the
3672 * receiver of the OOTB packet shall discard the OOTB packet and take
3673 * no further action.
3675 enum sctp_disposition
sctp_sf_ootb(struct net
*net
,
3676 const struct sctp_endpoint
*ep
,
3677 const struct sctp_association
*asoc
,
3678 const union sctp_subtype type
,
3679 void *arg
, struct sctp_cmd_seq
*commands
)
3681 struct sctp_chunk
*chunk
= arg
;
3682 struct sk_buff
*skb
= chunk
->skb
;
3683 struct sctp_chunkhdr
*ch
;
3684 struct sctp_errhdr
*err
;
3685 int ootb_cookie_ack
= 0;
3686 int ootb_shut_ack
= 0;
3689 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
3691 if (asoc
&& !sctp_vtag_verify(chunk
, asoc
))
3694 ch
= (struct sctp_chunkhdr
*)chunk
->chunk_hdr
;
3696 /* Report violation if the chunk is less then minimal */
3697 if (ntohs(ch
->length
) < sizeof(*ch
))
3698 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3701 /* Report violation if chunk len overflows */
3702 ch_end
= ((__u8
*)ch
) + SCTP_PAD4(ntohs(ch
->length
));
3703 if (ch_end
> skb_tail_pointer(skb
))
3704 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3707 /* Now that we know we at least have a chunk header,
3708 * do things that are type appropriate.
3710 if (SCTP_CID_SHUTDOWN_ACK
== ch
->type
)
3713 /* RFC 2960, Section 3.3.7
3714 * Moreover, under any circumstances, an endpoint that
3715 * receives an ABORT MUST NOT respond to that ABORT by
3716 * sending an ABORT of its own.
3718 if (SCTP_CID_ABORT
== ch
->type
)
3719 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3721 /* RFC 8.4, 7) If the packet contains a "Stale cookie" ERROR
3722 * or a COOKIE ACK the SCTP Packet should be silently
3726 if (SCTP_CID_COOKIE_ACK
== ch
->type
)
3727 ootb_cookie_ack
= 1;
3729 if (SCTP_CID_ERROR
== ch
->type
) {
3730 sctp_walk_errors(err
, ch
) {
3731 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
) {
3732 ootb_cookie_ack
= 1;
3738 ch
= (struct sctp_chunkhdr
*)ch_end
;
3739 } while (ch_end
< skb_tail_pointer(skb
));
3742 return sctp_sf_shut_8_4_5(net
, ep
, asoc
, type
, arg
, commands
);
3743 else if (ootb_cookie_ack
)
3744 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3746 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
3750 * Handle an "Out of the blue" SHUTDOWN ACK.
3752 * Section: 8.4 5, sctpimpguide 2.41.
3754 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3755 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3756 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3757 * packet must fill in the Verification Tag field of the outbound
3758 * packet with the Verification Tag received in the SHUTDOWN ACK and
3759 * set the T-bit in the Chunk Flags to indicate that the Verification
3763 * (endpoint, asoc, type, arg, commands)
3766 * (enum sctp_disposition)
3768 * The return value is the disposition of the chunk.
3770 static enum sctp_disposition
sctp_sf_shut_8_4_5(
3772 const struct sctp_endpoint
*ep
,
3773 const struct sctp_association
*asoc
,
3774 const union sctp_subtype type
,
3776 struct sctp_cmd_seq
*commands
)
3778 struct sctp_packet
*packet
= NULL
;
3779 struct sctp_chunk
*chunk
= arg
;
3780 struct sctp_chunk
*shut
;
3782 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
3784 return SCTP_DISPOSITION_NOMEM
;
3786 /* Make an SHUTDOWN_COMPLETE.
3787 * The T bit will be set if the asoc is NULL.
3789 shut
= sctp_make_shutdown_complete(asoc
, chunk
);
3791 sctp_ootb_pkt_free(packet
);
3792 return SCTP_DISPOSITION_NOMEM
;
3795 /* Reflect vtag if T-Bit is set */
3796 if (sctp_test_T_bit(shut
))
3797 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3799 /* Set the skb to the belonging sock for accounting. */
3800 shut
->skb
->sk
= ep
->base
.sk
;
3802 sctp_packet_append_chunk(packet
, shut
);
3804 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3805 SCTP_PACKET(packet
));
3807 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
3809 /* We need to discard the rest of the packet to prevent
3810 * potential boomming attacks from additional bundled chunks.
3811 * This is documented in SCTP Threats ID.
3813 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3817 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3819 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3820 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3821 * procedures in section 8.4 SHOULD be followed, in other words it
3822 * should be treated as an Out Of The Blue packet.
3823 * [This means that we do NOT check the Verification Tag on these
3827 enum sctp_disposition
sctp_sf_do_8_5_1_E_sa(struct net
*net
,
3828 const struct sctp_endpoint
*ep
,
3829 const struct sctp_association
*asoc
,
3830 const union sctp_subtype type
,
3832 struct sctp_cmd_seq
*commands
)
3834 struct sctp_chunk
*chunk
= arg
;
3836 if (!sctp_vtag_verify(chunk
, asoc
))
3839 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3840 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
3841 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3844 /* Although we do have an association in this case, it corresponds
3845 * to a restarted association. So the packet is treated as an OOTB
3846 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3847 * called with a NULL association.
3849 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
3851 return sctp_sf_shut_8_4_5(net
, ep
, NULL
, type
, arg
, commands
);
3854 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3855 enum sctp_disposition
sctp_sf_do_asconf(struct net
*net
,
3856 const struct sctp_endpoint
*ep
,
3857 const struct sctp_association
*asoc
,
3858 const union sctp_subtype type
,
3860 struct sctp_cmd_seq
*commands
)
3862 struct sctp_paramhdr
*err_param
= NULL
;
3863 struct sctp_chunk
*asconf_ack
= NULL
;
3864 struct sctp_chunk
*chunk
= arg
;
3865 struct sctp_addiphdr
*hdr
;
3868 if (!sctp_vtag_verify(chunk
, asoc
)) {
3869 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3871 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3874 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3875 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_addip_chunk
)))
3876 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3879 /* ADD-IP: Section 4.1.1
3880 * This chunk MUST be sent in an authenticated way by using
3881 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3882 * is received unauthenticated it MUST be silently discarded as
3883 * described in [I-D.ietf-tsvwg-sctp-auth].
3885 if (!asoc
->peer
.asconf_capable
||
3886 (!net
->sctp
.addip_noauth
&& !chunk
->auth
))
3887 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3889 hdr
= (struct sctp_addiphdr
*)chunk
->skb
->data
;
3890 serial
= ntohl(hdr
->serial
);
3892 /* Verify the ASCONF chunk before processing it. */
3893 if (!sctp_verify_asconf(asoc
, chunk
, true, &err_param
))
3894 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3895 (void *)err_param
, commands
);
3897 /* ADDIP 5.2 E1) Compare the value of the serial number to the value
3898 * the endpoint stored in a new association variable
3899 * 'Peer-Serial-Number'.
3901 if (serial
== asoc
->peer
.addip_serial
+ 1) {
3902 /* If this is the first instance of ASCONF in the packet,
3903 * we can clean our old ASCONF-ACKs.
3905 if (!chunk
->has_asconf
)
3906 sctp_assoc_clean_asconf_ack_cache(asoc
);
3908 /* ADDIP 5.2 E4) When the Sequence Number matches the next one
3909 * expected, process the ASCONF as described below and after
3910 * processing the ASCONF Chunk, append an ASCONF-ACK Chunk to
3911 * the response packet and cache a copy of it (in the event it
3912 * later needs to be retransmitted).
3914 * Essentially, do V1-V5.
3916 asconf_ack
= sctp_process_asconf((struct sctp_association
*)
3919 return SCTP_DISPOSITION_NOMEM
;
3920 } else if (serial
< asoc
->peer
.addip_serial
+ 1) {
3922 * If the value found in the Sequence Number is less than the
3923 * ('Peer- Sequence-Number' + 1), simply skip to the next
3924 * ASCONF, and include in the outbound response packet
3925 * any previously cached ASCONF-ACK response that was
3926 * sent and saved that matches the Sequence Number of the
3927 * ASCONF. Note: It is possible that no cached ASCONF-ACK
3928 * Chunk exists. This will occur when an older ASCONF
3929 * arrives out of order. In such a case, the receiver
3930 * should skip the ASCONF Chunk and not include ASCONF-ACK
3931 * Chunk for that chunk.
3933 asconf_ack
= sctp_assoc_lookup_asconf_ack(asoc
, hdr
->serial
);
3935 return SCTP_DISPOSITION_DISCARD
;
3937 /* Reset the transport so that we select the correct one
3938 * this time around. This is to make sure that we don't
3939 * accidentally use a stale transport that's been removed.
3941 asconf_ack
->transport
= NULL
;
3943 /* ADDIP 5.2 E5) Otherwise, the ASCONF Chunk is discarded since
3944 * it must be either a stale packet or from an attacker.
3946 return SCTP_DISPOSITION_DISCARD
;
3949 /* ADDIP 5.2 E6) The destination address of the SCTP packet
3950 * containing the ASCONF-ACK Chunks MUST be the source address of
3951 * the SCTP packet that held the ASCONF Chunks.
3953 * To do this properly, we'll set the destination address of the chunk
3954 * and at the transmit time, will try look up the transport to use.
3955 * Since ASCONFs may be bundled, the correct transport may not be
3956 * created until we process the entire packet, thus this workaround.
3958 asconf_ack
->dest
= chunk
->source
;
3959 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(asconf_ack
));
3960 if (asoc
->new_transport
) {
3961 sctp_sf_heartbeat(ep
, asoc
, type
, asoc
->new_transport
, commands
);
3962 ((struct sctp_association
*)asoc
)->new_transport
= NULL
;
3965 return SCTP_DISPOSITION_CONSUME
;
3968 static enum sctp_disposition
sctp_send_next_asconf(
3970 const struct sctp_endpoint
*ep
,
3971 struct sctp_association
*asoc
,
3972 const union sctp_subtype type
,
3973 struct sctp_cmd_seq
*commands
)
3975 struct sctp_chunk
*asconf
;
3976 struct list_head
*entry
;
3978 if (list_empty(&asoc
->addip_chunk_list
))
3979 return SCTP_DISPOSITION_CONSUME
;
3981 entry
= asoc
->addip_chunk_list
.next
;
3982 asconf
= list_entry(entry
, struct sctp_chunk
, list
);
3984 list_del_init(entry
);
3985 sctp_chunk_hold(asconf
);
3986 asoc
->addip_last_asconf
= asconf
;
3988 return sctp_sf_do_prm_asconf(net
, ep
, asoc
, type
, asconf
, commands
);
3992 * ADDIP Section 4.3 General rules for address manipulation
3993 * When building TLV parameters for the ASCONF Chunk that will add or
3994 * delete IP addresses the D0 to D13 rules should be applied:
3996 enum sctp_disposition
sctp_sf_do_asconf_ack(struct net
*net
,
3997 const struct sctp_endpoint
*ep
,
3998 const struct sctp_association
*asoc
,
3999 const union sctp_subtype type
,
4001 struct sctp_cmd_seq
*commands
)
4003 struct sctp_chunk
*last_asconf
= asoc
->addip_last_asconf
;
4004 struct sctp_paramhdr
*err_param
= NULL
;
4005 struct sctp_chunk
*asconf_ack
= arg
;
4006 struct sctp_addiphdr
*addip_hdr
;
4007 __u32 sent_serial
, rcvd_serial
;
4008 struct sctp_chunk
*abort
;
4010 if (!sctp_vtag_verify(asconf_ack
, asoc
)) {
4011 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
4013 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4016 /* Make sure that the ADDIP chunk has a valid length. */
4017 if (!sctp_chunk_length_valid(asconf_ack
,
4018 sizeof(struct sctp_addip_chunk
)))
4019 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4022 /* ADD-IP, Section 4.1.2:
4023 * This chunk MUST be sent in an authenticated way by using
4024 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
4025 * is received unauthenticated it MUST be silently discarded as
4026 * described in [I-D.ietf-tsvwg-sctp-auth].
4028 if (!asoc
->peer
.asconf_capable
||
4029 (!net
->sctp
.addip_noauth
&& !asconf_ack
->auth
))
4030 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4032 addip_hdr
= (struct sctp_addiphdr
*)asconf_ack
->skb
->data
;
4033 rcvd_serial
= ntohl(addip_hdr
->serial
);
4035 /* Verify the ASCONF-ACK chunk before processing it. */
4036 if (!sctp_verify_asconf(asoc
, asconf_ack
, false, &err_param
))
4037 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
4038 (void *)err_param
, commands
);
4041 addip_hdr
= (struct sctp_addiphdr
*)last_asconf
->subh
.addip_hdr
;
4042 sent_serial
= ntohl(addip_hdr
->serial
);
4044 sent_serial
= asoc
->addip_serial
- 1;
4047 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
4048 * equal to the next serial number to be used but no ASCONF chunk is
4049 * outstanding the endpoint MUST ABORT the association. Note that a
4050 * sequence number is greater than if it is no more than 2^^31-1
4051 * larger than the current sequence number (using serial arithmetic).
4053 if (ADDIP_SERIAL_gte(rcvd_serial
, sent_serial
+ 1) &&
4054 !(asoc
->addip_last_asconf
)) {
4055 abort
= sctp_make_abort(asoc
, asconf_ack
,
4056 sizeof(struct sctp_errhdr
));
4058 sctp_init_cause(abort
, SCTP_ERROR_ASCONF_ACK
, 0);
4059 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4062 /* We are going to ABORT, so we might as well stop
4063 * processing the rest of the chunks in the packet.
4065 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4066 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
4067 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
4068 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4069 SCTP_ERROR(ECONNABORTED
));
4070 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4071 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
4072 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4073 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4074 return SCTP_DISPOSITION_ABORT
;
4077 if ((rcvd_serial
== sent_serial
) && asoc
->addip_last_asconf
) {
4078 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4079 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
4081 if (!sctp_process_asconf_ack((struct sctp_association
*)asoc
,
4083 return sctp_send_next_asconf(net
, ep
,
4084 (struct sctp_association
*)asoc
,
4087 abort
= sctp_make_abort(asoc
, asconf_ack
,
4088 sizeof(struct sctp_errhdr
));
4090 sctp_init_cause(abort
, SCTP_ERROR_RSRC_LOW
, 0);
4091 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4094 /* We are going to ABORT, so we might as well stop
4095 * processing the rest of the chunks in the packet.
4097 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
4098 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4099 SCTP_ERROR(ECONNABORTED
));
4100 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4101 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
4102 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4103 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4104 return SCTP_DISPOSITION_ABORT
;
4107 return SCTP_DISPOSITION_DISCARD
;
4110 /* RE-CONFIG Section 5.2 Upon reception of an RECONF Chunk. */
4111 enum sctp_disposition
sctp_sf_do_reconf(struct net
*net
,
4112 const struct sctp_endpoint
*ep
,
4113 const struct sctp_association
*asoc
,
4114 const union sctp_subtype type
,
4116 struct sctp_cmd_seq
*commands
)
4118 struct sctp_paramhdr
*err_param
= NULL
;
4119 struct sctp_chunk
*chunk
= arg
;
4120 struct sctp_reconf_chunk
*hdr
;
4121 union sctp_params param
;
4123 if (!sctp_vtag_verify(chunk
, asoc
)) {
4124 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
4126 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4129 /* Make sure that the RECONF chunk has a valid length. */
4130 if (!sctp_chunk_length_valid(chunk
, sizeof(*hdr
)))
4131 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4134 if (!sctp_verify_reconf(asoc
, chunk
, &err_param
))
4135 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
4136 (void *)err_param
, commands
);
4138 hdr
= (struct sctp_reconf_chunk
*)chunk
->chunk_hdr
;
4139 sctp_walk_params(param
, hdr
, params
) {
4140 struct sctp_chunk
*reply
= NULL
;
4141 struct sctp_ulpevent
*ev
= NULL
;
4143 if (param
.p
->type
== SCTP_PARAM_RESET_OUT_REQUEST
)
4144 reply
= sctp_process_strreset_outreq(
4145 (struct sctp_association
*)asoc
, param
, &ev
);
4146 else if (param
.p
->type
== SCTP_PARAM_RESET_IN_REQUEST
)
4147 reply
= sctp_process_strreset_inreq(
4148 (struct sctp_association
*)asoc
, param
, &ev
);
4149 else if (param
.p
->type
== SCTP_PARAM_RESET_TSN_REQUEST
)
4150 reply
= sctp_process_strreset_tsnreq(
4151 (struct sctp_association
*)asoc
, param
, &ev
);
4152 else if (param
.p
->type
== SCTP_PARAM_RESET_ADD_OUT_STREAMS
)
4153 reply
= sctp_process_strreset_addstrm_out(
4154 (struct sctp_association
*)asoc
, param
, &ev
);
4155 else if (param
.p
->type
== SCTP_PARAM_RESET_ADD_IN_STREAMS
)
4156 reply
= sctp_process_strreset_addstrm_in(
4157 (struct sctp_association
*)asoc
, param
, &ev
);
4158 else if (param
.p
->type
== SCTP_PARAM_RESET_RESPONSE
)
4159 reply
= sctp_process_strreset_resp(
4160 (struct sctp_association
*)asoc
, param
, &ev
);
4163 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
4167 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4171 return SCTP_DISPOSITION_CONSUME
;
4175 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
4177 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
4178 * its cumulative TSN point to the value carried in the FORWARD TSN
4179 * chunk, and then MUST further advance its cumulative TSN point locally
4181 * After the above processing, the data receiver MUST stop reporting any
4182 * missing TSNs earlier than or equal to the new cumulative TSN point.
4184 * Verification Tag: 8.5 Verification Tag [Normal verification]
4186 * The return value is the disposition of the chunk.
4188 enum sctp_disposition
sctp_sf_eat_fwd_tsn(struct net
*net
,
4189 const struct sctp_endpoint
*ep
,
4190 const struct sctp_association
*asoc
,
4191 const union sctp_subtype type
,
4193 struct sctp_cmd_seq
*commands
)
4195 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
4196 struct sctp_chunk
*chunk
= arg
;
4200 if (!sctp_vtag_verify(chunk
, asoc
)) {
4201 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
4203 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4206 if (!asoc
->peer
.prsctp_capable
)
4207 return sctp_sf_unk_chunk(net
, ep
, asoc
, type
, arg
, commands
);
4209 /* Make sure that the FORWARD_TSN chunk has valid length. */
4210 if (!sctp_chunk_length_valid(chunk
, sctp_ftsnchk_len(&asoc
->stream
)))
4211 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4214 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
4215 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
4216 len
= ntohs(chunk
->chunk_hdr
->length
);
4217 len
-= sizeof(struct sctp_chunkhdr
);
4218 skb_pull(chunk
->skb
, len
);
4220 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
4221 pr_debug("%s: TSN 0x%x\n", __func__
, tsn
);
4223 /* The TSN is too high--silently discard the chunk and count on it
4224 * getting retransmitted later.
4226 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
4227 goto discard_noforce
;
4229 if (!asoc
->stream
.si
->validate_ftsn(chunk
))
4230 goto discard_noforce
;
4232 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
4233 if (len
> sctp_ftsnhdr_len(&asoc
->stream
))
4234 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
4237 /* Count this as receiving DATA. */
4238 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
]) {
4239 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
4240 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
4243 /* FIXME: For now send a SACK, but DATA processing may
4246 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
4248 return SCTP_DISPOSITION_CONSUME
;
4251 return SCTP_DISPOSITION_DISCARD
;
4254 enum sctp_disposition
sctp_sf_eat_fwd_tsn_fast(
4256 const struct sctp_endpoint
*ep
,
4257 const struct sctp_association
*asoc
,
4258 const union sctp_subtype type
,
4260 struct sctp_cmd_seq
*commands
)
4262 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
4263 struct sctp_chunk
*chunk
= arg
;
4267 if (!sctp_vtag_verify(chunk
, asoc
)) {
4268 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
4270 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4273 if (!asoc
->peer
.prsctp_capable
)
4274 return sctp_sf_unk_chunk(net
, ep
, asoc
, type
, arg
, commands
);
4276 /* Make sure that the FORWARD_TSN chunk has a valid length. */
4277 if (!sctp_chunk_length_valid(chunk
, sctp_ftsnchk_len(&asoc
->stream
)))
4278 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4281 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
4282 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
4283 len
= ntohs(chunk
->chunk_hdr
->length
);
4284 len
-= sizeof(struct sctp_chunkhdr
);
4285 skb_pull(chunk
->skb
, len
);
4287 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
4288 pr_debug("%s: TSN 0x%x\n", __func__
, tsn
);
4290 /* The TSN is too high--silently discard the chunk and count on it
4291 * getting retransmitted later.
4293 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
4296 if (!asoc
->stream
.si
->validate_ftsn(chunk
))
4299 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
4300 if (len
> sctp_ftsnhdr_len(&asoc
->stream
))
4301 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
4304 /* Go a head and force a SACK, since we are shutting down. */
4306 /* Implementor's Guide.
4308 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
4309 * respond to each received packet containing one or more DATA chunk(s)
4310 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
4312 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
4313 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
4314 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
4315 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
4317 return SCTP_DISPOSITION_CONSUME
;
4321 * SCTP-AUTH Section 6.3 Receiving authenticated chunks
4323 * The receiver MUST use the HMAC algorithm indicated in the HMAC
4324 * Identifier field. If this algorithm was not specified by the
4325 * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk
4326 * during association setup, the AUTH chunk and all chunks after it MUST
4327 * be discarded and an ERROR chunk SHOULD be sent with the error cause
4328 * defined in Section 4.1.
4330 * If an endpoint with no shared key receives a Shared Key Identifier
4331 * other than 0, it MUST silently discard all authenticated chunks. If
4332 * the endpoint has at least one endpoint pair shared key for the peer,
4333 * it MUST use the key specified by the Shared Key Identifier if a
4334 * key has been configured for that Shared Key Identifier. If no
4335 * endpoint pair shared key has been configured for that Shared Key
4336 * Identifier, all authenticated chunks MUST be silently discarded.
4338 * Verification Tag: 8.5 Verification Tag [Normal verification]
4340 * The return value is the disposition of the chunk.
4342 static enum sctp_ierror
sctp_sf_authenticate(
4343 const struct sctp_association
*asoc
,
4344 struct sctp_chunk
*chunk
)
4346 struct sctp_shared_key
*sh_key
= NULL
;
4347 struct sctp_authhdr
*auth_hdr
;
4348 __u8
*save_digest
, *digest
;
4349 struct sctp_hmac
*hmac
;
4350 unsigned int sig_len
;
4353 /* Pull in the auth header, so we can do some more verification */
4354 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
4355 chunk
->subh
.auth_hdr
= auth_hdr
;
4356 skb_pull(chunk
->skb
, sizeof(*auth_hdr
));
4358 /* Make sure that we support the HMAC algorithm from the auth
4361 if (!sctp_auth_asoc_verify_hmac_id(asoc
, auth_hdr
->hmac_id
))
4362 return SCTP_IERROR_AUTH_BAD_HMAC
;
4364 /* Make sure that the provided shared key identifier has been
4367 key_id
= ntohs(auth_hdr
->shkey_id
);
4368 if (key_id
!= asoc
->active_key_id
) {
4369 sh_key
= sctp_auth_get_shkey(asoc
, key_id
);
4371 return SCTP_IERROR_AUTH_BAD_KEYID
;
4374 /* Make sure that the length of the signature matches what
4377 sig_len
= ntohs(chunk
->chunk_hdr
->length
) -
4378 sizeof(struct sctp_auth_chunk
);
4379 hmac
= sctp_auth_get_hmac(ntohs(auth_hdr
->hmac_id
));
4380 if (sig_len
!= hmac
->hmac_len
)
4381 return SCTP_IERROR_PROTO_VIOLATION
;
4383 /* Now that we've done validation checks, we can compute and
4384 * verify the hmac. The steps involved are:
4385 * 1. Save the digest from the chunk.
4386 * 2. Zero out the digest in the chunk.
4387 * 3. Compute the new digest
4388 * 4. Compare saved and new digests.
4390 digest
= auth_hdr
->hmac
;
4391 skb_pull(chunk
->skb
, sig_len
);
4393 save_digest
= kmemdup(digest
, sig_len
, GFP_ATOMIC
);
4397 memset(digest
, 0, sig_len
);
4399 sctp_auth_calculate_hmac(asoc
, chunk
->skb
,
4400 (struct sctp_auth_chunk
*)chunk
->chunk_hdr
,
4401 sh_key
, GFP_ATOMIC
);
4403 /* Discard the packet if the digests do not match */
4404 if (memcmp(save_digest
, digest
, sig_len
)) {
4406 return SCTP_IERROR_BAD_SIG
;
4412 return SCTP_IERROR_NO_ERROR
;
4414 return SCTP_IERROR_NOMEM
;
4417 enum sctp_disposition
sctp_sf_eat_auth(struct net
*net
,
4418 const struct sctp_endpoint
*ep
,
4419 const struct sctp_association
*asoc
,
4420 const union sctp_subtype type
,
4421 void *arg
, struct sctp_cmd_seq
*commands
)
4423 struct sctp_chunk
*chunk
= arg
;
4424 struct sctp_authhdr
*auth_hdr
;
4425 struct sctp_chunk
*err_chunk
;
4426 enum sctp_ierror error
;
4428 /* Make sure that the peer has AUTH capable */
4429 if (!asoc
->peer
.auth_capable
)
4430 return sctp_sf_unk_chunk(net
, ep
, asoc
, type
, arg
, commands
);
4432 if (!sctp_vtag_verify(chunk
, asoc
)) {
4433 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
4435 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4438 /* Make sure that the AUTH chunk has valid length. */
4439 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_auth_chunk
)))
4440 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4443 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
4444 error
= sctp_sf_authenticate(asoc
, chunk
);
4446 case SCTP_IERROR_AUTH_BAD_HMAC
:
4447 /* Generate the ERROR chunk and discard the rest
4450 err_chunk
= sctp_make_op_error(asoc
, chunk
,
4451 SCTP_ERROR_UNSUP_HMAC
,
4455 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4456 SCTP_CHUNK(err_chunk
));
4459 case SCTP_IERROR_AUTH_BAD_KEYID
:
4460 case SCTP_IERROR_BAD_SIG
:
4461 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4463 case SCTP_IERROR_PROTO_VIOLATION
:
4464 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4467 case SCTP_IERROR_NOMEM
:
4468 return SCTP_DISPOSITION_NOMEM
;
4470 default: /* Prevent gcc warnings */
4474 if (asoc
->active_key_id
!= ntohs(auth_hdr
->shkey_id
)) {
4475 struct sctp_ulpevent
*ev
;
4477 ev
= sctp_ulpevent_make_authkey(asoc
, ntohs(auth_hdr
->shkey_id
),
4478 SCTP_AUTH_NEW_KEY
, GFP_ATOMIC
);
4483 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
4487 return SCTP_DISPOSITION_CONSUME
;
4491 * Process an unknown chunk.
4493 * Section: 3.2. Also, 2.1 in the implementor's guide.
4495 * Chunk Types are encoded such that the highest-order two bits specify
4496 * the action that must be taken if the processing endpoint does not
4497 * recognize the Chunk Type.
4499 * 00 - Stop processing this SCTP packet and discard it, do not process
4500 * any further chunks within it.
4502 * 01 - Stop processing this SCTP packet and discard it, do not process
4503 * any further chunks within it, and report the unrecognized
4504 * chunk in an 'Unrecognized Chunk Type'.
4506 * 10 - Skip this chunk and continue processing.
4508 * 11 - Skip this chunk and continue processing, but report in an ERROR
4509 * Chunk using the 'Unrecognized Chunk Type' cause of error.
4511 * The return value is the disposition of the chunk.
4513 enum sctp_disposition
sctp_sf_unk_chunk(struct net
*net
,
4514 const struct sctp_endpoint
*ep
,
4515 const struct sctp_association
*asoc
,
4516 const union sctp_subtype type
,
4518 struct sctp_cmd_seq
*commands
)
4520 struct sctp_chunk
*unk_chunk
= arg
;
4521 struct sctp_chunk
*err_chunk
;
4522 struct sctp_chunkhdr
*hdr
;
4524 pr_debug("%s: processing unknown chunk id:%d\n", __func__
, type
.chunk
);
4526 if (!sctp_vtag_verify(unk_chunk
, asoc
))
4527 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4529 /* Make sure that the chunk has a valid length.
4530 * Since we don't know the chunk type, we use a general
4531 * chunkhdr structure to make a comparison.
4533 if (!sctp_chunk_length_valid(unk_chunk
, sizeof(*hdr
)))
4534 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4537 switch (type
.chunk
& SCTP_CID_ACTION_MASK
) {
4538 case SCTP_CID_ACTION_DISCARD
:
4539 /* Discard the packet. */
4540 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4541 case SCTP_CID_ACTION_DISCARD_ERR
:
4542 /* Generate an ERROR chunk as response. */
4543 hdr
= unk_chunk
->chunk_hdr
;
4544 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4545 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4546 SCTP_PAD4(ntohs(hdr
->length
)),
4549 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4550 SCTP_CHUNK(err_chunk
));
4553 /* Discard the packet. */
4554 sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4555 return SCTP_DISPOSITION_CONSUME
;
4556 case SCTP_CID_ACTION_SKIP
:
4557 /* Skip the chunk. */
4558 return SCTP_DISPOSITION_DISCARD
;
4559 case SCTP_CID_ACTION_SKIP_ERR
:
4560 /* Generate an ERROR chunk as response. */
4561 hdr
= unk_chunk
->chunk_hdr
;
4562 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4563 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4564 SCTP_PAD4(ntohs(hdr
->length
)),
4567 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4568 SCTP_CHUNK(err_chunk
));
4570 /* Skip the chunk. */
4571 return SCTP_DISPOSITION_CONSUME
;
4576 return SCTP_DISPOSITION_DISCARD
;
4580 * Discard the chunk.
4582 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
4583 * [Too numerous to mention...]
4584 * Verification Tag: No verification needed.
4586 * (endpoint, asoc, chunk)
4589 * (asoc, reply_msg, msg_up, timers, counters)
4591 * The return value is the disposition of the chunk.
4593 enum sctp_disposition
sctp_sf_discard_chunk(struct net
*net
,
4594 const struct sctp_endpoint
*ep
,
4595 const struct sctp_association
*asoc
,
4596 const union sctp_subtype type
,
4598 struct sctp_cmd_seq
*commands
)
4600 struct sctp_chunk
*chunk
= arg
;
4602 if (asoc
&& !sctp_vtag_verify(chunk
, asoc
))
4603 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4605 /* Make sure that the chunk has a valid length.
4606 * Since we don't know the chunk type, we use a general
4607 * chunkhdr structure to make a comparison.
4609 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
4610 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4613 pr_debug("%s: chunk:%d is discarded\n", __func__
, type
.chunk
);
4615 return SCTP_DISPOSITION_DISCARD
;
4619 * Discard the whole packet.
4623 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
4624 * silently discard the OOTB packet and take no further action.
4626 * Verification Tag: No verification necessary
4629 * (endpoint, asoc, chunk)
4632 * (asoc, reply_msg, msg_up, timers, counters)
4634 * The return value is the disposition of the chunk.
4636 enum sctp_disposition
sctp_sf_pdiscard(struct net
*net
,
4637 const struct sctp_endpoint
*ep
,
4638 const struct sctp_association
*asoc
,
4639 const union sctp_subtype type
,
4640 void *arg
, struct sctp_cmd_seq
*commands
)
4642 SCTP_INC_STATS(net
, SCTP_MIB_IN_PKT_DISCARDS
);
4643 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
4645 return SCTP_DISPOSITION_CONSUME
;
4650 * The other end is violating protocol.
4652 * Section: Not specified
4653 * Verification Tag: Not specified
4655 * (endpoint, asoc, chunk)
4658 * (asoc, reply_msg, msg_up, timers, counters)
4660 * We simply tag the chunk as a violation. The state machine will log
4661 * the violation and continue.
4663 enum sctp_disposition
sctp_sf_violation(struct net
*net
,
4664 const struct sctp_endpoint
*ep
,
4665 const struct sctp_association
*asoc
,
4666 const union sctp_subtype type
,
4668 struct sctp_cmd_seq
*commands
)
4670 struct sctp_chunk
*chunk
= arg
;
4672 if (!sctp_vtag_verify(chunk
, asoc
))
4673 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4675 /* Make sure that the chunk has a valid length. */
4676 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_chunkhdr
)))
4677 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4680 return SCTP_DISPOSITION_VIOLATION
;
4684 * Common function to handle a protocol violation.
4686 static enum sctp_disposition
sctp_sf_abort_violation(
4688 const struct sctp_endpoint
*ep
,
4689 const struct sctp_association
*asoc
,
4691 struct sctp_cmd_seq
*commands
,
4692 const __u8
*payload
,
4693 const size_t paylen
)
4695 struct sctp_packet
*packet
= NULL
;
4696 struct sctp_chunk
*chunk
= arg
;
4697 struct sctp_chunk
*abort
= NULL
;
4699 /* SCTP-AUTH, Section 6.3:
4700 * It should be noted that if the receiver wants to tear
4701 * down an association in an authenticated way only, the
4702 * handling of malformed packets should not result in
4703 * tearing down the association.
4705 * This means that if we only want to abort associations
4706 * in an authenticated way (i.e AUTH+ABORT), then we
4707 * can't destroy this association just because the packet
4710 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4713 /* Make the abort chunk. */
4714 abort
= sctp_make_abort_violation(asoc
, chunk
, payload
, paylen
);
4719 /* Treat INIT-ACK as a special case during COOKIE-WAIT. */
4720 if (chunk
->chunk_hdr
->type
== SCTP_CID_INIT_ACK
&&
4721 !asoc
->peer
.i
.init_tag
) {
4722 struct sctp_initack_chunk
*initack
;
4724 initack
= (struct sctp_initack_chunk
*)chunk
->chunk_hdr
;
4725 if (!sctp_chunk_length_valid(chunk
, sizeof(*initack
)))
4726 abort
->chunk_hdr
->flags
|= SCTP_CHUNK_FLAG_T
;
4728 unsigned int inittag
;
4730 inittag
= ntohl(initack
->init_hdr
.init_tag
);
4731 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_INITTAG
,
4736 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4737 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4739 if (asoc
->state
<= SCTP_STATE_COOKIE_ECHOED
) {
4740 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4741 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4742 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4743 SCTP_ERROR(ECONNREFUSED
));
4744 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4745 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4747 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4748 SCTP_ERROR(ECONNABORTED
));
4749 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4750 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4751 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4754 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
4759 if (sctp_test_T_bit(abort
))
4760 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
4762 abort
->skb
->sk
= ep
->base
.sk
;
4764 sctp_packet_append_chunk(packet
, abort
);
4766 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
4767 SCTP_PACKET(packet
));
4769 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4772 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4775 sctp_sf_pdiscard(net
, ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4776 return SCTP_DISPOSITION_ABORT
;
4779 sctp_chunk_free(abort
);
4781 return SCTP_DISPOSITION_NOMEM
;
4785 * Handle a protocol violation when the chunk length is invalid.
4786 * "Invalid" length is identified as smaller than the minimal length a
4787 * given chunk can be. For example, a SACK chunk has invalid length
4788 * if its length is set to be smaller than the size of struct sctp_sack_chunk.
4790 * We inform the other end by sending an ABORT with a Protocol Violation
4793 * Section: Not specified
4794 * Verification Tag: Nothing to do
4796 * (endpoint, asoc, chunk)
4799 * (reply_msg, msg_up, counters)
4801 * Generate an ABORT chunk and terminate the association.
4803 static enum sctp_disposition
sctp_sf_violation_chunklen(
4805 const struct sctp_endpoint
*ep
,
4806 const struct sctp_association
*asoc
,
4807 const union sctp_subtype type
,
4809 struct sctp_cmd_seq
*commands
)
4811 static const char err_str
[] = "The following chunk had invalid length:";
4813 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4818 * Handle a protocol violation when the parameter length is invalid.
4819 * If the length is smaller than the minimum length of a given parameter,
4820 * or accumulated length in multi parameters exceeds the end of the chunk,
4821 * the length is considered as invalid.
4823 static enum sctp_disposition
sctp_sf_violation_paramlen(
4825 const struct sctp_endpoint
*ep
,
4826 const struct sctp_association
*asoc
,
4827 const union sctp_subtype type
,
4828 void *arg
, void *ext
,
4829 struct sctp_cmd_seq
*commands
)
4831 struct sctp_paramhdr
*param
= ext
;
4832 struct sctp_chunk
*abort
= NULL
;
4833 struct sctp_chunk
*chunk
= arg
;
4835 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4838 /* Make the abort chunk. */
4839 abort
= sctp_make_violation_paramlen(asoc
, chunk
, param
);
4843 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4844 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4846 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4847 SCTP_ERROR(ECONNABORTED
));
4848 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4849 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4850 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4851 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4854 sctp_sf_pdiscard(net
, ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4855 return SCTP_DISPOSITION_ABORT
;
4857 return SCTP_DISPOSITION_NOMEM
;
4860 /* Handle a protocol violation when the peer trying to advance the
4861 * cumulative tsn ack to a point beyond the max tsn currently sent.
4863 * We inform the other end by sending an ABORT with a Protocol Violation
4866 static enum sctp_disposition
sctp_sf_violation_ctsn(
4868 const struct sctp_endpoint
*ep
,
4869 const struct sctp_association
*asoc
,
4870 const union sctp_subtype type
,
4872 struct sctp_cmd_seq
*commands
)
4874 static const char err_str
[] = "The cumulative tsn ack beyond the max tsn currently sent:";
4876 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4880 /* Handle protocol violation of an invalid chunk bundling. For example,
4881 * when we have an association and we receive bundled INIT-ACK, or
4882 * SHUTDOWN-COMPLETE, our peer is clearly violating the "MUST NOT bundle"
4883 * statement from the specs. Additionally, there might be an attacker
4884 * on the path and we may not want to continue this communication.
4886 static enum sctp_disposition
sctp_sf_violation_chunk(
4888 const struct sctp_endpoint
*ep
,
4889 const struct sctp_association
*asoc
,
4890 const union sctp_subtype type
,
4892 struct sctp_cmd_seq
*commands
)
4894 static const char err_str
[] = "The following chunk violates protocol:";
4897 return sctp_sf_violation(net
, ep
, asoc
, type
, arg
, commands
);
4899 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4902 /***************************************************************************
4903 * These are the state functions for handling primitive (Section 10) events.
4904 ***************************************************************************/
4906 * sctp_sf_do_prm_asoc
4908 * Section: 10.1 ULP-to-SCTP
4911 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
4912 * outbound stream count)
4913 * -> association id [,destination transport addr list] [,outbound stream
4916 * This primitive allows the upper layer to initiate an association to a
4917 * specific peer endpoint.
4919 * The peer endpoint shall be specified by one of the transport addresses
4920 * which defines the endpoint (see Section 1.4). If the local SCTP
4921 * instance has not been initialized, the ASSOCIATE is considered an
4923 * [This is not relevant for the kernel implementation since we do all
4924 * initialization at boot time. It we hadn't initialized we wouldn't
4925 * get anywhere near this code.]
4927 * An association id, which is a local handle to the SCTP association,
4928 * will be returned on successful establishment of the association. If
4929 * SCTP is not able to open an SCTP association with the peer endpoint,
4930 * an error is returned.
4931 * [In the kernel implementation, the struct sctp_association needs to
4932 * be created BEFORE causing this primitive to run.]
4934 * Other association parameters may be returned, including the
4935 * complete destination transport addresses of the peer as well as the
4936 * outbound stream count of the local endpoint. One of the transport
4937 * address from the returned destination addresses will be selected by
4938 * the local endpoint as default primary path for sending SCTP packets
4939 * to this peer. The returned "destination transport addr list" can
4940 * be used by the ULP to change the default primary path or to force
4941 * sending a packet to a specific transport address. [All of this
4942 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
4945 * Mandatory attributes:
4947 * o local SCTP instance name - obtained from the INITIALIZE operation.
4948 * [This is the argument asoc.]
4949 * o destination transport addr - specified as one of the transport
4950 * addresses of the peer endpoint with which the association is to be
4952 * [This is asoc->peer.active_path.]
4953 * o outbound stream count - the number of outbound streams the ULP
4954 * would like to open towards this peer endpoint.
4955 * [BUG: This is not currently implemented.]
4956 * Optional attributes:
4960 * The return value is a disposition.
4962 enum sctp_disposition
sctp_sf_do_prm_asoc(struct net
*net
,
4963 const struct sctp_endpoint
*ep
,
4964 const struct sctp_association
*asoc
,
4965 const union sctp_subtype type
,
4967 struct sctp_cmd_seq
*commands
)
4969 struct sctp_association
*my_asoc
;
4970 struct sctp_chunk
*repl
;
4972 /* The comment below says that we enter COOKIE-WAIT AFTER
4973 * sending the INIT, but that doesn't actually work in our
4976 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4977 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
4979 /* RFC 2960 5.1 Normal Establishment of an Association
4981 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
4982 * must provide its Verification Tag (Tag_A) in the Initiate
4983 * Tag field. Tag_A SHOULD be a random number in the range of
4984 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
4987 repl
= sctp_make_init(asoc
, &asoc
->base
.bind_addr
, GFP_ATOMIC
, 0);
4991 /* Choose transport for INIT. */
4992 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
4995 /* Cast away the const modifier, as we want to just
4996 * rerun it through as a sideffect.
4998 my_asoc
= (struct sctp_association
*)asoc
;
4999 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(my_asoc
));
5001 /* After sending the INIT, "A" starts the T1-init timer and
5002 * enters the COOKIE-WAIT state.
5004 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5005 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5006 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5007 return SCTP_DISPOSITION_CONSUME
;
5010 return SCTP_DISPOSITION_NOMEM
;
5014 * Process the SEND primitive.
5016 * Section: 10.1 ULP-to-SCTP
5019 * Format: SEND(association id, buffer address, byte count [,context]
5020 * [,stream id] [,life time] [,destination transport address]
5021 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
5024 * This is the main method to send user data via SCTP.
5026 * Mandatory attributes:
5028 * o association id - local handle to the SCTP association
5030 * o buffer address - the location where the user message to be
5031 * transmitted is stored;
5033 * o byte count - The size of the user data in number of bytes;
5035 * Optional attributes:
5037 * o context - an optional 32 bit integer that will be carried in the
5038 * sending failure notification to the ULP if the transportation of
5039 * this User Message fails.
5041 * o stream id - to indicate which stream to send the data on. If not
5042 * specified, stream 0 will be used.
5044 * o life time - specifies the life time of the user data. The user data
5045 * will not be sent by SCTP after the life time expires. This
5046 * parameter can be used to avoid efforts to transmit stale
5047 * user messages. SCTP notifies the ULP if the data cannot be
5048 * initiated to transport (i.e. sent to the destination via SCTP's
5049 * send primitive) within the life time variable. However, the
5050 * user data will be transmitted if SCTP has attempted to transmit a
5051 * chunk before the life time expired.
5053 * o destination transport address - specified as one of the destination
5054 * transport addresses of the peer endpoint to which this packet
5055 * should be sent. Whenever possible, SCTP should use this destination
5056 * transport address for sending the packets, instead of the current
5059 * o unorder flag - this flag, if present, indicates that the user
5060 * would like the data delivered in an unordered fashion to the peer
5061 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
5064 * o no-bundle flag - instructs SCTP not to bundle this user data with
5065 * other outbound DATA chunks. SCTP MAY still bundle even when
5066 * this flag is present, when faced with network congestion.
5068 * o payload protocol-id - A 32 bit unsigned integer that is to be
5069 * passed to the peer indicating the type of payload protocol data
5070 * being transmitted. This value is passed as opaque data by SCTP.
5072 * The return value is the disposition.
5074 enum sctp_disposition
sctp_sf_do_prm_send(struct net
*net
,
5075 const struct sctp_endpoint
*ep
,
5076 const struct sctp_association
*asoc
,
5077 const union sctp_subtype type
,
5079 struct sctp_cmd_seq
*commands
)
5081 struct sctp_datamsg
*msg
= arg
;
5083 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_MSG
, SCTP_DATAMSG(msg
));
5084 return SCTP_DISPOSITION_CONSUME
;
5088 * Process the SHUTDOWN primitive.
5093 * Format: SHUTDOWN(association id)
5096 * Gracefully closes an association. Any locally queued user data
5097 * will be delivered to the peer. The association will be terminated only
5098 * after the peer acknowledges all the SCTP packets sent. A success code
5099 * will be returned on successful termination of the association. If
5100 * attempting to terminate the association results in a failure, an error
5101 * code shall be returned.
5103 * Mandatory attributes:
5105 * o association id - local handle to the SCTP association
5107 * Optional attributes:
5111 * The return value is the disposition.
5113 enum sctp_disposition
sctp_sf_do_9_2_prm_shutdown(
5115 const struct sctp_endpoint
*ep
,
5116 const struct sctp_association
*asoc
,
5117 const union sctp_subtype type
,
5119 struct sctp_cmd_seq
*commands
)
5121 enum sctp_disposition disposition
;
5123 /* From 9.2 Shutdown of an Association
5124 * Upon receipt of the SHUTDOWN primitive from its upper
5125 * layer, the endpoint enters SHUTDOWN-PENDING state and
5126 * remains there until all outstanding data has been
5127 * acknowledged by its peer. The endpoint accepts no new data
5128 * from its upper layer, but retransmits data to the far end
5129 * if necessary to fill gaps.
5131 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5132 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
5134 disposition
= SCTP_DISPOSITION_CONSUME
;
5135 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
5136 disposition
= sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
, type
,
5144 * Process the ABORT primitive.
5149 * Format: Abort(association id [, cause code])
5152 * Ungracefully closes an association. Any locally queued user data
5153 * will be discarded and an ABORT chunk is sent to the peer. A success code
5154 * will be returned on successful abortion of the association. If
5155 * attempting to abort the association results in a failure, an error
5156 * code shall be returned.
5158 * Mandatory attributes:
5160 * o association id - local handle to the SCTP association
5162 * Optional attributes:
5164 * o cause code - reason of the abort to be passed to the peer
5168 * The return value is the disposition.
5170 enum sctp_disposition
sctp_sf_do_9_1_prm_abort(
5172 const struct sctp_endpoint
*ep
,
5173 const struct sctp_association
*asoc
,
5174 const union sctp_subtype type
,
5176 struct sctp_cmd_seq
*commands
)
5178 /* From 9.1 Abort of an Association
5179 * Upon receipt of the ABORT primitive from its upper
5180 * layer, the endpoint enters CLOSED state and
5181 * discard all outstanding data has been
5182 * acknowledged by its peer. The endpoint accepts no new data
5183 * from its upper layer, but retransmits data to the far end
5184 * if necessary to fill gaps.
5186 struct sctp_chunk
*abort
= arg
;
5189 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
5191 /* Even if we can't send the ABORT due to low memory delete the
5192 * TCB. This is a departure from our typical NOMEM handling.
5195 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5196 SCTP_ERROR(ECONNABORTED
));
5197 /* Delete the established association. */
5198 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5199 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
5201 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5202 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5204 return SCTP_DISPOSITION_ABORT
;
5207 /* We tried an illegal operation on an association which is closed. */
5208 enum sctp_disposition
sctp_sf_error_closed(struct net
*net
,
5209 const struct sctp_endpoint
*ep
,
5210 const struct sctp_association
*asoc
,
5211 const union sctp_subtype type
,
5213 struct sctp_cmd_seq
*commands
)
5215 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
, SCTP_ERROR(-EINVAL
));
5216 return SCTP_DISPOSITION_CONSUME
;
5219 /* We tried an illegal operation on an association which is shutting
5222 enum sctp_disposition
sctp_sf_error_shutdown(
5224 const struct sctp_endpoint
*ep
,
5225 const struct sctp_association
*asoc
,
5226 const union sctp_subtype type
,
5228 struct sctp_cmd_seq
*commands
)
5230 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
,
5231 SCTP_ERROR(-ESHUTDOWN
));
5232 return SCTP_DISPOSITION_CONSUME
;
5236 * sctp_cookie_wait_prm_shutdown
5238 * Section: 4 Note: 2
5243 * The RFC does not explicitly address this issue, but is the route through the
5244 * state table when someone issues a shutdown while in COOKIE_WAIT state.
5249 enum sctp_disposition
sctp_sf_cookie_wait_prm_shutdown(
5251 const struct sctp_endpoint
*ep
,
5252 const struct sctp_association
*asoc
,
5253 const union sctp_subtype type
,
5255 struct sctp_cmd_seq
*commands
)
5257 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5258 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5260 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5261 SCTP_STATE(SCTP_STATE_CLOSED
));
5263 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
5265 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
5267 return SCTP_DISPOSITION_DELETE_TCB
;
5271 * sctp_cookie_echoed_prm_shutdown
5273 * Section: 4 Note: 2
5278 * The RFC does not explicitly address this issue, but is the route through the
5279 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
5284 enum sctp_disposition
sctp_sf_cookie_echoed_prm_shutdown(
5286 const struct sctp_endpoint
*ep
,
5287 const struct sctp_association
*asoc
,
5288 const union sctp_subtype type
,
5290 struct sctp_cmd_seq
*commands
)
5292 /* There is a single T1 timer, so we should be able to use
5293 * common function with the COOKIE-WAIT state.
5295 return sctp_sf_cookie_wait_prm_shutdown(net
, ep
, asoc
, type
, arg
, commands
);
5299 * sctp_sf_cookie_wait_prm_abort
5301 * Section: 4 Note: 2
5306 * The RFC does not explicitly address this issue, but is the route through the
5307 * state table when someone issues an abort while in COOKIE_WAIT state.
5312 enum sctp_disposition
sctp_sf_cookie_wait_prm_abort(
5314 const struct sctp_endpoint
*ep
,
5315 const struct sctp_association
*asoc
,
5316 const union sctp_subtype type
,
5318 struct sctp_cmd_seq
*commands
)
5320 struct sctp_chunk
*abort
= arg
;
5322 /* Stop T1-init timer */
5323 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5324 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5327 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
5329 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5330 SCTP_STATE(SCTP_STATE_CLOSED
));
5332 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5334 /* Even if we can't send the ABORT due to low memory delete the
5335 * TCB. This is a departure from our typical NOMEM handling.
5338 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5339 SCTP_ERROR(ECONNREFUSED
));
5340 /* Delete the established association. */
5341 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5342 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
5344 return SCTP_DISPOSITION_ABORT
;
5348 * sctp_sf_cookie_echoed_prm_abort
5350 * Section: 4 Note: 3
5355 * The RFC does not explcitly address this issue, but is the route through the
5356 * state table when someone issues an abort while in COOKIE_ECHOED state.
5361 enum sctp_disposition
sctp_sf_cookie_echoed_prm_abort(
5363 const struct sctp_endpoint
*ep
,
5364 const struct sctp_association
*asoc
,
5365 const union sctp_subtype type
,
5367 struct sctp_cmd_seq
*commands
)
5369 /* There is a single T1 timer, so we should be able to use
5370 * common function with the COOKIE-WAIT state.
5372 return sctp_sf_cookie_wait_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5376 * sctp_sf_shutdown_pending_prm_abort
5381 * The RFC does not explicitly address this issue, but is the route through the
5382 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
5387 enum sctp_disposition
sctp_sf_shutdown_pending_prm_abort(
5389 const struct sctp_endpoint
*ep
,
5390 const struct sctp_association
*asoc
,
5391 const union sctp_subtype type
,
5393 struct sctp_cmd_seq
*commands
)
5395 /* Stop the T5-shutdown guard timer. */
5396 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5397 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5399 return sctp_sf_do_9_1_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5403 * sctp_sf_shutdown_sent_prm_abort
5408 * The RFC does not explicitly address this issue, but is the route through the
5409 * state table when someone issues an abort while in SHUTDOWN-SENT state.
5414 enum sctp_disposition
sctp_sf_shutdown_sent_prm_abort(
5416 const struct sctp_endpoint
*ep
,
5417 const struct sctp_association
*asoc
,
5418 const union sctp_subtype type
,
5420 struct sctp_cmd_seq
*commands
)
5422 /* Stop the T2-shutdown timer. */
5423 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5424 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5426 /* Stop the T5-shutdown guard timer. */
5427 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5428 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5430 return sctp_sf_do_9_1_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5434 * sctp_sf_cookie_echoed_prm_abort
5439 * The RFC does not explcitly address this issue, but is the route through the
5440 * state table when someone issues an abort while in COOKIE_ECHOED state.
5445 enum sctp_disposition
sctp_sf_shutdown_ack_sent_prm_abort(
5447 const struct sctp_endpoint
*ep
,
5448 const struct sctp_association
*asoc
,
5449 const union sctp_subtype type
,
5451 struct sctp_cmd_seq
*commands
)
5453 /* The same T2 timer, so we should be able to use
5454 * common function with the SHUTDOWN-SENT state.
5456 return sctp_sf_shutdown_sent_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5460 * Process the REQUESTHEARTBEAT primitive
5463 * J) Request Heartbeat
5465 * Format: REQUESTHEARTBEAT(association id, destination transport address)
5469 * Instructs the local endpoint to perform a HeartBeat on the specified
5470 * destination transport address of the given association. The returned
5471 * result should indicate whether the transmission of the HEARTBEAT
5472 * chunk to the destination address is successful.
5474 * Mandatory attributes:
5476 * o association id - local handle to the SCTP association
5478 * o destination transport address - the transport address of the
5479 * association on which a heartbeat should be issued.
5481 enum sctp_disposition
sctp_sf_do_prm_requestheartbeat(
5483 const struct sctp_endpoint
*ep
,
5484 const struct sctp_association
*asoc
,
5485 const union sctp_subtype type
,
5487 struct sctp_cmd_seq
*commands
)
5489 if (SCTP_DISPOSITION_NOMEM
== sctp_sf_heartbeat(ep
, asoc
, type
,
5490 (struct sctp_transport
*)arg
, commands
))
5491 return SCTP_DISPOSITION_NOMEM
;
5494 * RFC 2960 (bis), section 8.3
5496 * D) Request an on-demand HEARTBEAT on a specific destination
5497 * transport address of a given association.
5499 * The endpoint should increment the respective error counter of
5500 * the destination transport address each time a HEARTBEAT is sent
5501 * to that address and not acknowledged within one RTO.
5504 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
5505 SCTP_TRANSPORT(arg
));
5506 return SCTP_DISPOSITION_CONSUME
;
5510 * ADDIP Section 4.1 ASCONF Chunk Procedures
5511 * When an endpoint has an ASCONF signaled change to be sent to the
5512 * remote endpoint it should do A1 to A9
5514 enum sctp_disposition
sctp_sf_do_prm_asconf(struct net
*net
,
5515 const struct sctp_endpoint
*ep
,
5516 const struct sctp_association
*asoc
,
5517 const union sctp_subtype type
,
5519 struct sctp_cmd_seq
*commands
)
5521 struct sctp_chunk
*chunk
= arg
;
5523 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5524 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5525 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5526 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
5527 return SCTP_DISPOSITION_CONSUME
;
5530 /* RE-CONFIG Section 5.1 RECONF Chunk Procedures */
5531 enum sctp_disposition
sctp_sf_do_prm_reconf(struct net
*net
,
5532 const struct sctp_endpoint
*ep
,
5533 const struct sctp_association
*asoc
,
5534 const union sctp_subtype type
,
5536 struct sctp_cmd_seq
*commands
)
5538 struct sctp_chunk
*chunk
= arg
;
5540 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
5541 return SCTP_DISPOSITION_CONSUME
;
5545 * Ignore the primitive event
5547 * The return value is the disposition of the primitive.
5549 enum sctp_disposition
sctp_sf_ignore_primitive(
5551 const struct sctp_endpoint
*ep
,
5552 const struct sctp_association
*asoc
,
5553 const union sctp_subtype type
,
5555 struct sctp_cmd_seq
*commands
)
5557 pr_debug("%s: primitive type:%d is ignored\n", __func__
,
5560 return SCTP_DISPOSITION_DISCARD
;
5563 /***************************************************************************
5564 * These are the state functions for the OTHER events.
5565 ***************************************************************************/
5568 * When the SCTP stack has no more user data to send or retransmit, this
5569 * notification is given to the user. Also, at the time when a user app
5570 * subscribes to this event, if there is no data to be sent or
5571 * retransmit, the stack will immediately send up this notification.
5573 enum sctp_disposition
sctp_sf_do_no_pending_tsn(
5575 const struct sctp_endpoint
*ep
,
5576 const struct sctp_association
*asoc
,
5577 const union sctp_subtype type
,
5579 struct sctp_cmd_seq
*commands
)
5581 struct sctp_ulpevent
*event
;
5583 event
= sctp_ulpevent_make_sender_dry_event(asoc
, GFP_ATOMIC
);
5585 return SCTP_DISPOSITION_NOMEM
;
5587 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(event
));
5589 return SCTP_DISPOSITION_CONSUME
;
5593 * Start the shutdown negotiation.
5596 * Once all its outstanding data has been acknowledged, the endpoint
5597 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
5598 * TSN Ack field the last sequential TSN it has received from the peer.
5599 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
5600 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
5601 * with the updated last sequential TSN received from its peer.
5603 * The return value is the disposition.
5605 enum sctp_disposition
sctp_sf_do_9_2_start_shutdown(
5607 const struct sctp_endpoint
*ep
,
5608 const struct sctp_association
*asoc
,
5609 const union sctp_subtype type
,
5611 struct sctp_cmd_seq
*commands
)
5613 struct sctp_chunk
*reply
;
5615 /* Once all its outstanding data has been acknowledged, the
5616 * endpoint shall send a SHUTDOWN chunk to its peer including
5617 * in the Cumulative TSN Ack field the last sequential TSN it
5618 * has received from the peer.
5620 reply
= sctp_make_shutdown(asoc
, arg
);
5624 /* Set the transport for the SHUTDOWN chunk and the timeout for the
5625 * T2-shutdown timer.
5627 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5629 /* It shall then start the T2-shutdown timer */
5630 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5631 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5633 /* RFC 4960 Section 9.2
5634 * The sender of the SHUTDOWN MAY also start an overall guard timer
5635 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5637 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5638 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5640 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
5641 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5642 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5644 /* and enter the SHUTDOWN-SENT state. */
5645 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5646 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT
));
5648 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5650 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5653 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5655 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5657 return SCTP_DISPOSITION_CONSUME
;
5660 return SCTP_DISPOSITION_NOMEM
;
5664 * Generate a SHUTDOWN ACK now that everything is SACK'd.
5668 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5669 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
5670 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
5671 * endpoint must re-send the SHUTDOWN ACK.
5673 * The return value is the disposition.
5675 enum sctp_disposition
sctp_sf_do_9_2_shutdown_ack(
5677 const struct sctp_endpoint
*ep
,
5678 const struct sctp_association
*asoc
,
5679 const union sctp_subtype type
,
5681 struct sctp_cmd_seq
*commands
)
5683 struct sctp_chunk
*chunk
= arg
;
5684 struct sctp_chunk
*reply
;
5686 /* There are 2 ways of getting here:
5687 * 1) called in response to a SHUTDOWN chunk
5688 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
5690 * For the case (2), the arg parameter is set to NULL. We need
5691 * to check that we have a chunk before accessing it's fields.
5694 if (!sctp_vtag_verify(chunk
, asoc
))
5695 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
,
5698 /* Make sure that the SHUTDOWN chunk has a valid length. */
5699 if (!sctp_chunk_length_valid(
5700 chunk
, sizeof(struct sctp_shutdown_chunk
)))
5701 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
,
5705 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5706 * shall send a SHUTDOWN ACK ...
5708 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
5712 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
5713 * the T2-shutdown timer.
5715 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5717 /* and start/restart a T2-shutdown timer of its own, */
5718 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5719 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5721 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
5722 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5723 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5725 /* Enter the SHUTDOWN-ACK-SENT state. */
5726 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5727 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT
));
5729 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5731 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5734 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5736 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5738 return SCTP_DISPOSITION_CONSUME
;
5741 return SCTP_DISPOSITION_NOMEM
;
5745 * Ignore the event defined as other
5747 * The return value is the disposition of the event.
5749 enum sctp_disposition
sctp_sf_ignore_other(struct net
*net
,
5750 const struct sctp_endpoint
*ep
,
5751 const struct sctp_association
*asoc
,
5752 const union sctp_subtype type
,
5754 struct sctp_cmd_seq
*commands
)
5756 pr_debug("%s: the event other type:%d is ignored\n",
5757 __func__
, type
.other
);
5759 return SCTP_DISPOSITION_DISCARD
;
5762 /************************************************************
5763 * These are the state functions for handling timeout events.
5764 ************************************************************/
5769 * Section: 6.3.3 Handle T3-rtx Expiration
5771 * Whenever the retransmission timer T3-rtx expires for a destination
5772 * address, do the following:
5775 * The return value is the disposition of the chunk.
5777 enum sctp_disposition
sctp_sf_do_6_3_3_rtx(struct net
*net
,
5778 const struct sctp_endpoint
*ep
,
5779 const struct sctp_association
*asoc
,
5780 const union sctp_subtype type
,
5782 struct sctp_cmd_seq
*commands
)
5784 struct sctp_transport
*transport
= arg
;
5786 SCTP_INC_STATS(net
, SCTP_MIB_T3_RTX_EXPIREDS
);
5788 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5789 if (asoc
->peer
.zero_window_announced
&&
5790 asoc
->state
== SCTP_STATE_SHUTDOWN_PENDING
) {
5792 * We are here likely because the receiver had its rwnd
5793 * closed for a while and we have not been able to
5794 * transmit the locally queued data within the maximum
5795 * retransmission attempts limit. Start the T5
5796 * shutdown guard timer to give the receiver one last
5797 * chance and some additional time to recover before
5800 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START_ONCE
,
5801 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5803 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5804 SCTP_ERROR(ETIMEDOUT
));
5805 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5806 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5807 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5808 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5809 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5810 return SCTP_DISPOSITION_DELETE_TCB
;
5814 /* E1) For the destination address for which the timer
5815 * expires, adjust its ssthresh with rules defined in Section
5816 * 7.2.3 and set the cwnd <- MTU.
5819 /* E2) For the destination address for which the timer
5820 * expires, set RTO <- RTO * 2 ("back off the timer"). The
5821 * maximum value discussed in rule C7 above (RTO.max) may be
5822 * used to provide an upper bound to this doubling operation.
5825 /* E3) Determine how many of the earliest (i.e., lowest TSN)
5826 * outstanding DATA chunks for the address for which the
5827 * T3-rtx has expired will fit into a single packet, subject
5828 * to the MTU constraint for the path corresponding to the
5829 * destination transport address to which the retransmission
5830 * is being sent (this may be different from the address for
5831 * which the timer expires [see Section 6.4]). Call this
5832 * value K. Bundle and retransmit those K DATA chunks in a
5833 * single packet to the destination endpoint.
5835 * Note: Any DATA chunks that were sent to the address for
5836 * which the T3-rtx timer expired but did not fit in one MTU
5837 * (rule E3 above), should be marked for retransmission and
5838 * sent as soon as cwnd allows (normally when a SACK arrives).
5841 /* Do some failure management (Section 8.2). */
5842 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
5844 /* NB: Rules E4 and F1 are implicit in R1. */
5845 sctp_add_cmd_sf(commands
, SCTP_CMD_RETRAN
, SCTP_TRANSPORT(transport
));
5847 return SCTP_DISPOSITION_CONSUME
;
5851 * Generate delayed SACK on timeout
5853 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
5855 * The guidelines on delayed acknowledgement algorithm specified in
5856 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
5857 * acknowledgement SHOULD be generated for at least every second packet
5858 * (not every second DATA chunk) received, and SHOULD be generated
5859 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
5860 * some situations it may be beneficial for an SCTP transmitter to be
5861 * more conservative than the algorithms detailed in this document
5862 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
5863 * the following algorithms allow.
5865 enum sctp_disposition
sctp_sf_do_6_2_sack(struct net
*net
,
5866 const struct sctp_endpoint
*ep
,
5867 const struct sctp_association
*asoc
,
5868 const union sctp_subtype type
,
5870 struct sctp_cmd_seq
*commands
)
5872 SCTP_INC_STATS(net
, SCTP_MIB_DELAY_SACK_EXPIREDS
);
5873 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
5874 return SCTP_DISPOSITION_CONSUME
;
5878 * sctp_sf_t1_init_timer_expire
5880 * Section: 4 Note: 2
5885 * RFC 2960 Section 4 Notes
5886 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
5887 * and re-start the T1-init timer without changing state. This MUST
5888 * be repeated up to 'Max.Init.Retransmits' times. After that, the
5889 * endpoint MUST abort the initialization process and report the
5890 * error to SCTP user.
5896 enum sctp_disposition
sctp_sf_t1_init_timer_expire(
5898 const struct sctp_endpoint
*ep
,
5899 const struct sctp_association
*asoc
,
5900 const union sctp_subtype type
,
5902 struct sctp_cmd_seq
*commands
)
5904 int attempts
= asoc
->init_err_counter
+ 1;
5905 struct sctp_chunk
*repl
= NULL
;
5906 struct sctp_bind_addr
*bp
;
5908 pr_debug("%s: timer T1 expired (INIT)\n", __func__
);
5910 SCTP_INC_STATS(net
, SCTP_MIB_T1_INIT_EXPIREDS
);
5912 if (attempts
<= asoc
->max_init_attempts
) {
5913 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
5914 repl
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, 0);
5916 return SCTP_DISPOSITION_NOMEM
;
5918 /* Choose transport for INIT. */
5919 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5922 /* Issue a sideeffect to do the needed accounting. */
5923 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_RESTART
,
5924 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5926 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5928 pr_debug("%s: giving up on INIT, attempts:%d "
5929 "max_init_attempts:%d\n", __func__
, attempts
,
5930 asoc
->max_init_attempts
);
5932 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5933 SCTP_ERROR(ETIMEDOUT
));
5934 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5935 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5936 return SCTP_DISPOSITION_DELETE_TCB
;
5939 return SCTP_DISPOSITION_CONSUME
;
5943 * sctp_sf_t1_cookie_timer_expire
5945 * Section: 4 Note: 2
5950 * RFC 2960 Section 4 Notes
5951 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
5952 * COOKIE ECHO and re-start the T1-cookie timer without changing
5953 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
5954 * After that, the endpoint MUST abort the initialization process and
5955 * report the error to SCTP user.
5961 enum sctp_disposition
sctp_sf_t1_cookie_timer_expire(
5963 const struct sctp_endpoint
*ep
,
5964 const struct sctp_association
*asoc
,
5965 const union sctp_subtype type
,
5967 struct sctp_cmd_seq
*commands
)
5969 int attempts
= asoc
->init_err_counter
+ 1;
5970 struct sctp_chunk
*repl
= NULL
;
5972 pr_debug("%s: timer T1 expired (COOKIE-ECHO)\n", __func__
);
5974 SCTP_INC_STATS(net
, SCTP_MIB_T1_COOKIE_EXPIREDS
);
5976 if (attempts
<= asoc
->max_init_attempts
) {
5977 repl
= sctp_make_cookie_echo(asoc
, NULL
);
5979 return SCTP_DISPOSITION_NOMEM
;
5981 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5983 /* Issue a sideeffect to do the needed accounting. */
5984 sctp_add_cmd_sf(commands
, SCTP_CMD_COOKIEECHO_RESTART
,
5985 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
5987 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5989 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5990 SCTP_ERROR(ETIMEDOUT
));
5991 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5992 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5993 return SCTP_DISPOSITION_DELETE_TCB
;
5996 return SCTP_DISPOSITION_CONSUME
;
5999 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
6000 * with the updated last sequential TSN received from its peer.
6002 * An endpoint should limit the number of retransmission of the
6003 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
6004 * If this threshold is exceeded the endpoint should destroy the TCB and
6005 * MUST report the peer endpoint unreachable to the upper layer (and
6006 * thus the association enters the CLOSED state). The reception of any
6007 * packet from its peer (i.e. as the peer sends all of its queued DATA
6008 * chunks) should clear the endpoint's retransmission count and restart
6009 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
6010 * all of its queued DATA chunks that have not yet been sent.
6012 enum sctp_disposition
sctp_sf_t2_timer_expire(
6014 const struct sctp_endpoint
*ep
,
6015 const struct sctp_association
*asoc
,
6016 const union sctp_subtype type
,
6018 struct sctp_cmd_seq
*commands
)
6020 struct sctp_chunk
*reply
= NULL
;
6022 pr_debug("%s: timer T2 expired\n", __func__
);
6024 SCTP_INC_STATS(net
, SCTP_MIB_T2_SHUTDOWN_EXPIREDS
);
6026 ((struct sctp_association
*)asoc
)->shutdown_retries
++;
6028 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
6029 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
6030 SCTP_ERROR(ETIMEDOUT
));
6031 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
6032 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
6033 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
6034 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
6035 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
6036 return SCTP_DISPOSITION_DELETE_TCB
;
6039 switch (asoc
->state
) {
6040 case SCTP_STATE_SHUTDOWN_SENT
:
6041 reply
= sctp_make_shutdown(asoc
, NULL
);
6044 case SCTP_STATE_SHUTDOWN_ACK_SENT
:
6045 reply
= sctp_make_shutdown_ack(asoc
, NULL
);
6056 /* Do some failure management (Section 8.2).
6057 * If we remove the transport an SHUTDOWN was last sent to, don't
6058 * do failure management.
6060 if (asoc
->shutdown_last_sent_to
)
6061 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
6062 SCTP_TRANSPORT(asoc
->shutdown_last_sent_to
));
6064 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
6065 * the T2-shutdown timer.
6067 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
6069 /* Restart the T2-shutdown timer. */
6070 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
6071 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
6072 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
6073 return SCTP_DISPOSITION_CONSUME
;
6076 return SCTP_DISPOSITION_NOMEM
;
6080 * ADDIP Section 4.1 ASCONF Chunk Procedures
6081 * If the T4 RTO timer expires the endpoint should do B1 to B5
6083 enum sctp_disposition
sctp_sf_t4_timer_expire(
6085 const struct sctp_endpoint
*ep
,
6086 const struct sctp_association
*asoc
,
6087 const union sctp_subtype type
,
6089 struct sctp_cmd_seq
*commands
)
6091 struct sctp_chunk
*chunk
= asoc
->addip_last_asconf
;
6092 struct sctp_transport
*transport
= chunk
->transport
;
6094 SCTP_INC_STATS(net
, SCTP_MIB_T4_RTO_EXPIREDS
);
6096 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
6097 * detection on the appropriate destination address as defined in
6098 * RFC2960 [5] section 8.1 and 8.2.
6101 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
6102 SCTP_TRANSPORT(transport
));
6104 /* Reconfig T4 timer and transport. */
6105 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
6107 /* ADDIP 4.1 B2) Increment the association error counters and perform
6108 * endpoint failure detection on the association as defined in
6109 * RFC2960 [5] section 8.1 and 8.2.
6110 * association error counter is incremented in SCTP_CMD_STRIKE.
6112 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
6113 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
6114 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
6115 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
6116 SCTP_ERROR(ETIMEDOUT
));
6117 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
6118 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
6119 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
6120 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
6121 return SCTP_DISPOSITION_ABORT
;
6124 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
6125 * the ASCONF chunk was sent by doubling the RTO timer value.
6126 * This is done in SCTP_CMD_STRIKE.
6129 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
6130 * choose an alternate destination address (please refer to RFC2960
6131 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
6132 * chunk, it MUST be the same (including its serial number) as the last
6135 sctp_chunk_hold(asoc
->addip_last_asconf
);
6136 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6137 SCTP_CHUNK(asoc
->addip_last_asconf
));
6139 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
6140 * destination is selected, then the RTO used will be that of the new
6141 * destination address.
6143 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
6144 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
6146 return SCTP_DISPOSITION_CONSUME
;
6149 /* sctpimpguide-05 Section 2.12.2
6150 * The sender of the SHUTDOWN MAY also start an overall guard timer
6151 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
6152 * At the expiration of this timer the sender SHOULD abort the association
6153 * by sending an ABORT chunk.
6155 enum sctp_disposition
sctp_sf_t5_timer_expire(
6157 const struct sctp_endpoint
*ep
,
6158 const struct sctp_association
*asoc
,
6159 const union sctp_subtype type
,
6161 struct sctp_cmd_seq
*commands
)
6163 struct sctp_chunk
*reply
= NULL
;
6165 pr_debug("%s: timer T5 expired\n", __func__
);
6167 SCTP_INC_STATS(net
, SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS
);
6169 reply
= sctp_make_abort(asoc
, NULL
, 0);
6173 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
6174 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
6175 SCTP_ERROR(ETIMEDOUT
));
6176 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
6177 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
6179 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
6180 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
6182 return SCTP_DISPOSITION_DELETE_TCB
;
6184 return SCTP_DISPOSITION_NOMEM
;
6187 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
6188 * the association is automatically closed by starting the shutdown process.
6189 * The work that needs to be done is same as when SHUTDOWN is initiated by
6190 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
6192 enum sctp_disposition
sctp_sf_autoclose_timer_expire(
6194 const struct sctp_endpoint
*ep
,
6195 const struct sctp_association
*asoc
,
6196 const union sctp_subtype type
,
6198 struct sctp_cmd_seq
*commands
)
6200 enum sctp_disposition disposition
;
6202 SCTP_INC_STATS(net
, SCTP_MIB_AUTOCLOSE_EXPIREDS
);
6204 /* From 9.2 Shutdown of an Association
6205 * Upon receipt of the SHUTDOWN primitive from its upper
6206 * layer, the endpoint enters SHUTDOWN-PENDING state and
6207 * remains there until all outstanding data has been
6208 * acknowledged by its peer. The endpoint accepts no new data
6209 * from its upper layer, but retransmits data to the far end
6210 * if necessary to fill gaps.
6212 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
6213 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
6215 disposition
= SCTP_DISPOSITION_CONSUME
;
6216 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
6217 disposition
= sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
, type
,
6224 /*****************************************************************************
6225 * These are sa state functions which could apply to all types of events.
6226 ****************************************************************************/
6229 * This table entry is not implemented.
6232 * (endpoint, asoc, chunk)
6234 * The return value is the disposition of the chunk.
6236 enum sctp_disposition
sctp_sf_not_impl(struct net
*net
,
6237 const struct sctp_endpoint
*ep
,
6238 const struct sctp_association
*asoc
,
6239 const union sctp_subtype type
,
6240 void *arg
, struct sctp_cmd_seq
*commands
)
6242 return SCTP_DISPOSITION_NOT_IMPL
;
6246 * This table entry represents a bug.
6249 * (endpoint, asoc, chunk)
6251 * The return value is the disposition of the chunk.
6253 enum sctp_disposition
sctp_sf_bug(struct net
*net
,
6254 const struct sctp_endpoint
*ep
,
6255 const struct sctp_association
*asoc
,
6256 const union sctp_subtype type
,
6257 void *arg
, struct sctp_cmd_seq
*commands
)
6259 return SCTP_DISPOSITION_BUG
;
6263 * This table entry represents the firing of a timer in the wrong state.
6264 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
6265 * when the association is in the wrong state. This event should
6266 * be ignored, so as to prevent any rearming of the timer.
6269 * (endpoint, asoc, chunk)
6271 * The return value is the disposition of the chunk.
6273 enum sctp_disposition
sctp_sf_timer_ignore(struct net
*net
,
6274 const struct sctp_endpoint
*ep
,
6275 const struct sctp_association
*asoc
,
6276 const union sctp_subtype type
,
6278 struct sctp_cmd_seq
*commands
)
6280 pr_debug("%s: timer %d ignored\n", __func__
, type
.chunk
);
6282 return SCTP_DISPOSITION_CONSUME
;
6285 /********************************************************************
6286 * 2nd Level Abstractions
6287 ********************************************************************/
6289 /* Pull the SACK chunk based on the SACK header. */
6290 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
)
6292 struct sctp_sackhdr
*sack
;
6297 /* Protect ourselves from reading too far into
6298 * the skb from a bogus sender.
6300 sack
= (struct sctp_sackhdr
*) chunk
->skb
->data
;
6302 num_blocks
= ntohs(sack
->num_gap_ack_blocks
);
6303 num_dup_tsns
= ntohs(sack
->num_dup_tsns
);
6304 len
= sizeof(struct sctp_sackhdr
);
6305 len
+= (num_blocks
+ num_dup_tsns
) * sizeof(__u32
);
6306 if (len
> chunk
->skb
->len
)
6309 skb_pull(chunk
->skb
, len
);
6314 /* Create an ABORT packet to be sent as a response, with the specified
6317 static struct sctp_packet
*sctp_abort_pkt_new(
6319 const struct sctp_endpoint
*ep
,
6320 const struct sctp_association
*asoc
,
6321 struct sctp_chunk
*chunk
,
6322 const void *payload
, size_t paylen
)
6324 struct sctp_packet
*packet
;
6325 struct sctp_chunk
*abort
;
6327 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
6331 * The T bit will be set if the asoc is NULL.
6333 abort
= sctp_make_abort(asoc
, chunk
, paylen
);
6335 sctp_ootb_pkt_free(packet
);
6339 /* Reflect vtag if T-Bit is set */
6340 if (sctp_test_T_bit(abort
))
6341 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
6343 /* Add specified error causes, i.e., payload, to the
6346 sctp_addto_chunk(abort
, paylen
, payload
);
6348 /* Set the skb to the belonging sock for accounting. */
6349 abort
->skb
->sk
= ep
->base
.sk
;
6351 sctp_packet_append_chunk(packet
, abort
);
6358 /* Allocate a packet for responding in the OOTB conditions. */
6359 static struct sctp_packet
*sctp_ootb_pkt_new(
6361 const struct sctp_association
*asoc
,
6362 const struct sctp_chunk
*chunk
)
6364 struct sctp_transport
*transport
;
6365 struct sctp_packet
*packet
;
6369 /* Get the source and destination port from the inbound packet. */
6370 sport
= ntohs(chunk
->sctp_hdr
->dest
);
6371 dport
= ntohs(chunk
->sctp_hdr
->source
);
6373 /* The V-tag is going to be the same as the inbound packet if no
6374 * association exists, otherwise, use the peer's vtag.
6377 /* Special case the INIT-ACK as there is no peer's vtag
6380 switch (chunk
->chunk_hdr
->type
) {
6382 case SCTP_CID_INIT_ACK
:
6384 struct sctp_initack_chunk
*initack
;
6386 initack
= (struct sctp_initack_chunk
*)chunk
->chunk_hdr
;
6387 vtag
= ntohl(initack
->init_hdr
.init_tag
);
6391 vtag
= asoc
->peer
.i
.init_tag
;
6395 /* Special case the INIT and stale COOKIE_ECHO as there is no
6398 switch (chunk
->chunk_hdr
->type
) {
6401 struct sctp_init_chunk
*init
;
6403 init
= (struct sctp_init_chunk
*)chunk
->chunk_hdr
;
6404 vtag
= ntohl(init
->init_hdr
.init_tag
);
6408 vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
6413 /* Make a transport for the bucket, Eliza... */
6414 transport
= sctp_transport_new(net
, sctp_source(chunk
), GFP_ATOMIC
);
6418 transport
->encap_port
= SCTP_INPUT_CB(chunk
->skb
)->encap_port
;
6420 /* Cache a route for the transport with the chunk's destination as
6421 * the source address.
6423 sctp_transport_route(transport
, (union sctp_addr
*)&chunk
->dest
,
6424 sctp_sk(net
->sctp
.ctl_sock
));
6426 packet
= &transport
->packet
;
6427 sctp_packet_init(packet
, transport
, sport
, dport
);
6428 sctp_packet_config(packet
, vtag
, 0);
6436 /* Free the packet allocated earlier for responding in the OOTB condition. */
6437 void sctp_ootb_pkt_free(struct sctp_packet
*packet
)
6439 sctp_transport_free(packet
->transport
);
6442 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
6443 static void sctp_send_stale_cookie_err(struct net
*net
,
6444 const struct sctp_endpoint
*ep
,
6445 const struct sctp_association
*asoc
,
6446 const struct sctp_chunk
*chunk
,
6447 struct sctp_cmd_seq
*commands
,
6448 struct sctp_chunk
*err_chunk
)
6450 struct sctp_packet
*packet
;
6453 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
6455 struct sctp_signed_cookie
*cookie
;
6457 /* Override the OOTB vtag from the cookie. */
6458 cookie
= chunk
->subh
.cookie_hdr
;
6459 packet
->vtag
= cookie
->c
.peer_vtag
;
6461 /* Set the skb to the belonging sock for accounting. */
6462 err_chunk
->skb
->sk
= ep
->base
.sk
;
6463 sctp_packet_append_chunk(packet
, err_chunk
);
6464 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
6465 SCTP_PACKET(packet
));
6466 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
6468 sctp_chunk_free (err_chunk
);
6473 /* Process a data chunk */
6474 static int sctp_eat_data(const struct sctp_association
*asoc
,
6475 struct sctp_chunk
*chunk
,
6476 struct sctp_cmd_seq
*commands
)
6478 struct sctp_tsnmap
*map
= (struct sctp_tsnmap
*)&asoc
->peer
.tsn_map
;
6479 struct sock
*sk
= asoc
->base
.sk
;
6480 struct net
*net
= sock_net(sk
);
6481 struct sctp_datahdr
*data_hdr
;
6482 struct sctp_chunk
*err
;
6483 enum sctp_verb deliver
;
6488 data_hdr
= (struct sctp_datahdr
*)chunk
->skb
->data
;
6489 chunk
->subh
.data_hdr
= data_hdr
;
6490 skb_pull(chunk
->skb
, sctp_datahdr_len(&asoc
->stream
));
6492 tsn
= ntohl(data_hdr
->tsn
);
6493 pr_debug("%s: TSN 0x%x\n", __func__
, tsn
);
6495 /* ASSERT: Now skb->data is really the user data. */
6497 /* Process ECN based congestion.
6499 * Since the chunk structure is reused for all chunks within
6500 * a packet, we use ecn_ce_done to track if we've already
6501 * done CE processing for this packet.
6503 * We need to do ECN processing even if we plan to discard the
6507 if (asoc
->peer
.ecn_capable
&& !chunk
->ecn_ce_done
) {
6508 struct sctp_af
*af
= SCTP_INPUT_CB(chunk
->skb
)->af
;
6509 chunk
->ecn_ce_done
= 1;
6511 if (af
->is_ce(sctp_gso_headskb(chunk
->skb
))) {
6512 /* Do real work as side effect. */
6513 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_CE
,
6518 tmp
= sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
);
6520 /* The TSN is too high--silently discard the chunk and
6521 * count on it getting retransmitted later.
6524 chunk
->asoc
->stats
.outofseqtsns
++;
6525 return SCTP_IERROR_HIGH_TSN
;
6526 } else if (tmp
> 0) {
6527 /* This is a duplicate. Record it. */
6528 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_DUP
, SCTP_U32(tsn
));
6529 return SCTP_IERROR_DUP_TSN
;
6532 /* This is a new TSN. */
6534 /* Discard if there is no room in the receive window.
6535 * Actually, allow a little bit of overflow (up to a MTU).
6537 datalen
= ntohs(chunk
->chunk_hdr
->length
);
6538 datalen
-= sctp_datachk_len(&asoc
->stream
);
6540 deliver
= SCTP_CMD_CHUNK_ULP
;
6542 /* Think about partial delivery. */
6543 if ((datalen
>= asoc
->rwnd
) && (!asoc
->ulpq
.pd_mode
)) {
6545 /* Even if we don't accept this chunk there is
6548 sctp_add_cmd_sf(commands
, SCTP_CMD_PART_DELIVER
, SCTP_NULL());
6551 /* Spill over rwnd a little bit. Note: While allowed, this spill over
6552 * seems a bit troublesome in that frag_point varies based on
6553 * PMTU. In cases, such as loopback, this might be a rather
6556 if ((!chunk
->data_accepted
) && (!asoc
->rwnd
|| asoc
->rwnd_over
||
6557 (datalen
> asoc
->rwnd
+ asoc
->frag_point
))) {
6559 /* If this is the next TSN, consider reneging to make
6560 * room. Note: Playing nice with a confused sender. A
6561 * malicious sender can still eat up all our buffer
6562 * space and in the future we may want to detect and
6563 * do more drastic reneging.
6565 if (sctp_tsnmap_has_gap(map
) &&
6566 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
6567 pr_debug("%s: reneging for tsn:%u\n", __func__
, tsn
);
6568 deliver
= SCTP_CMD_RENEGE
;
6570 pr_debug("%s: discard tsn:%u len:%zu, rwnd:%d\n",
6571 __func__
, tsn
, datalen
, asoc
->rwnd
);
6573 return SCTP_IERROR_IGNORE_TSN
;
6578 * Also try to renege to limit our memory usage in the event that
6579 * we are under memory pressure
6580 * If we can't renege, don't worry about it, the sk_rmem_schedule
6581 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
6582 * memory usage too much
6584 if (sk_under_memory_pressure(sk
)) {
6585 if (sctp_tsnmap_has_gap(map
) &&
6586 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
6587 pr_debug("%s: under pressure, reneging for tsn:%u\n",
6589 deliver
= SCTP_CMD_RENEGE
;
6596 * Section 3.3.10.9 No User Data (9)
6600 * No User Data: This error cause is returned to the originator of a
6601 * DATA chunk if a received DATA chunk has no user data.
6603 if (unlikely(0 == datalen
)) {
6604 err
= sctp_make_abort_no_data(asoc
, chunk
, tsn
);
6606 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6609 /* We are going to ABORT, so we might as well stop
6610 * processing the rest of the chunks in the packet.
6612 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
6613 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
6614 SCTP_ERROR(ECONNABORTED
));
6615 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
6616 SCTP_PERR(SCTP_ERROR_NO_DATA
));
6617 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
6618 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
6619 return SCTP_IERROR_NO_DATA
;
6622 chunk
->data_accepted
= 1;
6624 /* Note: Some chunks may get overcounted (if we drop) or overcounted
6625 * if we renege and the chunk arrives again.
6627 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_UNORDERED
) {
6628 SCTP_INC_STATS(net
, SCTP_MIB_INUNORDERCHUNKS
);
6630 chunk
->asoc
->stats
.iuodchunks
++;
6632 SCTP_INC_STATS(net
, SCTP_MIB_INORDERCHUNKS
);
6634 chunk
->asoc
->stats
.iodchunks
++;
6637 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
6639 * If an endpoint receive a DATA chunk with an invalid stream
6640 * identifier, it shall acknowledge the reception of the DATA chunk
6641 * following the normal procedure, immediately send an ERROR chunk
6642 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
6643 * and discard the DATA chunk.
6645 if (ntohs(data_hdr
->stream
) >= asoc
->stream
.incnt
) {
6646 /* Mark tsn as received even though we drop it */
6647 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_TSN
, SCTP_U32(tsn
));
6649 err
= sctp_make_op_error(asoc
, chunk
, SCTP_ERROR_INV_STRM
,
6651 sizeof(data_hdr
->stream
),
6654 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6656 return SCTP_IERROR_BAD_STREAM
;
6659 /* Check to see if the SSN is possible for this TSN.
6660 * The biggest gap we can record is 4K wide. Since SSNs wrap
6661 * at an unsigned short, there is no way that an SSN can
6662 * wrap and for a valid TSN. We can simply check if the current
6663 * SSN is smaller then the next expected one. If it is, it wrapped
6666 if (!asoc
->stream
.si
->validate_data(chunk
))
6667 return SCTP_IERROR_PROTO_VIOLATION
;
6669 /* Send the data up to the user. Note: Schedule the
6670 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
6671 * chunk needs the updated rwnd.
6673 sctp_add_cmd_sf(commands
, deliver
, SCTP_CHUNK(chunk
));
6675 return SCTP_IERROR_NO_ERROR
;