Merge with Linux 2.5.59.
[linux-2.6/linux-mips.git] / net / sctp / sm_statefuns.c
blob0ef43f61a9c89cc81076f4f7095812fcbc7cdc27
1 /* SCTP kernel reference Implementation
2 * Copyright (c) 1999-2000 Cisco, Inc.
3 * Copyright (c) 1999-2001 Motorola, Inc.
4 * Copyright (c) 2001-2002 International Business Machines, Corp.
5 * Copyright (c) 2001-2002 Intel Corp.
6 * Copyright (c) 2002 Nokia Corp.
8 * This file is part of the SCTP kernel reference Implementation
10 * This is part of the SCTP Linux Kernel Reference Implementation.
12 * These are the state functions for the state machine.
14 * The SCTP reference implementation is free software;
15 * you can redistribute it and/or modify it under the terms of
16 * the GNU General Public License as published by
17 * the Free Software Foundation; either version 2, or (at your option)
18 * any later version.
20 * The SCTP reference implementation is distributed in the hope that it
21 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
22 * ************************
23 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 * See the GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with GNU CC; see the file COPYING. If not, write to
28 * the Free Software Foundation, 59 Temple Place - Suite 330,
29 * Boston, MA 02111-1307, USA.
31 * Please send any bug reports or fixes you make to the
32 * email address(es):
33 * lksctp developers <lksctp-developers@lists.sourceforge.net>
35 * Or submit a bug report through the following website:
36 * http://www.sf.net/projects/lksctp
38 * Written or modified by:
39 * La Monte H.P. Yarroll <piggy@acm.org>
40 * Karl Knutson <karl@athena.chicago.il.us>
41 * Mathew Kotowsky <kotowsky@sctp.org>
42 * Sridhar Samudrala <samudrala@us.ibm.com>
43 * Jon Grimm <jgrimm@us.ibm.com>
44 * Hui Huang <hui.huang@nokia.com>
45 * Dajiang Zhang <dajiang.zhang@nokia.com>
46 * Daisy Chang <daisyc@us.ibm.com>
47 * Ardelle Fan <ardelle.fan@intel.com>
49 * Any bugs reported given to us we will try to fix... any fixes shared will
50 * be incorporated into the next SCTP release.
53 #include <linux/types.h>
54 #include <linux/kernel.h>
55 #include <linux/ip.h>
56 #include <linux/ipv6.h>
57 #include <linux/net.h>
58 #include <linux/inet.h>
59 #include <net/sock.h>
60 #include <net/inet_ecn.h>
61 #include <linux/skbuff.h>
62 #include <net/sctp/sctp.h>
63 #include <net/sctp/sm.h>
64 #include <net/sctp/structs.h>
66 /**********************************************************
67 * These are the state functions for handling chunk events.
68 **********************************************************/
71 * Process the final SHUTDOWN COMPLETE.
73 * Section: 4 (C) (diagram), 9.2
74 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
75 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
76 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
77 * should stop the T2-shutdown timer and remove all knowledge of the
78 * association (and thus the association enters the CLOSED state).
80 * Verification Tag: 8.5.1(C)
81 * C) Rules for packet carrying SHUTDOWN COMPLETE:
82 * ...
83 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet if the
84 * Verification Tag field of the packet matches its own tag OR it is
85 * set to its peer's tag and the T bit is set in the Chunk Flags.
86 * Otherwise, the receiver MUST silently discard the packet and take
87 * no further action. An endpoint MUST ignore the SHUTDOWN COMPLETE if
88 * it is not in the SHUTDOWN-ACK-SENT state.
90 * Inputs
91 * (endpoint, asoc, chunk)
93 * Outputs
94 * (asoc, reply_msg, msg_up, timers, counters)
96 * The return value is the disposition of the chunk.
98 sctp_disposition_t sctp_sf_do_4_C(const sctp_endpoint_t *ep,
99 const sctp_association_t *asoc,
100 const sctp_subtype_t type,
101 void *arg,
102 sctp_cmd_seq_t *commands)
104 sctp_chunk_t *chunk = arg;
105 sctp_ulpevent_t *ev;
107 /* RFC 2960 6.10 Bundling
109 * An endpoint MUST NOT bundle INIT, INIT ACK or
110 * SHUTDOWN COMPLETE with any other chunks.
112 if (!chunk->singleton)
113 return SCTP_DISPOSITION_VIOLATION;
115 if (!sctp_vtag_verify_either(chunk, asoc))
116 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
118 /* RFC 2960 10.2 SCTP-to-ULP
120 * H) SHUTDOWN COMPLETE notification
122 * When SCTP completes the shutdown procedures (section 9.2) this
123 * notification is passed to the upper layer.
125 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
126 0, 0, 0, GFP_ATOMIC);
127 if (!ev)
128 goto nomem;
130 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
132 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
133 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
134 * not the chunk should be discarded. If the endpoint is in
135 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
136 * T2-shutdown timer and remove all knowledge of the
137 * association (and thus the association enters the CLOSED
138 * state).
140 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
141 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
143 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
144 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
146 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
147 SCTP_STATE(SCTP_STATE_CLOSED));
149 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
151 return SCTP_DISPOSITION_DELETE_TCB;
153 nomem:
154 return SCTP_DISPOSITION_NOMEM;
158 * Respond to a normal INIT chunk.
159 * We are the side that is being asked for an association.
161 * Section: 5.1 Normal Establishment of an Association, B
162 * B) "Z" shall respond immediately with an INIT ACK chunk. The
163 * destination IP address of the INIT ACK MUST be set to the source
164 * IP address of the INIT to which this INIT ACK is responding. In
165 * the response, besides filling in other parameters, "Z" must set the
166 * Verification Tag field to Tag_A, and also provide its own
167 * Verification Tag (Tag_Z) in the Initiate Tag field.
169 * Verification Tag: No checking.
171 * Inputs
172 * (endpoint, asoc, chunk)
174 * Outputs
175 * (asoc, reply_msg, msg_up, timers, counters)
177 * The return value is the disposition of the chunk.
179 sctp_disposition_t sctp_sf_do_5_1B_init(const sctp_endpoint_t *ep,
180 const sctp_association_t *asoc,
181 const sctp_subtype_t type,
182 void *arg,
183 sctp_cmd_seq_t *commands)
185 sctp_chunk_t *chunk = arg;
186 sctp_chunk_t *repl;
187 sctp_association_t *new_asoc;
188 sctp_chunk_t *err_chunk;
189 sctp_packet_t *packet;
190 sctp_unrecognized_param_t *unk_param;
191 int len;
193 /* If the packet is an OOTB packet which is temporarily on the
194 * control endpoint, responding with an ABORT.
196 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
197 return sctp_sf_ootb(ep, asoc, type, arg, commands);
199 /* 6.10 Bundling
200 * An endpoint MUST NOT bundle INIT, INIT ACK or
201 * SHUTDOWN COMPLETE with any other chunks.
203 if (!chunk->singleton)
204 return SCTP_DISPOSITION_VIOLATION;
206 /* Verify the INIT chunk before processing it. */
207 err_chunk = NULL;
208 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
209 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
210 &err_chunk)) {
211 /* This chunk contains fatal error. It is to be discarded.
212 * Send an ABORT, with causes if there is any.
214 if (err_chunk) {
215 packet = sctp_abort_pkt_new(ep, asoc, arg,
216 (__u8 *)(err_chunk->chunk_hdr) +
217 sizeof(sctp_chunkhdr_t),
218 ntohs(err_chunk->chunk_hdr->length) -
219 sizeof(sctp_chunkhdr_t));
221 sctp_free_chunk(err_chunk);
223 if (packet) {
224 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
225 SCTP_PACKET(packet));
226 return SCTP_DISPOSITION_CONSUME;
227 } else {
228 return SCTP_DISPOSITION_NOMEM;
230 } else {
231 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
232 commands);
236 /* Grab the INIT header. */
237 chunk->subh.init_hdr = (sctp_inithdr_t *)chunk->skb->data;
239 /* Tag the variable length parameters. */
240 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
242 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
243 if (!new_asoc)
244 goto nomem;
246 /* The call, sctp_process_init(), can fail on memory allocation. */
247 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
248 sctp_source(chunk),
249 (sctp_init_chunk_t *)chunk->chunk_hdr,
250 GFP_ATOMIC))
251 goto nomem_init;
253 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
255 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
257 /* If there are errors need to be reported for unknown parameters,
258 * make sure to reserve enough room in the INIT ACK for them.
260 len = 0;
261 if (err_chunk)
262 len = ntohs(err_chunk->chunk_hdr->length) -
263 sizeof(sctp_chunkhdr_t);
265 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
266 if (!repl)
267 goto nomem_ack;
269 /* If there are errors need to be reported for unknown parameters,
270 * include them in the outgoing INIT ACK as "Unrecognized parameter"
271 * parameter.
273 if (err_chunk) {
274 /* Get the "Unrecognized parameter" parameter(s) out of the
275 * ERROR chunk generated by sctp_verify_init(). Since the
276 * error cause code for "unknown parameter" and the
277 * "Unrecognized parameter" type is the same, we can
278 * construct the parameters in INIT ACK by copying the
279 * ERROR causes over.
281 unk_param = (sctp_unrecognized_param_t *)
282 ((__u8 *)(err_chunk->chunk_hdr) +
283 sizeof(sctp_chunkhdr_t));
284 /* Replace the cause code with the "Unrecognized parameter"
285 * parameter type.
287 sctp_addto_chunk(repl, len, unk_param);
288 sctp_free_chunk(err_chunk);
291 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
294 * Note: After sending out INIT ACK with the State Cookie parameter,
295 * "Z" MUST NOT allocate any resources, nor keep any states for the
296 * new association. Otherwise, "Z" will be vulnerable to resource
297 * attacks.
299 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
301 return SCTP_DISPOSITION_DELETE_TCB;
303 nomem_ack:
304 if (err_chunk)
305 sctp_free_chunk(err_chunk);
306 nomem_init:
307 sctp_association_free(new_asoc);
308 nomem:
309 return SCTP_DISPOSITION_NOMEM;
313 * Respond to a normal INIT ACK chunk.
314 * We are the side that is initiating the association.
316 * Section: 5.1 Normal Establishment of an Association, C
317 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
318 * timer and leave COOKIE-WAIT state. "A" shall then send the State
319 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
320 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
322 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
323 * DATA chunks, but it MUST be the first chunk in the packet and
324 * until the COOKIE ACK is returned the sender MUST NOT send any
325 * other packets to the peer.
327 * Verification Tag: 3.3.3
328 * If the value of the Initiate Tag in a received INIT ACK chunk is
329 * found to be 0, the receiver MUST treat it as an error and close the
330 * association by transmitting an ABORT.
332 * Inputs
333 * (endpoint, asoc, chunk)
335 * Outputs
336 * (asoc, reply_msg, msg_up, timers, counters)
338 * The return value is the disposition of the chunk.
340 sctp_disposition_t sctp_sf_do_5_1C_ack(const sctp_endpoint_t *ep,
341 const sctp_association_t *asoc,
342 const sctp_subtype_t type,
343 void *arg,
344 sctp_cmd_seq_t *commands)
346 sctp_chunk_t *chunk = arg;
347 sctp_init_chunk_t *initchunk;
348 __u32 init_tag;
349 sctp_chunk_t *err_chunk;
350 sctp_packet_t *packet;
351 sctp_disposition_t ret;
354 /* 6.10 Bundling
355 * An endpoint MUST NOT bundle INIT, INIT ACK or
356 * SHUTDOWN COMPLETE with any other chunks.
358 if (!chunk->singleton)
359 return SCTP_DISPOSITION_VIOLATION;
361 /* Grab the INIT header. */
362 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
364 init_tag = ntohl(chunk->subh.init_hdr->init_tag);
366 /* Verification Tag: 3.3.3
367 * If the value of the Initiate Tag in a received INIT ACK
368 * chunk is found to be 0, the receiver MUST treat it as an
369 * error and close the association by transmitting an ABORT.
371 if (!init_tag) {
372 sctp_chunk_t *reply = sctp_make_abort(asoc, chunk, 0);
373 if (!reply)
374 goto nomem;
376 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
377 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
378 SCTP_STATE(SCTP_STATE_CLOSED));
379 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
380 return SCTP_DISPOSITION_DELETE_TCB;
383 /* Verify the INIT chunk before processing it. */
384 err_chunk = NULL;
385 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
386 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
387 &err_chunk)) {
388 /* This chunk contains fatal error. It is to be discarded.
389 * Send an ABORT, with causes if there is any.
391 if (err_chunk) {
392 packet = sctp_abort_pkt_new(ep, asoc, arg,
393 (__u8 *)(err_chunk->chunk_hdr) +
394 sizeof(sctp_chunkhdr_t),
395 ntohs(err_chunk->chunk_hdr->length) -
396 sizeof(sctp_chunkhdr_t));
398 sctp_free_chunk(err_chunk);
400 if (packet) {
401 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
402 SCTP_PACKET(packet));
403 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
404 SCTP_STATE(SCTP_STATE_CLOSED));
405 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB,
406 SCTP_NULL());
407 return SCTP_DISPOSITION_CONSUME;
408 } else {
409 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
410 SCTP_STATE(SCTP_STATE_CLOSED));
411 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB,
412 SCTP_NULL());
413 return SCTP_DISPOSITION_NOMEM;
415 } else {
416 ret = sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
417 commands);
418 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
419 SCTP_STATE(SCTP_STATE_CLOSED));
420 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB,
421 SCTP_NULL());
422 return ret;
426 /* Tag the variable length paramters. Note that we never
427 * convert the parameters in an INIT chunk.
429 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
431 initchunk = (sctp_init_chunk_t *) chunk->chunk_hdr;
433 sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT,
434 SCTP_PEER_INIT(initchunk));
436 /* 5.1 C) "A" shall stop the T1-init timer and leave
437 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
438 * timer, and enter the COOKIE-ECHOED state.
440 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
441 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
442 sctp_add_cmd_sf(commands, SCTP_CMD_COUNTER_RESET,
443 SCTP_COUNTER(SCTP_COUNTER_INIT_ERROR));
444 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
445 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
446 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
447 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED));
449 /* 5.1 C) "A" shall then send the State Cookie received in the
450 * INIT ACK chunk in a COOKIE ECHO chunk, ...
452 /* If there is any errors to report, send the ERROR chunk generated
453 * for unknown parameters as well.
455 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO,
456 SCTP_CHUNK(err_chunk));
458 return SCTP_DISPOSITION_CONSUME;
460 nomem:
461 return SCTP_DISPOSITION_NOMEM;
465 * Respond to a normal COOKIE ECHO chunk.
466 * We are the side that is being asked for an association.
468 * Section: 5.1 Normal Establishment of an Association, D
469 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
470 * with a COOKIE ACK chunk after building a TCB and moving to
471 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
472 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
473 * chunk MUST be the first chunk in the packet.
475 * IMPLEMENTATION NOTE: An implementation may choose to send the
476 * Communication Up notification to the SCTP user upon reception
477 * of a valid COOKIE ECHO chunk.
479 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
480 * D) Rules for packet carrying a COOKIE ECHO
482 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
483 * Initial Tag received in the INIT ACK.
485 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
487 * Inputs
488 * (endpoint, asoc, chunk)
490 * Outputs
491 * (asoc, reply_msg, msg_up, timers, counters)
493 * The return value is the disposition of the chunk.
495 sctp_disposition_t sctp_sf_do_5_1D_ce(const sctp_endpoint_t *ep,
496 const sctp_association_t *asoc,
497 const sctp_subtype_t type, void *arg,
498 sctp_cmd_seq_t *commands)
500 sctp_chunk_t *chunk = arg;
501 sctp_association_t *new_asoc;
502 sctp_init_chunk_t *peer_init;
503 sctp_chunk_t *repl;
504 sctp_ulpevent_t *ev;
505 int error = 0;
506 sctp_chunk_t *err_chk_p;
508 /* If the packet is an OOTB packet which is temporarily on the
509 * control endpoint, responding with an ABORT.
511 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
512 return sctp_sf_ootb(ep, asoc, type, arg, commands);
514 /* "Decode" the chunk. We have no optional parameters so we
515 * are in good shape.
517 chunk->subh.cookie_hdr =
518 (sctp_signed_cookie_t *)chunk->skb->data;
519 skb_pull(chunk->skb,
520 ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t));
522 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
523 * "Z" will reply with a COOKIE ACK chunk after building a TCB
524 * and moving to the ESTABLISHED state.
526 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
527 &err_chk_p);
529 /* FIXME:
530 * If the re-build failed, what is the proper error path
531 * from here?
533 * [We should abort the association. --piggy]
535 if (!new_asoc) {
536 /* FIXME: Several errors are possible. A bad cookie should
537 * be silently discarded, but think about logging it too.
539 switch (error) {
540 case -SCTP_IERROR_NOMEM:
541 goto nomem;
543 case -SCTP_IERROR_STALE_COOKIE:
544 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
545 err_chk_p);
546 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
548 case -SCTP_IERROR_BAD_SIG:
549 default:
550 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
554 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
555 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
556 SCTP_STATE(SCTP_STATE_ESTABLISHED));
557 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
559 if (new_asoc->autoclose)
560 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
561 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
563 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
565 /* Re-build the bind address for the association is done in
566 * the sctp_unpack_cookie() already.
568 /* This is a brand-new association, so these are not yet side
569 * effects--it is safe to run them here.
571 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
573 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
574 &chunk->subh.cookie_hdr->c.peer_addr,
575 peer_init, GFP_ATOMIC))
576 goto nomem_init;
578 repl = sctp_make_cookie_ack(new_asoc, chunk);
579 if (!repl)
580 goto nomem_repl;
582 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
584 /* RFC 2960 5.1 Normal Establishment of an Association
586 * D) IMPLEMENTATION NOTE: An implementation may choose to
587 * send the Communication Up notification to the SCTP user
588 * upon reception of a valid COOKIE ECHO chunk.
590 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0,
591 new_asoc->c.sinit_num_ostreams,
592 new_asoc->c.sinit_max_instreams,
593 GFP_ATOMIC);
594 if (!ev)
595 goto nomem_ev;
597 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
599 return SCTP_DISPOSITION_CONSUME;
601 nomem_ev:
602 sctp_free_chunk(repl);
603 nomem_repl:
604 nomem_init:
605 sctp_association_free(new_asoc);
606 nomem:
607 return SCTP_DISPOSITION_NOMEM;
611 * Respond to a normal COOKIE ACK chunk.
612 * We are the side that is being asked for an association.
614 * RFC 2960 5.1 Normal Establishment of an Association
616 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
617 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
618 * timer. It may also notify its ULP about the successful
619 * establishment of the association with a Communication Up
620 * notification (see Section 10).
622 * Verification Tag:
623 * Inputs
624 * (endpoint, asoc, chunk)
626 * Outputs
627 * (asoc, reply_msg, msg_up, timers, counters)
629 * The return value is the disposition of the chunk.
631 sctp_disposition_t sctp_sf_do_5_1E_ca(const sctp_endpoint_t *ep,
632 const sctp_association_t *asoc,
633 const sctp_subtype_t type, void *arg,
634 sctp_cmd_seq_t *commands)
636 sctp_ulpevent_t *ev;
638 /* RFC 2960 5.1 Normal Establishment of an Association
640 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
641 * from the COOKIE-ECHOED state to the ESTABLISHED state,
642 * stopping the T1-cookie timer.
644 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
645 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
646 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
647 SCTP_STATE(SCTP_STATE_ESTABLISHED));
648 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
649 if (asoc->autoclose)
650 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
651 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
652 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
654 /* It may also notify its ULP about the successful
655 * establishment of the association with a Communication Up
656 * notification (see Section 10).
658 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP,
659 0, asoc->c.sinit_num_ostreams,
660 asoc->c.sinit_max_instreams,
661 GFP_ATOMIC);
663 if (!ev)
664 goto nomem;
666 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
668 return SCTP_DISPOSITION_CONSUME;
670 nomem:
671 return SCTP_DISPOSITION_NOMEM;
674 /* Generate and sendout a heartbeat packet. */
675 sctp_disposition_t sctp_sf_heartbeat(const sctp_endpoint_t *ep,
676 const sctp_association_t *asoc,
677 const sctp_subtype_t type,
678 void *arg,
679 sctp_cmd_seq_t *commands)
681 sctp_transport_t *transport = (sctp_transport_t *) arg;
682 sctp_chunk_t *reply;
683 sctp_sender_hb_info_t hbinfo;
684 size_t paylen = 0;
686 hbinfo.param_hdr.type = SCTP_PARAM_HEARTBEAT_INFO;
687 hbinfo.param_hdr.length = htons(sizeof(sctp_sender_hb_info_t));
688 hbinfo.daddr = transport->ipaddr;
689 hbinfo.sent_at = jiffies;
691 /* Send a heartbeat to our peer. */
692 paylen = sizeof(sctp_sender_hb_info_t);
693 reply = sctp_make_heartbeat(asoc, transport, &hbinfo, paylen);
694 if (!reply)
695 return SCTP_DISPOSITION_NOMEM;
697 /* Set rto_pending indicating that an RTT measurement
698 * is started with this heartbeat chunk.
700 sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING,
701 SCTP_TRANSPORT(transport));
703 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
704 return SCTP_DISPOSITION_CONSUME;
707 /* Generate a HEARTBEAT packet on the given transport. */
708 sctp_disposition_t sctp_sf_sendbeat_8_3(const sctp_endpoint_t *ep,
709 const sctp_association_t *asoc,
710 const sctp_subtype_t type,
711 void *arg,
712 sctp_cmd_seq_t *commands)
714 sctp_transport_t *transport = (sctp_transport_t *) arg;
716 if (asoc->overall_error_count >= asoc->overall_error_threshold) {
717 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
718 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_NULL());
719 return SCTP_DISPOSITION_DELETE_TCB;
722 /* Section 3.3.5.
723 * The Sender-specific Heartbeat Info field should normally include
724 * information about the sender's current time when this HEARTBEAT
725 * chunk is sent and the destination transport address to which this
726 * HEARTBEAT is sent (see Section 8.3).
729 if (transport->hb_allowed) {
730 if (SCTP_DISPOSITION_NOMEM ==
731 sctp_sf_heartbeat(ep, asoc, type, arg,
732 commands))
733 return SCTP_DISPOSITION_NOMEM;
734 /* Set transport error counter and association error counter
735 * when sending heartbeat.
737 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET,
738 SCTP_TRANSPORT(transport));
740 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_UPDATE,
741 SCTP_TRANSPORT(transport));
743 return SCTP_DISPOSITION_CONSUME;
747 * Process an heartbeat request.
749 * Section: 8.3 Path Heartbeat
750 * The receiver of the HEARTBEAT should immediately respond with a
751 * HEARTBEAT ACK that contains the Heartbeat Information field copied
752 * from the received HEARTBEAT chunk.
754 * Verification Tag: 8.5 Verification Tag [Normal verification]
755 * When receiving an SCTP packet, the endpoint MUST ensure that the
756 * value in the Verification Tag field of the received SCTP packet
757 * matches its own Tag. If the received Verification Tag value does not
758 * match the receiver's own tag value, the receiver shall silently
759 * discard the packet and shall not process it any further except for
760 * those cases listed in Section 8.5.1 below.
762 * Inputs
763 * (endpoint, asoc, chunk)
765 * Outputs
766 * (asoc, reply_msg, msg_up, timers, counters)
768 * The return value is the disposition of the chunk.
770 sctp_disposition_t sctp_sf_beat_8_3(const sctp_endpoint_t *ep,
771 const sctp_association_t *asoc,
772 const sctp_subtype_t type,
773 void *arg,
774 sctp_cmd_seq_t *commands)
776 sctp_chunk_t *chunk = arg;
777 sctp_chunk_t *reply;
778 size_t paylen = 0;
780 /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
781 * that the value in the Verification Tag field of the
782 * received SCTP packet matches its own Tag. If the received
783 * Verification Tag value does not match the receiver's own
784 * tag value, the receiver shall silently discard the packet...
786 if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
787 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
789 /* 8.3 The receiver of the HEARTBEAT should immediately
790 * respond with a HEARTBEAT ACK that contains the Heartbeat
791 * Information field copied from the received HEARTBEAT chunk.
793 chunk->subh.hb_hdr = (sctp_heartbeathdr_t *) chunk->skb->data;
794 paylen = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t);
795 skb_pull(chunk->skb, paylen);
797 reply = sctp_make_heartbeat_ack(asoc, chunk,
798 chunk->subh.hb_hdr, paylen);
799 if (!reply)
800 goto nomem;
802 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
803 return SCTP_DISPOSITION_CONSUME;
805 nomem:
806 return SCTP_DISPOSITION_NOMEM;
810 * Process the returning HEARTBEAT ACK.
812 * Section: 8.3 Path Heartbeat
813 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
814 * should clear the error counter of the destination transport
815 * address to which the HEARTBEAT was sent, and mark the destination
816 * transport address as active if it is not so marked. The endpoint may
817 * optionally report to the upper layer when an inactive destination
818 * address is marked as active due to the reception of the latest
819 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
820 * clear the association overall error count as well (as defined
821 * in section 8.1).
823 * The receiver of the HEARTBEAT ACK should also perform an RTT
824 * measurement for that destination transport address using the time
825 * value carried in the HEARTBEAT ACK chunk.
827 * Verification Tag: 8.5 Verification Tag [Normal verification]
829 * Inputs
830 * (endpoint, asoc, chunk)
832 * Outputs
833 * (asoc, reply_msg, msg_up, timers, counters)
835 * The return value is the disposition of the chunk.
837 sctp_disposition_t sctp_sf_backbeat_8_3(const sctp_endpoint_t *ep,
838 const sctp_association_t *asoc,
839 const sctp_subtype_t type,
840 void *arg,
841 sctp_cmd_seq_t *commands)
843 sctp_chunk_t *chunk = arg;
844 union sctp_addr from_addr;
845 sctp_transport_t *link;
846 sctp_sender_hb_info_t *hbinfo;
847 unsigned long max_interval;
849 /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
850 * that the value in the Verification Tag field of the
851 * received SCTP packet matches its own Tag. ...
853 if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
854 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
856 hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data;
857 from_addr = hbinfo->daddr;
858 link = sctp_assoc_lookup_paddr(asoc, &from_addr);
860 /* This should never happen, but lets log it if so. */
861 if (!link) {
862 printk(KERN_WARNING
863 "%s: Could not find address %d.%d.%d.%d\n",
864 __FUNCTION__, NIPQUAD(from_addr.v4.sin_addr));
865 return SCTP_DISPOSITION_DISCARD;
868 max_interval = link->hb_interval + link->rto;
870 /* Check if the timestamp looks valid. */
871 if (time_after(hbinfo->sent_at, jiffies) ||
872 time_after(jiffies, hbinfo->sent_at + max_interval)) {
873 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp"
874 "received for transport: %p\n",
875 __FUNCTION__, link);
876 return SCTP_DISPOSITION_DISCARD;
879 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
880 * the HEARTBEAT should clear the error counter of the
881 * destination transport address to which the HEARTBEAT was
882 * sent and mark the destination transport address as active if
883 * it is not so marked.
885 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link));
887 return SCTP_DISPOSITION_CONSUME;
890 /* Helper function to send out an abort for the restart
891 * condition.
893 static int sctp_sf_send_restart_abort(union sctp_addr *ssa,
894 sctp_chunk_t *init,
895 sctp_cmd_seq_t *commands)
897 int len;
898 sctp_packet_t *pkt;
899 sctp_addr_param_t *addrparm;
900 sctp_errhdr_t *errhdr;
901 sctp_endpoint_t *ep;
902 char buffer[sizeof(sctp_errhdr_t) + sizeof(sctp_addr_param_t)];
904 /* Build the error on the stack. We are way to malloc
905 * malloc crazy throughout the code today.
907 errhdr = (sctp_errhdr_t *)buffer;
908 addrparm = (sctp_addr_param_t *)errhdr->variable;
910 /* Copy into a parm format. */
911 len = sockaddr2sctp_addr(ssa, addrparm);
912 len += sizeof(sctp_errhdr_t);
914 errhdr->cause = SCTP_ERROR_RESTART;
915 errhdr->length = htons(len);
917 /* Assign to the control socket. */
918 ep = sctp_sk((sctp_get_ctl_sock()))->ep;
920 /* Association is NULL since this may be a restart attack and we
921 * want to send back the attacker's vtag.
923 pkt = sctp_abort_pkt_new(ep, NULL, init, errhdr, len);
925 if (!pkt)
926 goto out;
927 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt));
929 /* Discard the rest of the inbound packet. */
930 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
932 out:
933 /* Even if there is no memory, treat as a failure so
934 * the packet will get dropped.
936 return 0;
939 /* A restart is occuring, check to make sure no new addresses
940 * are being added as we may be under a takeover attack.
942 static int sctp_sf_check_restart_addrs(const sctp_association_t *new_asoc,
943 const sctp_association_t *asoc,
944 sctp_chunk_t *init,
945 sctp_cmd_seq_t *commands)
947 sctp_transport_t *new_addr, *addr;
948 struct list_head *pos, *pos2;
949 int found;
951 /* Implementor's Guide - Sectin 5.2.2
952 * ...
953 * Before responding the endpoint MUST check to see if the
954 * unexpected INIT adds new addresses to the association. If new
955 * addresses are added to the association, the endpoint MUST respond
956 * with an ABORT..
959 /* Search through all current addresses and make sure
960 * we aren't adding any new ones.
962 new_addr = 0;
963 found = 0;
965 list_for_each(pos, &new_asoc->peer.transport_addr_list) {
966 new_addr = list_entry(pos, sctp_transport_t, transports);
967 found = 0;
968 list_for_each(pos2, &asoc->peer.transport_addr_list) {
969 addr = list_entry(pos2, sctp_transport_t, transports);
970 if (sctp_cmp_addr_exact(&new_addr->ipaddr,
971 &addr->ipaddr)) {
972 found = 1;
973 break;
976 if (!found)
977 break;
980 /* If a new address was added, ABORT the sender. */
981 if (!found && new_addr) {
982 sctp_sf_send_restart_abort(&new_addr->ipaddr, init, commands);
985 /* Return success if all addresses were found. */
986 return found;
989 /* Populate the verification/tie tags based on overlapping INIT
990 * scenario.
992 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
994 static void sctp_tietags_populate(sctp_association_t *new_asoc,
995 const sctp_association_t *asoc)
997 switch (asoc->state) {
999 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1001 case SCTP_STATE_COOKIE_WAIT:
1002 new_asoc->c.my_vtag = asoc->c.my_vtag;
1003 new_asoc->c.my_ttag = asoc->c.my_vtag;
1004 new_asoc->c.peer_ttag = 0;
1005 break;
1007 case SCTP_STATE_COOKIE_ECHOED:
1008 new_asoc->c.my_vtag = asoc->c.my_vtag;
1009 new_asoc->c.my_ttag = asoc->c.my_vtag;
1010 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1011 break;
1013 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1014 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1016 default:
1017 new_asoc->c.my_ttag = asoc->c.my_vtag;
1018 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1019 break;
1022 /* Other parameters for the endpoint SHOULD be copied from the
1023 * existing parameters of the association (e.g. number of
1024 * outbound streams) into the INIT ACK and cookie.
1026 new_asoc->rwnd = asoc->rwnd;
1027 new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams;
1028 new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams;
1029 new_asoc->c.initial_tsn = asoc->c.initial_tsn;
1033 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1034 * handling action.
1036 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1038 * Returns value representing action to be taken. These action values
1039 * correspond to Action/Description values in RFC 2960, Table 2.
1041 static char sctp_tietags_compare(sctp_association_t *new_asoc,
1042 const sctp_association_t *asoc)
1044 /* In this case, the peer may have restarted. */
1045 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1046 (asoc->c.peer_vtag != new_asoc->c.peer_vtag) &&
1047 (asoc->c.my_vtag == new_asoc->c.my_ttag) &&
1048 (asoc->c.peer_vtag == new_asoc->c.peer_ttag))
1049 return 'A';
1051 /* Collision case D.
1052 * Note: Test case D first, otherwise it may be incorrectly
1053 * identified as second case of B if the value of the Tie_tag is
1054 * not filled into the state cookie.
1056 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1057 (asoc->c.peer_vtag == new_asoc->c.peer_vtag))
1058 return 'D';
1060 /* Collision case B. */
1061 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1062 ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) ||
1063 (!new_asoc->c.my_ttag && !new_asoc->c.peer_ttag)))
1064 return 'B';
1066 /* Collision case C. */
1067 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1068 (asoc->c.peer_vtag == new_asoc->c.peer_vtag) &&
1069 (0 == new_asoc->c.my_ttag) &&
1070 (0 == new_asoc->c.peer_ttag))
1071 return 'C';
1073 return 'E'; /* No such case available. */
1076 /* Common helper routine for both duplicate and simulataneous INIT
1077 * chunk handling.
1079 static sctp_disposition_t sctp_sf_do_unexpected_init(
1080 const sctp_endpoint_t *ep,
1081 const sctp_association_t *asoc,
1082 const sctp_subtype_t type,
1083 void *arg, sctp_cmd_seq_t *commands)
1085 sctp_disposition_t retval;
1086 sctp_chunk_t *chunk = arg;
1087 sctp_chunk_t *repl;
1088 sctp_association_t *new_asoc;
1089 sctp_chunk_t *err_chunk;
1090 sctp_packet_t *packet;
1091 sctp_unrecognized_param_t *unk_param;
1092 int len;
1095 /* 6.10 Bundling
1096 * An endpoint MUST NOT bundle INIT, INIT ACK or
1097 * SHUTDOWN COMPLETE with any other chunks.
1099 if (!chunk->singleton)
1100 return SCTP_DISPOSITION_VIOLATION;
1102 /* Grab the INIT header. */
1103 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
1105 /* Tag the variable length parameters. */
1106 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
1108 /* Verify the INIT chunk before processing it. */
1109 err_chunk = NULL;
1110 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
1111 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
1112 &err_chunk)) {
1113 /* This chunk contains fatal error. It is to be discarded.
1114 * Send an ABORT, with causes if there is any.
1116 if (err_chunk) {
1117 packet = sctp_abort_pkt_new(ep, asoc, arg,
1118 (__u8 *)(err_chunk->chunk_hdr) +
1119 sizeof(sctp_chunkhdr_t),
1120 ntohs(err_chunk->chunk_hdr->length) -
1121 sizeof(sctp_chunkhdr_t));
1123 if (packet) {
1124 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
1125 SCTP_PACKET(packet));
1126 retval = SCTP_DISPOSITION_CONSUME;
1127 } else {
1128 retval = SCTP_DISPOSITION_NOMEM;
1130 goto cleanup;
1131 } else {
1132 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
1133 commands);
1138 * Other parameters for the endpoint SHOULD be copied from the
1139 * existing parameters of the association (e.g. number of
1140 * outbound streams) into the INIT ACK and cookie.
1141 * FIXME: We are copying parameters from the endpoint not the
1142 * association.
1144 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
1145 if (!new_asoc)
1146 goto nomem;
1148 /* In the outbound INIT ACK the endpoint MUST copy its current
1149 * Verification Tag and Peers Verification tag into a reserved
1150 * place (local tie-tag and per tie-tag) within the state cookie.
1152 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1153 sctp_source(chunk),
1154 (sctp_init_chunk_t *)chunk->chunk_hdr,
1155 GFP_ATOMIC)) {
1156 retval = SCTP_DISPOSITION_NOMEM;
1157 goto nomem_init;
1160 /* Make sure no new addresses are being added during the
1161 * restart. Do not do this check for COOKIE-WAIT state,
1162 * since there are no peer addresses to check against.
1163 * Upon return an ABORT will have been sent if needed.
1165 if (asoc->state != SCTP_STATE_COOKIE_WAIT) {
1166 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
1167 commands)) {
1168 retval = SCTP_DISPOSITION_CONSUME;
1169 goto cleanup_asoc;
1173 sctp_tietags_populate(new_asoc, asoc);
1175 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1177 /* If there are errors need to be reported for unknown parameters,
1178 * make sure to reserve enough room in the INIT ACK for them.
1180 len = 0;
1181 if (err_chunk) {
1182 len = ntohs(err_chunk->chunk_hdr->length) -
1183 sizeof(sctp_chunkhdr_t);
1185 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
1186 if (!repl)
1187 goto nomem;
1189 /* If there are errors need to be reported for unknown parameters,
1190 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1191 * parameter.
1193 if (err_chunk) {
1194 /* Get the "Unrecognized parameter" parameter(s) out of the
1195 * ERROR chunk generated by sctp_verify_init(). Since the
1196 * error cause code for "unknown parameter" and the
1197 * "Unrecognized parameter" type is the same, we can
1198 * construct the parameters in INIT ACK by copying the
1199 * ERROR causes over.
1201 unk_param = (sctp_unrecognized_param_t *)
1202 ((__u8 *)(err_chunk->chunk_hdr) +
1203 sizeof(sctp_chunkhdr_t));
1204 /* Replace the cause code with the "Unrecognized parameter"
1205 * parameter type.
1207 sctp_addto_chunk(repl, len, unk_param);
1208 sctp_free_chunk(err_chunk);
1211 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1212 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1215 * Note: After sending out INIT ACK with the State Cookie parameter,
1216 * "Z" MUST NOT allocate any resources for this new association.
1217 * Otherwise, "Z" will be vulnerable to resource attacks.
1219 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1220 retval = SCTP_DISPOSITION_CONSUME;
1222 cleanup:
1223 if (err_chunk)
1224 sctp_free_chunk(err_chunk);
1225 return retval;
1226 nomem:
1227 retval = SCTP_DISPOSITION_NOMEM;
1228 goto cleanup;
1229 nomem_init:
1230 cleanup_asoc:
1231 sctp_association_free(new_asoc);
1232 goto cleanup;
1236 * Handle simultanous INIT.
1237 * This means we started an INIT and then we got an INIT request from
1238 * our peer.
1240 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1241 * This usually indicates an initialization collision, i.e., each
1242 * endpoint is attempting, at about the same time, to establish an
1243 * association with the other endpoint.
1245 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1246 * endpoint MUST respond with an INIT ACK using the same parameters it
1247 * sent in its original INIT chunk (including its Verification Tag,
1248 * unchanged). These original parameters are combined with those from the
1249 * newly received INIT chunk. The endpoint shall also generate a State
1250 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1251 * INIT to calculate the State Cookie.
1253 * After that, the endpoint MUST NOT change its state, the T1-init
1254 * timer shall be left running and the corresponding TCB MUST NOT be
1255 * destroyed. The normal procedures for handling State Cookies when
1256 * a TCB exists will resolve the duplicate INITs to a single association.
1258 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1259 * its Tie-Tags with the Tag information of itself and its peer (see
1260 * section 5.2.2 for a description of the Tie-Tags).
1262 * Verification Tag: Not explicit, but an INIT can not have a valid
1263 * verification tag, so we skip the check.
1265 * Inputs
1266 * (endpoint, asoc, chunk)
1268 * Outputs
1269 * (asoc, reply_msg, msg_up, timers, counters)
1271 * The return value is the disposition of the chunk.
1273 sctp_disposition_t sctp_sf_do_5_2_1_siminit(const sctp_endpoint_t *ep,
1274 const sctp_association_t *asoc,
1275 const sctp_subtype_t type,
1276 void *arg,
1277 sctp_cmd_seq_t *commands)
1279 /* Call helper to do the real work for both simulataneous and
1280 * duplicate INIT chunk handling.
1282 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1286 * Handle duplicated INIT messages. These are usually delayed
1287 * restransmissions.
1289 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1290 * COOKIE-ECHOED and COOKIE-WAIT
1292 * Unless otherwise stated, upon reception of an unexpected INIT for
1293 * this association, the endpoint shall generate an INIT ACK with a
1294 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1295 * current Verification Tag and peer's Verification Tag into a reserved
1296 * place within the state cookie. We shall refer to these locations as
1297 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1298 * containing this INIT ACK MUST carry a Verification Tag value equal to
1299 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1300 * MUST contain a new Initiation Tag (randomly generated see Section
1301 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1302 * existing parameters of the association (e.g. number of outbound
1303 * streams) into the INIT ACK and cookie.
1305 * After sending out the INIT ACK, the endpoint shall take no further
1306 * actions, i.e., the existing association, including its current state,
1307 * and the corresponding TCB MUST NOT be changed.
1309 * Note: Only when a TCB exists and the association is not in a COOKIE-
1310 * WAIT state are the Tie-Tags populated. For a normal association INIT
1311 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1312 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1313 * State Cookie are populated as specified in section 5.2.1.
1315 * Verification Tag: Not specifed, but an INIT has no way of knowing
1316 * what the verification tag could be, so we ignore it.
1318 * Inputs
1319 * (endpoint, asoc, chunk)
1321 * Outputs
1322 * (asoc, reply_msg, msg_up, timers, counters)
1324 * The return value is the disposition of the chunk.
1326 sctp_disposition_t sctp_sf_do_5_2_2_dupinit(const sctp_endpoint_t *ep,
1327 const sctp_association_t *asoc,
1328 const sctp_subtype_t type,
1329 void *arg,
1330 sctp_cmd_seq_t *commands)
1332 /* Call helper to do the real work for both simulataneous and
1333 * duplicate INIT chunk handling.
1335 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1340 /* Unexpected COOKIE-ECHO handlerfor peer restart (Table 2, action 'A')
1342 * Section 5.2.4
1343 * A) In this case, the peer may have restarted.
1345 static sctp_disposition_t sctp_sf_do_dupcook_a(const sctp_endpoint_t *ep,
1346 const sctp_association_t *asoc,
1347 sctp_chunk_t *chunk,
1348 sctp_cmd_seq_t *commands,
1349 sctp_association_t *new_asoc)
1351 sctp_init_chunk_t *peer_init;
1352 sctp_ulpevent_t *ev;
1353 sctp_chunk_t *repl;
1355 /* new_asoc is a brand-new association, so these are not yet
1356 * side effects--it is safe to run them here.
1358 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1360 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1361 sctp_source(chunk), peer_init, GFP_ATOMIC))
1362 goto nomem;
1364 /* Make sure no new addresses are being added during the
1365 * restart. Though this is a pretty complicated attack
1366 * since you'd have to get inside the cookie.
1368 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) {
1369 return SCTP_DISPOSITION_CONSUME;
1372 /* For now, fail any unsent/unacked data. Consider the optional
1373 * choice of resending of this data.
1375 sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL());
1377 /* Update the content of current association. */
1378 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1380 repl = sctp_make_cookie_ack(new_asoc, chunk);
1381 if (!repl)
1382 goto nomem;
1384 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1386 /* Report association restart to upper layer. */
1387 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0,
1388 new_asoc->c.sinit_num_ostreams,
1389 new_asoc->c.sinit_max_instreams,
1390 GFP_ATOMIC);
1391 if (!ev)
1392 goto nomem_ev;
1394 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1395 return SCTP_DISPOSITION_CONSUME;
1397 nomem_ev:
1398 sctp_free_chunk(repl);
1399 nomem:
1400 return SCTP_DISPOSITION_NOMEM;
1403 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1405 * Section 5.2.4
1406 * B) In this case, both sides may be attempting to start an association
1407 * at about the same time but the peer endpoint started its INIT
1408 * after responding to the local endpoint's INIT
1410 /* This case represents an intialization collision. */
1411 static sctp_disposition_t sctp_sf_do_dupcook_b(const sctp_endpoint_t *ep,
1412 const sctp_association_t *asoc,
1413 sctp_chunk_t *chunk,
1414 sctp_cmd_seq_t *commands,
1415 sctp_association_t *new_asoc)
1417 sctp_init_chunk_t *peer_init;
1418 sctp_ulpevent_t *ev;
1419 sctp_chunk_t *repl;
1421 /* new_asoc is a brand-new association, so these are not yet
1422 * side effects--it is safe to run them here.
1424 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1425 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1426 sctp_source(chunk), peer_init, GFP_ATOMIC))
1427 goto nomem;
1429 /* Update the content of current association. */
1430 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1431 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1432 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1433 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
1435 repl = sctp_make_cookie_ack(new_asoc, chunk);
1436 if (!repl)
1437 goto nomem;
1439 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1440 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1442 /* RFC 2960 5.1 Normal Establishment of an Association
1444 * D) IMPLEMENTATION NOTE: An implementation may choose to
1445 * send the Communication Up notification to the SCTP user
1446 * upon reception of a valid COOKIE ECHO chunk.
1448 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP, 0,
1449 new_asoc->c.sinit_num_ostreams,
1450 new_asoc->c.sinit_max_instreams,
1451 GFP_ATOMIC);
1452 if (!ev)
1453 goto nomem_ev;
1455 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1456 return SCTP_DISPOSITION_CONSUME;
1458 nomem_ev:
1459 sctp_free_chunk(repl);
1460 nomem:
1461 return SCTP_DISPOSITION_NOMEM;
1464 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1466 * Section 5.2.4
1467 * C) In this case, the local endpoint's cookie has arrived late.
1468 * Before it arrived, the local endpoint sent an INIT and received an
1469 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1470 * but a new tag of its own.
1472 /* This case represents an intialization collision. */
1473 static sctp_disposition_t sctp_sf_do_dupcook_c(const sctp_endpoint_t *ep,
1474 const sctp_association_t *asoc,
1475 sctp_chunk_t *chunk,
1476 sctp_cmd_seq_t *commands,
1477 sctp_association_t *new_asoc)
1479 /* The cookie should be silently discarded.
1480 * The endpoint SHOULD NOT change states and should leave
1481 * any timers running.
1483 return SCTP_DISPOSITION_DISCARD;
1486 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1488 * Section 5.2.4
1490 * D) When both local and remote tags match the endpoint should always
1491 * enter the ESTABLISHED state, if it has not already done so.
1493 /* This case represents an intialization collision. */
1494 static sctp_disposition_t sctp_sf_do_dupcook_d(const sctp_endpoint_t *ep,
1495 const sctp_association_t *asoc,
1496 sctp_chunk_t *chunk,
1497 sctp_cmd_seq_t *commands,
1498 sctp_association_t *new_asoc)
1500 sctp_ulpevent_t *ev = NULL;
1501 sctp_chunk_t *repl;
1503 /* The local endpoint cannot use any value from the received
1504 * state cookie and need to immediately resend a COOKIE-ACK
1505 * and move into ESTABLISHED if it hasn't done so.
1507 if (SCTP_STATE_ESTABLISHED != asoc->state) {
1508 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1509 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1510 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START,
1511 SCTP_NULL());
1513 /* RFC 2960 5.1 Normal Establishment of an Association
1515 * D) IMPLEMENTATION NOTE: An implementation may choose
1516 * to send the Communication Up notification to the
1517 * SCTP user upon reception of a valid COOKIE
1518 * ECHO chunk.
1520 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0,
1521 SCTP_COMM_UP, 0,
1522 new_asoc->c.sinit_num_ostreams,
1523 new_asoc->c.sinit_max_instreams,
1524 GFP_ATOMIC);
1525 if (!ev)
1526 goto nomem;
1527 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1528 SCTP_ULPEVENT(ev));
1530 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1532 repl = sctp_make_cookie_ack(new_asoc, chunk);
1533 if (!repl)
1534 goto nomem;
1536 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1537 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1538 return SCTP_DISPOSITION_CONSUME;
1540 nomem:
1541 if (ev)
1542 sctp_ulpevent_free(ev);
1543 return SCTP_DISPOSITION_NOMEM;
1547 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1548 * chunk was retransmitted and then delayed in the network.
1550 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1552 * Verification Tag: None. Do cookie validation.
1554 * Inputs
1555 * (endpoint, asoc, chunk)
1557 * Outputs
1558 * (asoc, reply_msg, msg_up, timers, counters)
1560 * The return value is the disposition of the chunk.
1562 sctp_disposition_t sctp_sf_do_5_2_4_dupcook(const sctp_endpoint_t *ep,
1563 const sctp_association_t *asoc,
1564 const sctp_subtype_t type,
1565 void *arg,
1566 sctp_cmd_seq_t *commands)
1568 sctp_disposition_t retval;
1569 sctp_chunk_t *chunk = arg;
1570 sctp_association_t *new_asoc;
1571 int error = 0;
1572 char action;
1573 sctp_chunk_t *err_chk_p;
1575 /* "Decode" the chunk. We have no optional parameters so we
1576 * are in good shape.
1578 chunk->subh.cookie_hdr = (sctp_signed_cookie_t *)chunk->skb->data;
1579 skb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
1580 sizeof(sctp_chunkhdr_t));
1582 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
1583 * of a duplicate COOKIE ECHO match the Verification Tags of the
1584 * current association, consider the State Cookie valid even if
1585 * the lifespan is exceeded.
1587 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
1588 &err_chk_p);
1590 /* FIXME:
1591 * If the re-build failed, what is the proper error path
1592 * from here?
1594 * [We should abort the association. --piggy]
1596 if (!new_asoc) {
1597 /* FIXME: Several errors are possible. A bad cookie should
1598 * be silently discarded, but think about logging it too.
1600 switch (error) {
1601 case -SCTP_IERROR_NOMEM:
1602 goto nomem;
1604 case -SCTP_IERROR_STALE_COOKIE:
1605 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
1606 err_chk_p);
1607 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1609 break;
1610 case -SCTP_IERROR_BAD_SIG:
1611 default:
1612 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1616 /* Compare the tie_tag in cookie with the verification tag of
1617 * current association.
1619 action = sctp_tietags_compare(new_asoc, asoc);
1621 switch (action) {
1622 case 'A': /* Association restart. */
1623 retval = sctp_sf_do_dupcook_a(ep, asoc, chunk, commands,
1624 new_asoc);
1625 break;
1627 case 'B': /* Collision case B. */
1628 retval = sctp_sf_do_dupcook_b(ep, asoc, chunk, commands,
1629 new_asoc);
1630 break;
1632 case 'C': /* Collisioun case C. */
1633 retval = sctp_sf_do_dupcook_c(ep, asoc, chunk, commands,
1634 new_asoc);
1635 break;
1637 case 'D': /* Collision case D. */
1638 retval = sctp_sf_do_dupcook_d(ep, asoc, chunk, commands,
1639 new_asoc);
1640 break;
1642 default: /* No such case, discard it. */
1643 printk(KERN_WARNING "%s:unknown case\n", __FUNCTION__);
1644 retval = SCTP_DISPOSITION_DISCARD;
1645 break;
1648 /* Delete the tempory new association. */
1649 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1650 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1652 return retval;
1654 nomem:
1655 return SCTP_DISPOSITION_NOMEM;
1659 * Process an ABORT. (SHUTDOWN-PENDING state)
1661 * See sctp_sf_do_9_1_abort().
1663 sctp_disposition_t sctp_sf_shutdown_pending_abort(const sctp_endpoint_t *ep,
1664 const sctp_association_t *asoc,
1665 const sctp_subtype_t type,
1666 void *arg,
1667 sctp_cmd_seq_t *commands)
1669 sctp_chunk_t *chunk = arg;
1671 if (!sctp_vtag_verify_either(chunk, asoc))
1672 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1674 /* Stop the T5-shutdown guard timer. */
1675 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1676 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
1678 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
1682 * Process an ABORT. (SHUTDOWN-SENT state)
1684 * See sctp_sf_do_9_1_abort().
1686 sctp_disposition_t sctp_sf_shutdown_sent_abort(const sctp_endpoint_t *ep,
1687 const sctp_association_t *asoc,
1688 const sctp_subtype_t type,
1689 void *arg,
1690 sctp_cmd_seq_t *commands)
1692 sctp_chunk_t *chunk = arg;
1694 if (!sctp_vtag_verify_either(chunk, asoc))
1695 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1697 /* Stop the T2-shutdown timer. */
1698 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1699 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
1701 /* Stop the T5-shutdown guard timer. */
1702 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1703 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
1705 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
1709 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
1711 * See sctp_sf_do_9_1_abort().
1713 sctp_disposition_t sctp_sf_shutdown_ack_sent_abort(const sctp_endpoint_t *ep,
1714 const sctp_association_t *asoc,
1715 const sctp_subtype_t type,
1716 void *arg,
1717 sctp_cmd_seq_t *commands)
1719 /* The same T2 timer, so we should be able to use
1720 * common function with the SHUTDOWN-SENT state.
1722 return sctp_sf_shutdown_sent_abort(ep, asoc, type, arg, commands);
1726 * Handle an Error received in COOKIE_ECHOED state.
1728 * Only handle the error type of stale COOKIE Error, the other errors will
1729 * be ignored.
1731 * Inputs
1732 * (endpoint, asoc, chunk)
1734 * Outputs
1735 * (asoc, reply_msg, msg_up, timers, counters)
1737 * The return value is the disposition of the chunk.
1739 sctp_disposition_t sctp_sf_cookie_echoed_err(const sctp_endpoint_t *ep,
1740 const sctp_association_t *asoc,
1741 const sctp_subtype_t type,
1742 void *arg,
1743 sctp_cmd_seq_t *commands)
1745 sctp_chunk_t *chunk = arg;
1746 sctp_errhdr_t *err;
1748 /* If we have gotten too many failures, give up. */
1749 if (1 + asoc->counters[SCTP_COUNTER_INIT_ERROR] >
1750 asoc->max_init_attempts) {
1751 /* INIT_FAILED will issue an ulpevent. */
1752 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, SCTP_NULL());
1753 return SCTP_DISPOSITION_DELETE_TCB;
1755 err = (sctp_errhdr_t *)(chunk->skb->data);
1757 /* Process the error here */
1758 switch (err->cause) {
1759 case SCTP_ERROR_STALE_COOKIE:
1760 return sctp_sf_do_5_2_6_stale(ep, asoc, type, arg, commands);
1761 default:
1762 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1767 * Handle a Stale COOKIE Error
1769 * Section: 5.2.6 Handle Stale COOKIE Error
1770 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
1771 * one of the following three alternatives.
1772 * ...
1773 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
1774 * Preservative parameter requesting an extension to the lifetime of
1775 * the State Cookie. When calculating the time extension, an
1776 * implementation SHOULD use the RTT information measured based on the
1777 * previous COOKIE ECHO / ERROR exchange, and should add no more
1778 * than 1 second beyond the measured RTT, due to long State Cookie
1779 * lifetimes making the endpoint more subject to a replay attack.
1781 * Verification Tag: Not explicit, but safe to ignore.
1783 * Inputs
1784 * (endpoint, asoc, chunk)
1786 * Outputs
1787 * (asoc, reply_msg, msg_up, timers, counters)
1789 * The return value is the disposition of the chunk.
1791 sctp_disposition_t sctp_sf_do_5_2_6_stale(const sctp_endpoint_t *ep,
1792 const sctp_association_t *asoc,
1793 const sctp_subtype_t type,
1794 void *arg,
1795 sctp_cmd_seq_t *commands)
1797 sctp_chunk_t *chunk = arg;
1798 time_t stale;
1799 sctp_cookie_preserve_param_t bht;
1800 sctp_errhdr_t *err;
1801 struct list_head *pos;
1802 sctp_transport_t *t;
1803 sctp_chunk_t *reply;
1804 sctp_bind_addr_t *bp;
1805 int attempts;
1807 attempts = asoc->counters[SCTP_COUNTER_INIT_ERROR] + 1;
1809 if (attempts >= asoc->max_init_attempts) {
1810 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, SCTP_NULL());
1811 return SCTP_DISPOSITION_DELETE_TCB;
1814 err = (sctp_errhdr_t *)(chunk->skb->data);
1816 /* When calculating the time extension, an implementation
1817 * SHOULD use the RTT information measured based on the
1818 * previous COOKIE ECHO / ERROR exchange, and should add no
1819 * more than 1 second beyond the measured RTT, due to long
1820 * State Cookie lifetimes making the endpoint more subject to
1821 * a replay attack.
1822 * Measure of Staleness's unit is usec. (1/1000000 sec)
1823 * Suggested Cookie Life-span Increment's unit is msec.
1824 * (1/1000 sec)
1825 * In general, if you use the suggested cookie life, the value
1826 * found in the field of measure of staleness should be doubled
1827 * to give ample time to retransmit the new cookie and thus
1828 * yield a higher probability of success on the reattempt.
1830 stale = ntohl(*(suseconds_t *)((u8 *)err + sizeof(sctp_errhdr_t)));
1831 stale = stale << 1 / 1000;
1833 bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE;
1834 bht.param_hdr.length = htons(sizeof(bht));
1835 bht.lifespan_increment = htonl(stale);
1837 /* Build that new INIT chunk. */
1838 bp = (sctp_bind_addr_t *) &asoc->base.bind_addr;
1839 reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht));
1840 if (!reply)
1841 goto nomem;
1843 sctp_addto_chunk(reply, sizeof(bht), &bht);
1845 /* Cast away the const modifier, as we want to just
1846 * rerun it through as a sideffect.
1848 sctp_add_cmd_sf(commands, SCTP_CMD_COUNTER_INC,
1849 SCTP_COUNTER(SCTP_COUNTER_INIT_ERROR));
1851 /* If we've sent any data bundled with COOKIE-ECHO we need to resend. */
1852 list_for_each(pos, &asoc->peer.transport_addr_list) {
1853 t = list_entry(pos, sctp_transport_t, transports);
1854 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(t));
1857 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1858 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
1859 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1860 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
1861 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
1862 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
1864 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
1866 return SCTP_DISPOSITION_CONSUME;
1868 nomem:
1869 return SCTP_DISPOSITION_NOMEM;
1873 * Process an ABORT.
1875 * Section: 9.1
1876 * After checking the Verification Tag, the receiving endpoint shall
1877 * remove the association from its record, and shall report the
1878 * termination to its upper layer.
1880 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
1881 * B) Rules for packet carrying ABORT:
1883 * - The endpoint shall always fill in the Verification Tag field of the
1884 * outbound packet with the destination endpoint's tag value if it
1885 * is known.
1887 * - If the ABORT is sent in response to an OOTB packet, the endpoint
1888 * MUST follow the procedure described in Section 8.4.
1890 * - The receiver MUST accept the packet if the Verification Tag
1891 * matches either its own tag, OR the tag of its peer. Otherwise, the
1892 * receiver MUST silently discard the packet and take no further
1893 * action.
1895 * Inputs
1896 * (endpoint, asoc, chunk)
1898 * Outputs
1899 * (asoc, reply_msg, msg_up, timers, counters)
1901 * The return value is the disposition of the chunk.
1903 sctp_disposition_t sctp_sf_do_9_1_abort(const sctp_endpoint_t *ep,
1904 const sctp_association_t *asoc,
1905 const sctp_subtype_t type,
1906 void *arg,
1907 sctp_cmd_seq_t *commands)
1909 sctp_chunk_t *chunk = arg;
1911 if (!sctp_vtag_verify_either(chunk, asoc))
1912 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1914 /* ASSOC_FAILED will DELETE_TCB. */
1915 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_NULL());
1917 /* BUG? This does not look complete... */
1918 return SCTP_DISPOSITION_ABORT;
1922 * Process an ABORT. (COOKIE-WAIT state)
1924 * See sctp_sf_do_9_1_abort() above.
1926 sctp_disposition_t sctp_sf_cookie_wait_abort(const sctp_endpoint_t *ep,
1927 const sctp_association_t *asoc,
1928 const sctp_subtype_t type,
1929 void *arg,
1930 sctp_cmd_seq_t *commands)
1932 sctp_chunk_t *chunk = arg;
1934 if (!sctp_vtag_verify_either(chunk, asoc))
1935 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1937 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1938 SCTP_STATE(SCTP_STATE_CLOSED));
1939 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1940 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
1942 /* CMD_INIT_FAILED will DELETE_TCB. */
1943 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, SCTP_NULL());
1945 /* BUG? This does not look complete... */
1946 return SCTP_DISPOSITION_ABORT;
1950 * Process an ABORT. (COOKIE-ECHOED state)
1952 * See sctp_sf_do_9_1_abort() above.
1954 sctp_disposition_t sctp_sf_cookie_echoed_abort(const sctp_endpoint_t *ep,
1955 const sctp_association_t *asoc,
1956 const sctp_subtype_t type,
1957 void *arg,
1958 sctp_cmd_seq_t *commands)
1960 /* There is a single T1 timer, so we should be able to use
1961 * common function with the COOKIE-WAIT state.
1963 return sctp_sf_cookie_wait_abort(ep, asoc, type, arg, commands);
1967 * sctp_sf_do_9_2_shut
1969 * Section: 9.2
1970 * Upon the reception of the SHUTDOWN, the peer endpoint shall
1971 * - enter the SHUTDOWN-RECEIVED state,
1973 * - stop accepting new data from its SCTP user
1975 * - verify, by checking the Cumulative TSN Ack field of the chunk,
1976 * that all its outstanding DATA chunks have been received by the
1977 * SHUTDOWN sender.
1979 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
1980 * send a SHUTDOWN in response to a ULP request. And should discard
1981 * subsequent SHUTDOWN chunks.
1983 * If there are still outstanding DATA chunks left, the SHUTDOWN
1984 * receiver shall continue to follow normal data transmission
1985 * procedures defined in Section 6 until all outstanding DATA chunks
1986 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
1987 * new data from its SCTP user.
1989 * Verification Tag: 8.5 Verification Tag [Normal verification]
1991 * Inputs
1992 * (endpoint, asoc, chunk)
1994 * Outputs
1995 * (asoc, reply_msg, msg_up, timers, counters)
1997 * The return value is the disposition of the chunk.
1999 sctp_disposition_t sctp_sf_do_9_2_shutdown(const sctp_endpoint_t *ep,
2000 const sctp_association_t *asoc,
2001 const sctp_subtype_t type,
2002 void *arg,
2003 sctp_cmd_seq_t *commands)
2005 sctp_chunk_t *chunk = arg;
2006 sctp_shutdownhdr_t *sdh;
2007 sctp_disposition_t disposition;
2009 /* Convert the elaborate header. */
2010 sdh = (sctp_shutdownhdr_t *)chunk->skb->data;
2011 skb_pull(chunk->skb, sizeof(sctp_shutdownhdr_t));
2012 chunk->subh.shutdown_hdr = sdh;
2014 /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
2015 * that the value in the Verification Tag field of the
2016 * received SCTP packet matches its own Tag. If the received
2017 * Verification Tag value does not match the receiver's own
2018 * tag value, the receiver shall silently discard the packet...
2020 if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
2021 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2023 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2024 * - enter the SHUTDOWN-RECEIVED state,
2025 * - stop accepting new data from its SCTP user
2027 * [This is implicit in the new state.]
2029 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2030 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED));
2031 disposition = SCTP_DISPOSITION_CONSUME;
2033 if (sctp_outqueue_is_empty(&asoc->outqueue)) {
2034 disposition = sctp_sf_do_9_2_shutdown_ack(ep, asoc, type,
2035 arg, commands);
2038 /* - verify, by checking the Cumulative TSN Ack field of the
2039 * chunk, that all its outstanding DATA chunks have been
2040 * received by the SHUTDOWN sender.
2042 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
2043 SCTP_U32(chunk->subh.shutdown_hdr->cum_tsn_ack));
2044 return disposition;
2047 /* RFC 2960 9.2
2048 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2049 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2050 * transport addresses (either in the IP addresses or in the INIT chunk)
2051 * that belong to this association, it should discard the INIT chunk and
2052 * retransmit the SHUTDOWN ACK chunk.
2054 sctp_disposition_t sctp_sf_do_9_2_reshutack(const sctp_endpoint_t *ep,
2055 const sctp_association_t *asoc,
2056 const sctp_subtype_t type,
2057 void *arg,
2058 sctp_cmd_seq_t *commands)
2060 sctp_chunk_t *chunk = (sctp_chunk_t *) arg;
2061 sctp_chunk_t *reply;
2063 reply = sctp_make_shutdown_ack(asoc, chunk);
2064 if (NULL == reply)
2065 goto nomem;
2067 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2068 * the T2-SHUTDOWN timer.
2070 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
2072 /* and restart the T2-shutdown timer. */
2073 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2074 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2076 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2078 return SCTP_DISPOSITION_CONSUME;
2079 nomem:
2080 return SCTP_DISPOSITION_NOMEM;
2084 * sctp_sf_do_ecn_cwr
2086 * Section: Appendix A: Explicit Congestion Notification
2088 * CWR:
2090 * RFC 2481 details a specific bit for a sender to send in the header of
2091 * its next outbound TCP segment to indicate to its peer that it has
2092 * reduced its congestion window. This is termed the CWR bit. For
2093 * SCTP the same indication is made by including the CWR chunk.
2094 * This chunk contains one data element, i.e. the TSN number that
2095 * was sent in the ECNE chunk. This element represents the lowest
2096 * TSN number in the datagram that was originally marked with the
2097 * CE bit.
2099 * Verification Tag: 8.5 Verification Tag [Normal verification]
2100 * Inputs
2101 * (endpoint, asoc, chunk)
2103 * Outputs
2104 * (asoc, reply_msg, msg_up, timers, counters)
2106 * The return value is the disposition of the chunk.
2108 sctp_disposition_t sctp_sf_do_ecn_cwr(const sctp_endpoint_t *ep,
2109 const sctp_association_t *asoc,
2110 const sctp_subtype_t type,
2111 void *arg,
2112 sctp_cmd_seq_t *commands)
2114 sctp_cwrhdr_t *cwr;
2115 sctp_chunk_t *chunk = arg;
2117 /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
2118 * that the value in the Verification Tag field of the
2119 * received SCTP packet matches its own Tag. If the received
2120 * Verification Tag value does not match the receiver's own
2121 * tag value, the receiver shall silently discard the packet...
2123 if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
2124 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2126 cwr = (sctp_cwrhdr_t *) chunk->skb->data;
2127 skb_pull(chunk->skb, sizeof(sctp_cwrhdr_t));
2129 cwr->lowest_tsn = ntohl(cwr->lowest_tsn);
2131 /* Does this CWR ack the last sent congestion notification? */
2132 if (TSN_lte(asoc->last_ecne_tsn, cwr->lowest_tsn)) {
2133 /* Stop sending ECNE. */
2134 sctp_add_cmd_sf(commands,
2135 SCTP_CMD_ECN_CWR,
2136 SCTP_U32(cwr->lowest_tsn));
2138 return SCTP_DISPOSITION_CONSUME;
2142 * sctp_sf_do_ecne
2144 * Section: Appendix A: Explicit Congestion Notification
2146 * ECN-Echo
2148 * RFC 2481 details a specific bit for a receiver to send back in its
2149 * TCP acknowledgements to notify the sender of the Congestion
2150 * Experienced (CE) bit having arrived from the network. For SCTP this
2151 * same indication is made by including the ECNE chunk. This chunk
2152 * contains one data element, i.e. the lowest TSN associated with the IP
2153 * datagram marked with the CE bit.....
2155 * Verification Tag: 8.5 Verification Tag [Normal verification]
2156 * Inputs
2157 * (endpoint, asoc, chunk)
2159 * Outputs
2160 * (asoc, reply_msg, msg_up, timers, counters)
2162 * The return value is the disposition of the chunk.
2164 sctp_disposition_t sctp_sf_do_ecne(const sctp_endpoint_t *ep,
2165 const sctp_association_t *asoc,
2166 const sctp_subtype_t type,
2167 void *arg,
2168 sctp_cmd_seq_t *commands)
2170 sctp_ecnehdr_t *ecne;
2171 sctp_chunk_t *chunk = arg;
2173 /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
2174 * that the value in the Verification Tag field of the
2175 * received SCTP packet matches its own Tag. If the received
2176 * Verification Tag value does not match the receiver's own
2177 * tag value, the receiver shall silently discard the packet...
2179 if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
2180 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2182 ecne = (sctp_ecnehdr_t *) chunk->skb->data;
2183 skb_pull(chunk->skb, sizeof(sctp_ecnehdr_t));
2185 /* If this is a newer ECNE than the last CWR packet we sent out */
2186 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE,
2187 SCTP_U32(ntohl(ecne->lowest_tsn)));
2189 return SCTP_DISPOSITION_CONSUME;
2193 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2195 * The SCTP endpoint MUST always acknowledge the reception of each valid
2196 * DATA chunk.
2198 * The guidelines on delayed acknowledgement algorithm specified in
2199 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2200 * acknowledgement SHOULD be generated for at least every second packet
2201 * (not every second DATA chunk) received, and SHOULD be generated within
2202 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2203 * situations it may be beneficial for an SCTP transmitter to be more
2204 * conservative than the algorithms detailed in this document allow.
2205 * However, an SCTP transmitter MUST NOT be more aggressive than the
2206 * following algorithms allow.
2208 * A SCTP receiver MUST NOT generate more than one SACK for every
2209 * incoming packet, other than to update the offered window as the
2210 * receiving application consumes new data.
2212 * Verification Tag: 8.5 Verification Tag [Normal verification]
2214 * Inputs
2215 * (endpoint, asoc, chunk)
2217 * Outputs
2218 * (asoc, reply_msg, msg_up, timers, counters)
2220 * The return value is the disposition of the chunk.
2222 sctp_disposition_t sctp_sf_eat_data_6_2(const sctp_endpoint_t *ep,
2223 const sctp_association_t *asoc,
2224 const sctp_subtype_t type,
2225 void *arg,
2226 sctp_cmd_seq_t *commands)
2228 sctp_chunk_t *chunk = arg;
2229 sctp_datahdr_t *data_hdr;
2230 sctp_chunk_t *err;
2231 size_t datalen;
2232 int tmp;
2233 __u32 tsn;
2235 /* RFC 2960 8.5 Verification Tag
2237 * When receiving an SCTP packet, the endpoint MUST ensure
2238 * that the value in the Verification Tag field of the
2239 * received SCTP packet matches its own Tag.
2242 if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag) {
2243 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2244 SCTP_NULL());
2245 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2248 data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *)chunk->skb->data;
2249 skb_pull(chunk->skb, sizeof(sctp_datahdr_t));
2251 tsn = ntohl(data_hdr->tsn);
2253 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn);
2254 SCTP_DEBUG_PRINTK("eat_data: skb->head %p.\n", chunk->skb->head);
2256 /* ASSERT: Now skb->data is really the user data. */
2258 /* Process ECN based congestion.
2260 * Since the chunk structure is reused for all chunks within
2261 * a packet, we use ecn_ce_done to track if we've already
2262 * done CE processing for this packet.
2264 * We need to do ECN processing even if we plan to discard the
2265 * chunk later.
2268 if (!chunk->ecn_ce_done) {
2269 chunk->ecn_ce_done = 1;
2270 if (INET_ECN_is_ce(chunk->skb->nh.iph->tos) &&
2271 asoc->peer.ecn_capable) {
2272 /* Do real work as sideffect. */
2273 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
2274 SCTP_U32(tsn));
2278 tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
2279 if (tmp < 0) {
2280 /* The TSN is too high--silently discard the chunk and
2281 * count on it getting retransmitted later.
2283 goto discard_noforce;
2284 } else if (tmp > 0) {
2285 /* This is a duplicate. Record it. */
2286 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
2287 goto discard_force;
2290 /* This is a new TSN. */
2292 /* Discard if there is no room in the receive window.
2293 * Actually, allow a little bit of overflow (up to a MTU).
2295 datalen = ntohs(chunk->chunk_hdr->length);
2296 datalen -= sizeof(sctp_data_chunk_t);
2298 if (asoc->rwnd_over || (datalen > asoc->rwnd + asoc->frag_point)) {
2299 SCTP_DEBUG_PRINTK("Discarding tsn: %u datalen: %Zd, "
2300 "rwnd: %d\n", tsn, datalen, asoc->rwnd);
2301 goto discard_force;
2305 * Section 3.3.10.9 No User Data (9)
2307 * Cause of error
2308 * ---------------
2309 * No User Data: This error cause is returned to the originator of a
2310 * DATA chunk if a received DATA chunk has no user data.
2312 if (unlikely(0 == datalen)) {
2313 err = sctp_make_abort_no_data(asoc, chunk, tsn);
2314 if (err) {
2315 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
2316 SCTP_CHUNK(err));
2318 /* We are going to ABORT, so we might as well stop
2319 * processing the rest of the chunks in the packet.
2321 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
2322 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_NULL());
2323 return SCTP_DISPOSITION_CONSUME;
2326 /* We are accepting this DATA chunk. */
2328 /* Record the fact that we have received this TSN. */
2329 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
2331 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
2333 * If an endpoint receive a DATA chunk with an invalid stream
2334 * identifier, it shall acknowledge the reception of the DATA chunk
2335 * following the normal procedure, immediately send an ERROR chunk
2336 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
2337 * and discard the DATA chunk.
2339 if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) {
2340 err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
2341 &data_hdr->stream,
2342 sizeof(data_hdr->stream));
2343 if (err) {
2344 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
2345 SCTP_CHUNK(err));
2347 goto discard_noforce;
2350 /* Send the data up to the user. Note: Schedule the
2351 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
2352 * chunk needs the updated rwnd.
2354 sctp_add_cmd_sf(commands, SCTP_CMD_CHUNK_ULP, SCTP_CHUNK(chunk));
2355 if (asoc->autoclose) {
2356 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2357 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
2360 /* If this is the last chunk in a packet, we need to count it
2361 * toward sack generation. Note that we need to SACK every
2362 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2363 * THEM. We elect to NOT generate SACK's if the chunk fails
2364 * the verification tag test.
2366 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2368 * The SCTP endpoint MUST always acknowledge the reception of
2369 * each valid DATA chunk.
2371 * The guidelines on delayed acknowledgement algorithm
2372 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2373 * Specifically, an acknowledgement SHOULD be generated for at
2374 * least every second packet (not every second DATA chunk)
2375 * received, and SHOULD be generated within 200 ms of the
2376 * arrival of any unacknowledged DATA chunk. In some
2377 * situations it may be beneficial for an SCTP transmitter to
2378 * be more conservative than the algorithms detailed in this
2379 * document allow. However, an SCTP transmitter MUST NOT be
2380 * more aggressive than the following algorithms allow.
2382 if (chunk->end_of_packet) {
2383 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2385 /* Start the SACK timer. */
2386 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2387 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
2390 return SCTP_DISPOSITION_CONSUME;
2392 discard_force:
2393 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2395 * When a packet arrives with duplicate DATA chunk(s) and with
2396 * no new DATA chunk(s), the endpoint MUST immediately send a
2397 * SACK with no delay. If a packet arrives with duplicate
2398 * DATA chunk(s) bundled with new DATA chunks, the endpoint
2399 * MAY immediately send a SACK. Normally receipt of duplicate
2400 * DATA chunks will occur when the original SACK chunk was lost
2401 * and the peer's RTO has expired. The duplicate TSN number(s)
2402 * SHOULD be reported in the SACK as duplicate.
2404 /* In our case, we split the MAY SACK advice up whether or not
2405 * the last chunk is a duplicate.'
2407 if (chunk->end_of_packet)
2408 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2409 return SCTP_DISPOSITION_DISCARD;
2411 discard_noforce:
2412 if (chunk->end_of_packet) {
2413 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2415 /* Start the SACK timer. */
2416 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2417 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
2419 return SCTP_DISPOSITION_DISCARD;
2423 * sctp_sf_eat_data_fast_4_4
2425 * Section: 4 (4)
2426 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
2427 * DATA chunks without delay.
2429 * Verification Tag: 8.5 Verification Tag [Normal verification]
2430 * Inputs
2431 * (endpoint, asoc, chunk)
2433 * Outputs
2434 * (asoc, reply_msg, msg_up, timers, counters)
2436 * The return value is the disposition of the chunk.
2438 sctp_disposition_t sctp_sf_eat_data_fast_4_4(const sctp_endpoint_t *ep,
2439 const sctp_association_t *asoc,
2440 const sctp_subtype_t type,
2441 void *arg,
2442 sctp_cmd_seq_t *commands)
2444 sctp_chunk_t *chunk = arg;
2445 sctp_datahdr_t *data_hdr;
2446 sctp_chunk_t *err;
2447 size_t datalen;
2448 int tmp;
2449 __u32 tsn;
2451 /* RFC 2960 8.5 Verification Tag
2453 * When receiving an SCTP packet, the endpoint MUST ensure
2454 * that the value in the Verification Tag field of the
2455 * received SCTP packet matches its own Tag.
2457 if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag) {
2458 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2459 SCTP_NULL());
2460 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2463 data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *) chunk->skb->data;
2464 skb_pull(chunk->skb, sizeof(sctp_datahdr_t));
2466 tsn = ntohl(data_hdr->tsn);
2468 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn);
2470 /* ASSERT: Now skb->data is really the user data. */
2472 /* Process ECN based congestion.
2474 * Since the chunk structure is reused for all chunks within
2475 * a packet, we use ecn_ce_done to track if we've already
2476 * done CE processing for this packet.
2478 * We need to do ECN processing even if we plan to discard the
2479 * chunk later.
2481 if (!chunk->ecn_ce_done) {
2482 chunk->ecn_ce_done = 1;
2483 if (INET_ECN_is_ce(chunk->skb->nh.iph->tos) &&
2484 asoc->peer.ecn_capable) {
2485 /* Do real work as sideffect. */
2486 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
2487 SCTP_U32(tsn));
2491 tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
2492 if (tmp < 0) {
2493 /* The TSN is too high--silently discard the chunk and
2494 * count on it getting retransmitted later.
2496 goto gen_shutdown;
2497 } else if (tmp > 0) {
2498 /* This is a duplicate. Record it. */
2499 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
2500 goto gen_shutdown;
2503 /* This is a new TSN. */
2505 datalen = ntohs(chunk->chunk_hdr->length);
2506 datalen -= sizeof(sctp_data_chunk_t);
2509 * Section 3.3.10.9 No User Data (9)
2511 * Cause of error
2512 * ---------------
2513 * No User Data: This error cause is returned to the originator of a
2514 * DATA chunk if a received DATA chunk has no user data.
2516 if (unlikely(0 == datalen)) {
2517 err = sctp_make_abort_no_data(asoc, chunk, tsn);
2518 if (err) {
2519 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
2520 SCTP_CHUNK(err));
2522 /* We are going to ABORT, so we might as well stop
2523 * processing the rest of the chunks in the packet.
2525 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
2526 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_NULL());
2527 return SCTP_DISPOSITION_CONSUME;
2530 /* We are accepting this DATA chunk. */
2532 /* Record the fact that we have received this TSN. */
2533 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
2535 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
2537 * If an endpoint receive a DATA chunk with an invalid stream
2538 * identifier, it shall acknowledge the reception of the DATA chunk
2539 * following the normal procedure, immediately send an ERROR chunk
2540 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
2541 * and discard the DATA chunk.
2543 if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) {
2544 err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
2545 &data_hdr->stream,
2546 sizeof(data_hdr->stream));
2547 if (err) {
2548 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
2549 SCTP_CHUNK(err));
2553 /* Go a head and force a SACK, since we are shutting down. */
2554 gen_shutdown:
2555 /* Implementor's Guide.
2557 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
2558 * respond to each received packet containing one or more DATA chunk(s)
2559 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
2561 if (chunk->end_of_packet) {
2562 /* We must delay the chunk creation since the cumulative
2563 * TSN has not been updated yet.
2565 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
2566 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2567 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2568 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2570 return SCTP_DISPOSITION_CONSUME;
2574 * Section: 6.2 Processing a Received SACK
2575 * D) Any time a SACK arrives, the endpoint performs the following:
2577 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
2578 * then drop the SACK. Since Cumulative TSN Ack is monotonically
2579 * increasing, a SACK whose Cumulative TSN Ack is less than the
2580 * Cumulative TSN Ack Point indicates an out-of-order SACK.
2582 * ii) Set rwnd equal to the newly received a_rwnd minus the number
2583 * of bytes still outstanding after processing the Cumulative TSN Ack
2584 * and the Gap Ack Blocks.
2586 * iii) If the SACK is missing a TSN that was previously
2587 * acknowledged via a Gap Ack Block (e.g., the data receiver
2588 * reneged on the data), then mark the corresponding DATA chunk
2589 * as available for retransmit: Mark it as missing for fast
2590 * retransmit as described in Section 7.2.4 and if no retransmit
2591 * timer is running for the destination address to which the DATA
2592 * chunk was originally transmitted, then T3-rtx is started for
2593 * that destination address.
2595 * Verification Tag: 8.5 Verification Tag [Normal verification]
2597 * Inputs
2598 * (endpoint, asoc, chunk)
2600 * Outputs
2601 * (asoc, reply_msg, msg_up, timers, counters)
2603 * The return value is the disposition of the chunk.
2605 sctp_disposition_t sctp_sf_eat_sack_6_2(const sctp_endpoint_t *ep,
2606 const sctp_association_t *asoc,
2607 const sctp_subtype_t type,
2608 void *arg,
2609 sctp_cmd_seq_t *commands)
2611 sctp_chunk_t *chunk = arg;
2612 sctp_sackhdr_t *sackh;
2613 __u32 ctsn;
2615 /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
2616 * that the value in the Verification Tag field of the
2617 * received SCTP packet matches its own Tag. ...
2619 if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
2620 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2622 /* Pull the SACK chunk from the data buffer */
2623 sackh = sctp_sm_pull_sack(chunk);
2624 chunk->subh.sack_hdr = sackh;
2625 ctsn = ntohl(sackh->cum_tsn_ack);
2627 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
2628 * Ack Point, then drop the SACK. Since Cumulative TSN
2629 * Ack is monotonically increasing, a SACK whose
2630 * Cumulative TSN Ack is less than the Cumulative TSN Ack
2631 * Point indicates an out-of-order SACK.
2633 if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
2634 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn);
2635 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc->ctsn_ack_point);
2636 return SCTP_DISPOSITION_DISCARD;
2639 /* Return this SACK for further processing. */
2640 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_SACKH(sackh));
2642 /* Note: We do the rest of the work on the PROCESS_SACK
2643 * sideeffect.
2645 return SCTP_DISPOSITION_CONSUME;
2649 * Generate an ABORT in response to a packet.
2651 * Section: 8.4 Handle "Out of the blue" Packets
2653 * 8) The receiver should respond to the sender of the OOTB packet
2654 * with an ABORT. When sending the ABORT, the receiver of the
2655 * OOTB packet MUST fill in the Verification Tag field of the
2656 * outbound packet with the value found in the Verification Tag
2657 * field of the OOTB packet and set the T-bit in the Chunk Flags
2658 * to indicate that no TCB was found. After sending this ABORT,
2659 * the receiver of the OOTB packet shall discard the OOTB packet
2660 * and take no further action.
2662 * Verification Tag:
2664 * The return value is the disposition of the chunk.
2666 sctp_disposition_t sctp_sf_tabort_8_4_8(const sctp_endpoint_t *ep,
2667 const sctp_association_t *asoc,
2668 const sctp_subtype_t type,
2669 void *arg,
2670 sctp_cmd_seq_t *commands)
2672 sctp_packet_t *packet = NULL;
2673 sctp_chunk_t *chunk = arg;
2674 sctp_chunk_t *abort;
2676 packet = sctp_ootb_pkt_new(asoc, chunk);
2678 if (packet) {
2679 /* Make an ABORT. The T bit will be set if the asoc
2680 * is NULL.
2682 abort = sctp_make_abort(asoc, chunk, 0);
2683 if (!abort) {
2684 sctp_ootb_pkt_free(packet);
2685 return SCTP_DISPOSITION_NOMEM;
2688 /* Set the skb to the belonging sock for accounting. */
2689 abort->skb->sk = ep->base.sk;
2691 sctp_packet_append_chunk(packet, abort);
2693 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
2694 SCTP_PACKET(packet));
2696 return SCTP_DISPOSITION_CONSUME;
2699 return SCTP_DISPOSITION_NOMEM;
2703 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
2704 * event as ULP notification for each cause included in the chunk.
2706 * API 5.3.1.3 - SCTP_REMOTE_ERROR
2708 * The return value is the disposition of the chunk.
2710 sctp_disposition_t sctp_sf_operr_notify(const sctp_endpoint_t *ep,
2711 const sctp_association_t *asoc,
2712 const sctp_subtype_t type,
2713 void *arg,
2714 sctp_cmd_seq_t *commands)
2716 sctp_chunk_t *chunk = arg;
2717 sctp_ulpevent_t *ev;
2719 while (chunk->chunk_end > chunk->skb->data) {
2720 ev = sctp_ulpevent_make_remote_error(asoc, chunk, 0,
2721 GFP_ATOMIC);
2722 if (!ev)
2723 goto nomem;
2725 if (!sctp_add_cmd(commands, SCTP_CMD_EVENT_ULP,
2726 SCTP_ULPEVENT(ev))) {
2727 sctp_ulpevent_free(ev);
2728 goto nomem;
2731 return SCTP_DISPOSITION_CONSUME;
2733 nomem:
2734 return SCTP_DISPOSITION_NOMEM;
2738 * Process an inbound SHUTDOWN ACK.
2740 * From Section 9.2:
2741 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
2742 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
2743 * peer, and remove all record of the association.
2745 * The return value is the disposition.
2747 sctp_disposition_t sctp_sf_do_9_2_final(const sctp_endpoint_t *ep,
2748 const sctp_association_t *asoc,
2749 const sctp_subtype_t type,
2750 void *arg,
2751 sctp_cmd_seq_t *commands)
2753 sctp_chunk_t *chunk = arg;
2754 sctp_chunk_t *reply;
2755 sctp_ulpevent_t *ev;
2757 /* 10.2 H) SHUTDOWN COMPLETE notification
2759 * When SCTP completes the shutdown procedures (section 9.2) this
2760 * notification is passed to the upper layer.
2762 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
2763 0, 0, 0, GFP_ATOMIC);
2764 if (!ev)
2765 goto nomem;
2767 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
2769 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
2770 * stop the T2-shutdown timer,
2772 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2773 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2775 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2776 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
2778 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
2779 reply = sctp_make_shutdown_complete(asoc, chunk);
2780 if (!reply)
2781 goto nomem;
2783 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2784 SCTP_STATE(SCTP_STATE_CLOSED));
2785 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2787 /* ...and remove all record of the association. */
2788 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
2789 return SCTP_DISPOSITION_DELETE_TCB;
2791 nomem:
2792 return SCTP_DISPOSITION_NOMEM;
2796 * RFC 2960, 8.4 - Handle "Out of the blue" Packets
2797 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
2798 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
2799 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
2800 * packet must fill in the Verification Tag field of the outbound
2801 * packet with the Verification Tag received in the SHUTDOWN ACK and
2802 * set the T-bit in the Chunk Flags to indicate that no TCB was
2803 * found. Otherwise,
2805 * 8) The receiver should respond to the sender of the OOTB packet with
2806 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
2807 * MUST fill in the Verification Tag field of the outbound packet
2808 * with the value found in the Verification Tag field of the OOTB
2809 * packet and set the T-bit in the Chunk Flags to indicate that no
2810 * TCB was found. After sending this ABORT, the receiver of the OOTB
2811 * packet shall discard the OOTB packet and take no further action.
2813 sctp_disposition_t sctp_sf_ootb(const sctp_endpoint_t *ep,
2814 const sctp_association_t *asoc,
2815 const sctp_subtype_t type,
2816 void *arg,
2817 sctp_cmd_seq_t *commands)
2819 sctp_chunk_t *chunk = arg;
2820 struct sk_buff *skb = chunk->skb;
2821 sctp_chunkhdr_t *ch;
2822 __u8 *ch_end;
2823 int ootb_shut_ack = 0;
2825 ch = (sctp_chunkhdr_t *) chunk->chunk_hdr;
2826 do {
2827 ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length));
2829 if (SCTP_CID_SHUTDOWN_ACK == ch->type)
2830 ootb_shut_ack = 1;
2832 ch = (sctp_chunkhdr_t *) ch_end;
2833 } while (ch_end < skb->tail);
2835 if (ootb_shut_ack)
2836 sctp_sf_shut_8_4_5(ep, asoc, type, arg, commands);
2837 else
2838 sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
2840 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2844 * Handle an "Out of the blue" SHUTDOWN ACK.
2846 * Section: 8.4 5)
2847 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
2848 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
2849 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB packet
2850 * must fill in the Verification Tag field of the outbound packet with
2851 * the Verification Tag received in the SHUTDOWN ACK and set the
2852 * T-bit in the Chunk Flags to indicate that no TCB was found.
2854 * Inputs
2855 * (endpoint, asoc, type, arg, commands)
2857 * Outputs
2858 * (sctp_disposition_t)
2860 * The return value is the disposition of the chunk.
2862 sctp_disposition_t sctp_sf_shut_8_4_5(const sctp_endpoint_t *ep,
2863 const sctp_association_t *asoc,
2864 const sctp_subtype_t type,
2865 void *arg,
2866 sctp_cmd_seq_t *commands)
2868 sctp_packet_t *packet = NULL;
2869 sctp_chunk_t *chunk = arg;
2870 sctp_chunk_t *shut;
2872 packet = sctp_ootb_pkt_new(asoc, chunk);
2874 if (packet) {
2875 /* Make an SHUTDOWN_COMPLETE.
2876 * The T bit will be set if the asoc is NULL.
2878 shut = sctp_make_shutdown_complete(asoc, chunk);
2879 if (!shut) {
2880 sctp_ootb_pkt_free(packet);
2881 return SCTP_DISPOSITION_NOMEM;
2884 /* Set the skb to the belonging sock for accounting. */
2885 shut->skb->sk = ep->base.sk;
2887 sctp_packet_append_chunk(packet, shut);
2889 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
2890 SCTP_PACKET(packet));
2892 return SCTP_DISPOSITION_CONSUME;
2895 return SCTP_DISPOSITION_NOMEM;
2899 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
2901 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
2902 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
2903 * procedures in section 8.4 SHOULD be followed, in other words it
2904 * should be treated as an Out Of The Blue packet.
2905 * [This means that we do NOT check the Verification Tag on these
2906 * chunks. --piggy ]
2909 sctp_disposition_t sctp_sf_do_8_5_1_E_sa(const sctp_endpoint_t *ep,
2910 const sctp_association_t *asoc,
2911 const sctp_subtype_t type,
2912 void *arg,
2913 sctp_cmd_seq_t *commands)
2915 /* Although we do have an association in this case, it corresponds
2916 * to a restarted association. So the packet is treated as an OOTB
2917 * packet and the state function that handles OOTB SHUTDOWN_ACK is
2918 * called with a NULL association.
2920 return sctp_sf_shut_8_4_5(ep, NULL, type, arg, commands);
2924 * Process an unknown chunk.
2926 * Section: 3.2. Also, 2.1 in the implementor's guide.
2928 * Chunk Types are encoded such that the highest-order two bits specify
2929 * the action that must be taken if the processing endpoint does not
2930 * recognize the Chunk Type.
2932 * 00 - Stop processing this SCTP packet and discard it, do not process
2933 * any further chunks within it.
2935 * 01 - Stop processing this SCTP packet and discard it, do not process
2936 * any further chunks within it, and report the unrecognized
2937 * chunk in an 'Unrecognized Chunk Type'.
2939 * 10 - Skip this chunk and continue processing.
2941 * 11 - Skip this chunk and continue processing, but report in an ERROR
2942 * Chunk using the 'Unrecognized Chunk Type' cause of error.
2944 * The return value is the disposition of the chunk.
2946 sctp_disposition_t sctp_sf_unk_chunk(const sctp_endpoint_t *ep,
2947 const sctp_association_t *asoc,
2948 const sctp_subtype_t type,
2949 void *arg,
2950 sctp_cmd_seq_t *commands)
2952 sctp_chunk_t *unk_chunk = arg;
2953 sctp_chunk_t *err_chunk;
2954 sctp_chunkhdr_t *hdr;
2956 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type.chunk);
2958 /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
2959 * that the value in the Verification Tag field of the
2960 * received SCTP packet matches its own Tag. If the received
2961 * Verification Tag value does not match the receiver's own
2962 * tag value, the receiver shall silently discard the packet.
2964 if (ntohl(unk_chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
2965 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2967 switch (type.chunk & SCTP_CID_ACTION_MASK) {
2968 case SCTP_CID_ACTION_DISCARD:
2969 /* Discard the packet. */
2970 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2971 break;
2972 case SCTP_CID_ACTION_DISCARD_ERR:
2973 /* Discard the packet. */
2974 sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2976 /* Generate an ERROR chunk as response. */
2977 hdr = unk_chunk->chunk_hdr;
2978 err_chunk = sctp_make_op_error(asoc, unk_chunk,
2979 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
2980 WORD_ROUND(ntohs(hdr->length)));
2981 if (err_chunk) {
2982 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
2983 SCTP_CHUNK(err_chunk));
2985 return SCTP_DISPOSITION_CONSUME;
2986 break;
2987 case SCTP_CID_ACTION_SKIP:
2988 /* Skip the chunk. */
2989 return SCTP_DISPOSITION_DISCARD;
2990 break;
2991 case SCTP_CID_ACTION_SKIP_ERR:
2992 /* Generate an ERROR chunk as response. */
2993 hdr = unk_chunk->chunk_hdr;
2994 err_chunk = sctp_make_op_error(asoc, unk_chunk,
2995 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
2996 WORD_ROUND(ntohs(hdr->length)));
2997 if (err_chunk) {
2998 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
2999 SCTP_CHUNK(err_chunk));
3001 /* Skip the chunk. */
3002 return SCTP_DISPOSITION_CONSUME;
3003 break;
3004 default:
3005 break;
3008 return SCTP_DISPOSITION_DISCARD;
3012 * Discard the chunk.
3014 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
3015 * [Too numerous to mention...]
3016 * Verification Tag: No verification needed.
3017 * Inputs
3018 * (endpoint, asoc, chunk)
3020 * Outputs
3021 * (asoc, reply_msg, msg_up, timers, counters)
3023 * The return value is the disposition of the chunk.
3025 sctp_disposition_t sctp_sf_discard_chunk(const sctp_endpoint_t *ep,
3026 const sctp_association_t *asoc,
3027 const sctp_subtype_t type,
3028 void *arg,
3029 sctp_cmd_seq_t *commands)
3031 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type.chunk);
3032 return SCTP_DISPOSITION_DISCARD;
3036 * Discard the whole packet.
3038 * Section: 8.4 2)
3040 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
3041 * silently discard the OOTB packet and take no further action.
3042 * Otherwise,
3044 * Verification Tag: No verification necessary
3046 * Inputs
3047 * (endpoint, asoc, chunk)
3049 * Outputs
3050 * (asoc, reply_msg, msg_up, timers, counters)
3052 * The return value is the disposition of the chunk.
3054 sctp_disposition_t sctp_sf_pdiscard(const sctp_endpoint_t *ep,
3055 const sctp_association_t *asoc,
3056 const sctp_subtype_t type,
3057 void *arg,
3058 sctp_cmd_seq_t *commands)
3060 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
3062 return SCTP_DISPOSITION_CONSUME;
3065 #if 0
3067 * We did something stupid but got lucky. Namely, we sent a HEARTBEAT
3068 * before the association was all the way up and we did NOT get an
3069 * ABORT.
3071 * Log the fact and then process normally.
3073 * Section: Not specified
3074 * Verification Tag: 8.5 Verification Tag [Normal verification]
3075 * Inputs
3076 * (endpoint, asoc, chunk)
3078 * Outputs
3079 * (asoc, reply_msg, msg_up, timers, counters)
3081 * The return value is the disposition of the chunk.
3083 sctp_disposition_t lucky(const sctp_endpoint_t *ep,
3084 const sctp_association_t *asoc,
3085 const sctp_subtype_t type,
3086 void *arg,
3087 sctp_cmd_seq_t *commands)
3089 sctp_chunk_t *chunk = arg;
3091 /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
3092 * that the value in the Verification Tag field of the
3093 * received SCTP packet matches its own Tag. ...
3095 if (chunk->sctp_hdr->vtag != asoc->c.my_vtag)
3096 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3098 return SCTP_DISPOSITION_CONSUME;
3100 nomem:
3101 return SCTP_DISPOSITION_NOMEM;
3103 #endif /* 0 */
3105 #if 0
3107 * The other end is doing something very stupid. We'll ignore them
3108 * after logging their idiocy. :-)
3110 * Section: Not specified
3111 * Verification Tag: 8.5 Verification Tag [Normal verification]
3112 * Inputs
3113 * (endpoint, asoc, chunk)
3115 * Outputs
3116 * (asoc, reply_msg, msg_up, timers, counters)
3118 * The return value is the disposition of the chunk.
3120 sctp_disposition_t other_stupid(const sctp_endpoint_t *ep,
3121 const sctp_association_t *asoc,
3122 const sctp_subtype_t type,
3123 void *arg,
3124 sctp_cmd_seq_t *commands)
3126 sctp_chunk_t *chunk = arg;
3128 /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
3129 * that the value in the Verification Tag field of the
3130 * received SCTP packet matches its own Tag. ...
3132 if (chunk->sctp_hdr->vtag != asoc->c.my_vtag)
3133 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3135 return SCTP_DISPOSITION_CONSUME;
3137 nomem:
3138 return SCTP_DISPOSITION_NOMEM;
3140 #endif /* 0 */
3143 * The other end is violating protocol.
3145 * Section: Not specified
3146 * Verification Tag: Not specified
3147 * Inputs
3148 * (endpoint, asoc, chunk)
3150 * Outputs
3151 * (asoc, reply_msg, msg_up, timers, counters)
3153 * We simply tag the chunk as a violation. The state machine will log
3154 * the violation and continue.
3156 sctp_disposition_t sctp_sf_violation(const sctp_endpoint_t *ep,
3157 const sctp_association_t *asoc,
3158 const sctp_subtype_t type,
3159 void *arg,
3160 sctp_cmd_seq_t *commands)
3162 return SCTP_DISPOSITION_VIOLATION;
3165 /***************************************************************************
3166 * These are the state functions for handling primitive (Section 10) events.
3167 ***************************************************************************/
3169 * sctp_sf_do_prm_asoc
3171 * Section: 10.1 ULP-to-SCTP
3172 * B) Associate
3174 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
3175 * outbound stream count)
3176 * -> association id [,destination transport addr list] [,outbound stream
3177 * count]
3179 * This primitive allows the upper layer to initiate an association to a
3180 * specific peer endpoint.
3182 * The peer endpoint shall be specified by one of the transport addresses
3183 * which defines the endpoint (see Section 1.4). If the local SCTP
3184 * instance has not been initialized, the ASSOCIATE is considered an
3185 * error.
3186 * [This is not relevant for the kernel implementation since we do all
3187 * initialization at boot time. It we hadn't initialized we wouldn't
3188 * get anywhere near this code.]
3190 * An association id, which is a local handle to the SCTP association,
3191 * will be returned on successful establishment of the association. If
3192 * SCTP is not able to open an SCTP association with the peer endpoint,
3193 * an error is returned.
3194 * [In the kernel implementation, the sctp_association_t needs to
3195 * be created BEFORE causing this primitive to run.]
3197 * Other association parameters may be returned, including the
3198 * complete destination transport addresses of the peer as well as the
3199 * outbound stream count of the local endpoint. One of the transport
3200 * address from the returned destination addresses will be selected by
3201 * the local endpoint as default primary path for sending SCTP packets
3202 * to this peer. The returned "destination transport addr list" can
3203 * be used by the ULP to change the default primary path or to force
3204 * sending a packet to a specific transport address. [All of this
3205 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
3206 * function.]
3208 * Mandatory attributes:
3210 * o local SCTP instance name - obtained from the INITIALIZE operation.
3211 * [This is the argument asoc.]
3212 * o destination transport addr - specified as one of the transport
3213 * addresses of the peer endpoint with which the association is to be
3214 * established.
3215 * [This is asoc->peer.active_path.]
3216 * o outbound stream count - the number of outbound streams the ULP
3217 * would like to open towards this peer endpoint.
3218 * [BUG: This is not currently implemented.]
3219 * Optional attributes:
3221 * None.
3223 * The return value is a disposition.
3225 sctp_disposition_t sctp_sf_do_prm_asoc(const sctp_endpoint_t *ep,
3226 const sctp_association_t *asoc,
3227 const sctp_subtype_t type,
3228 void *arg,
3229 sctp_cmd_seq_t *commands)
3231 sctp_chunk_t *repl;
3232 sctp_bind_addr_t *bp;
3233 sctp_scope_t scope;
3234 int error;
3235 int flags;
3237 /* The comment below says that we enter COOKIE-WAIT AFTER
3238 * sending the INIT, but that doesn't actually work in our
3239 * implementation...
3241 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3242 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
3244 /* Build up the bind address list for the association based on
3245 * info from the local endpoint and the remote peer.
3247 bp = sctp_bind_addr_new(GFP_ATOMIC);
3248 if (!bp)
3249 goto nomem;
3251 /* Use scoping rules to determine the subset of addresses from
3252 * the endpoint.
3254 scope = sctp_scope(&asoc->peer.active_path->ipaddr);
3255 flags = (PF_INET6 == asoc->base.sk->family) ? SCTP_ADDR6_ALLOWED : 0;
3256 if (asoc->peer.ipv4_address)
3257 flags |= SCTP_ADDR4_PEERSUPP;
3258 if (asoc->peer.ipv6_address)
3259 flags |= SCTP_ADDR6_PEERSUPP;
3260 error = sctp_bind_addr_copy(bp, &ep->base.bind_addr, scope,
3261 GFP_ATOMIC, flags);
3262 if (error)
3263 goto nomem;
3265 /* FIXME: Either move address assignment out of this function
3266 * or else move the association allocation/init into this function.
3267 * The association structure is brand new before calling this
3268 * function, so would not be a sideeffect if the allocation
3269 * moved into this function. --jgrimm
3271 sctp_add_cmd_sf(commands, SCTP_CMD_SET_BIND_ADDR, (sctp_arg_t) bp);
3273 /* RFC 2960 5.1 Normal Establishment of an Association
3275 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
3276 * must provide its Verification Tag (Tag_A) in the Initiate
3277 * Tag field. Tag_A SHOULD be a random number in the range of
3278 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
3281 repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0);
3282 if (!repl)
3283 goto nomem;
3285 /* Cast away the const modifier, as we want to just
3286 * rerun it through as a sideffect.
3288 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC,
3289 SCTP_ASOC((sctp_association_t *) asoc));
3291 /* After sending the INIT, "A" starts the T1-init timer and
3292 * enters the COOKIE-WAIT state.
3294 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
3295 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
3296 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
3297 return SCTP_DISPOSITION_CONSUME;
3299 nomem:
3300 if (bp)
3301 sctp_bind_addr_free(bp);
3303 return SCTP_DISPOSITION_NOMEM;
3307 * Process the SEND primitive.
3309 * Section: 10.1 ULP-to-SCTP
3310 * E) Send
3312 * Format: SEND(association id, buffer address, byte count [,context]
3313 * [,stream id] [,life time] [,destination transport address]
3314 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
3315 * -> result
3317 * This is the main method to send user data via SCTP.
3319 * Mandatory attributes:
3321 * o association id - local handle to the SCTP association
3323 * o buffer address - the location where the user message to be
3324 * transmitted is stored;
3326 * o byte count - The size of the user data in number of bytes;
3328 * Optional attributes:
3330 * o context - an optional 32 bit integer that will be carried in the
3331 * sending failure notification to the ULP if the transportation of
3332 * this User Message fails.
3334 * o stream id - to indicate which stream to send the data on. If not
3335 * specified, stream 0 will be used.
3337 * o life time - specifies the life time of the user data. The user data
3338 * will not be sent by SCTP after the life time expires. This
3339 * parameter can be used to avoid efforts to transmit stale
3340 * user messages. SCTP notifies the ULP if the data cannot be
3341 * initiated to transport (i.e. sent to the destination via SCTP's
3342 * send primitive) within the life time variable. However, the
3343 * user data will be transmitted if SCTP has attempted to transmit a
3344 * chunk before the life time expired.
3346 * o destination transport address - specified as one of the destination
3347 * transport addresses of the peer endpoint to which this packet
3348 * should be sent. Whenever possible, SCTP should use this destination
3349 * transport address for sending the packets, instead of the current
3350 * primary path.
3352 * o unorder flag - this flag, if present, indicates that the user
3353 * would like the data delivered in an unordered fashion to the peer
3354 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
3355 * message).
3357 * o no-bundle flag - instructs SCTP not to bundle this user data with
3358 * other outbound DATA chunks. SCTP MAY still bundle even when
3359 * this flag is present, when faced with network congestion.
3361 * o payload protocol-id - A 32 bit unsigned integer that is to be
3362 * passed to the peer indicating the type of payload protocol data
3363 * being transmitted. This value is passed as opaque data by SCTP.
3365 * The return value is the disposition.
3367 sctp_disposition_t sctp_sf_do_prm_send(const sctp_endpoint_t *ep,
3368 const sctp_association_t *asoc,
3369 const sctp_subtype_t type,
3370 void *arg,
3371 sctp_cmd_seq_t *commands)
3373 sctp_chunk_t *chunk = arg;
3375 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
3376 return SCTP_DISPOSITION_CONSUME;
3380 * Process the SHUTDOWN primitive.
3382 * Section: 10.1:
3383 * C) Shutdown
3385 * Format: SHUTDOWN(association id)
3386 * -> result
3388 * Gracefully closes an association. Any locally queued user data
3389 * will be delivered to the peer. The association will be terminated only
3390 * after the peer acknowledges all the SCTP packets sent. A success code
3391 * will be returned on successful termination of the association. If
3392 * attempting to terminate the association results in a failure, an error
3393 * code shall be returned.
3395 * Mandatory attributes:
3397 * o association id - local handle to the SCTP association
3399 * Optional attributes:
3401 * None.
3403 * The return value is the disposition.
3405 sctp_disposition_t sctp_sf_do_9_2_prm_shutdown(const sctp_endpoint_t *ep,
3406 const sctp_association_t *asoc,
3407 const sctp_subtype_t type,
3408 void *arg,
3409 sctp_cmd_seq_t *commands)
3411 int disposition;
3413 /* From 9.2 Shutdown of an Association
3414 * Upon receipt of the SHUTDOWN primitive from its upper
3415 * layer, the endpoint enters SHUTDOWN-PENDING state and
3416 * remains there until all outstanding data has been
3417 * acknowledged by its peer. The endpoint accepts no new data
3418 * from its upper layer, but retransmits data to the far end
3419 * if necessary to fill gaps.
3421 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3422 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
3424 /* sctpimpguide-05 Section 2.12.2
3425 * The sender of the SHUTDOWN MAY also start an overall guard timer
3426 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
3428 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
3429 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3431 disposition = SCTP_DISPOSITION_CONSUME;
3432 if (sctp_outqueue_is_empty(&asoc->outqueue)) {
3433 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
3434 arg, commands);
3436 return disposition;
3440 * Process the ABORT primitive.
3442 * Section: 10.1:
3443 * C) Abort
3445 * Format: Abort(association id [, cause code])
3446 * -> result
3448 * Ungracefully closes an association. Any locally queued user data
3449 * will be discarded and an ABORT chunk is sent to the peer. A success code
3450 * will be returned on successful abortion of the association. If
3451 * attempting to abort the association results in a failure, an error
3452 * code shall be returned.
3454 * Mandatory attributes:
3456 * o association id - local handle to the SCTP association
3458 * Optional attributes:
3460 * o cause code - reason of the abort to be passed to the peer
3462 * None.
3464 * The return value is the disposition.
3466 sctp_disposition_t sctp_sf_do_9_1_prm_abort(const sctp_endpoint_t *ep,
3467 const sctp_association_t *asoc,
3468 const sctp_subtype_t type,
3469 void *arg,
3470 sctp_cmd_seq_t *commands)
3472 /* From 9.1 Abort of an Association
3473 * Upon receipt of the ABORT primitive from its upper
3474 * layer, the endpoint enters CLOSED state and
3475 * discard all outstanding data has been
3476 * acknowledged by its peer. The endpoint accepts no new data
3477 * from its upper layer, but retransmits data to the far end
3478 * if necessary to fill gaps.
3480 struct msghdr *msg = arg;
3481 sctp_chunk_t *abort;
3482 sctp_disposition_t retval;
3484 retval = SCTP_DISPOSITION_CONSUME;
3486 /* Generate ABORT chunk to send the peer. */
3487 abort = sctp_make_abort_user(asoc, NULL, msg);
3488 if (!abort)
3489 retval = SCTP_DISPOSITION_NOMEM;
3490 else
3491 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
3493 /* Even if we can't send the ABORT due to low memory delete the
3494 * TCB. This is a departure from our typical NOMEM handling.
3497 /* Delete the established association. */
3498 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_NULL());
3499 return retval;
3502 /* We tried an illegal operation on an association which is closed. */
3503 sctp_disposition_t sctp_sf_error_closed(const sctp_endpoint_t *ep,
3504 const sctp_association_t *asoc,
3505 const sctp_subtype_t type,
3506 void *arg,
3507 sctp_cmd_seq_t *commands)
3509 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL));
3510 return SCTP_DISPOSITION_CONSUME;
3513 /* We tried an illegal operation on an association which is shutting
3514 * down.
3516 sctp_disposition_t sctp_sf_error_shutdown(const sctp_endpoint_t *ep,
3517 const sctp_association_t *asoc,
3518 const sctp_subtype_t type,
3519 void *arg,
3520 sctp_cmd_seq_t *commands)
3522 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR,
3523 SCTP_ERROR(-ESHUTDOWN));
3524 return SCTP_DISPOSITION_CONSUME;
3528 * sctp_cookie_wait_prm_shutdown
3530 * Section: 4 Note: 2
3531 * Verification Tag:
3532 * Inputs
3533 * (endpoint, asoc)
3535 * The RFC does not explicitly address this issue, but is the route through the
3536 * state table when someone issues a shutdown while in COOKIE_WAIT state.
3538 * Outputs
3539 * (timers)
3541 sctp_disposition_t sctp_sf_cookie_wait_prm_shutdown(
3542 const sctp_endpoint_t *ep,
3543 const sctp_association_t *asoc,
3544 const sctp_subtype_t type,
3545 void *arg,
3546 sctp_cmd_seq_t *commands)
3548 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3549 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
3551 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3552 SCTP_STATE(SCTP_STATE_CLOSED));
3554 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
3556 return SCTP_DISPOSITION_DELETE_TCB;
3560 * sctp_cookie_echoed_prm_shutdown
3562 * Section: 4 Note: 2
3563 * Verification Tag:
3564 * Inputs
3565 * (endpoint, asoc)
3567 * The RFC does not explcitly address this issue, but is the route through the
3568 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
3570 * Outputs
3571 * (timers)
3573 sctp_disposition_t sctp_sf_cookie_echoed_prm_shutdown(
3574 const sctp_endpoint_t *ep,
3575 const sctp_association_t *asoc,
3576 const sctp_subtype_t type,
3577 void *arg, sctp_cmd_seq_t *commands)
3579 /* There is a single T1 timer, so we should be able to use
3580 * common function with the COOKIE-WAIT state.
3582 return sctp_sf_cookie_wait_prm_shutdown(ep, asoc, type, arg, commands);
3586 * sctp_sf_cookie_wait_prm_abort
3588 * Section: 4 Note: 2
3589 * Verification Tag:
3590 * Inputs
3591 * (endpoint, asoc)
3593 * The RFC does not explicitly address this issue, but is the route through the
3594 * state table when someone issues an abort while in COOKIE_WAIT state.
3596 * Outputs
3597 * (timers)
3599 sctp_disposition_t sctp_sf_cookie_wait_prm_abort(const sctp_endpoint_t *ep,
3600 const sctp_association_t *asoc,
3601 const sctp_subtype_t type,
3602 void *arg,
3603 sctp_cmd_seq_t *commands)
3605 struct msghdr *msg = arg;
3606 sctp_chunk_t *abort;
3607 sctp_disposition_t retval;
3609 /* Stop T1-init timer */
3610 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3611 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
3612 retval = SCTP_DISPOSITION_CONSUME;
3614 /* Generate ABORT chunk to send the peer */
3615 abort = sctp_make_abort_user(asoc, NULL, msg);
3616 if (!abort)
3617 retval = SCTP_DISPOSITION_NOMEM;
3618 else
3619 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
3621 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3622 SCTP_STATE(SCTP_STATE_CLOSED));
3624 /* Even if we can't send the ABORT due to low memory delete the
3625 * TCB. This is a departure from our typical NOMEM handling.
3628 /* Delete the established association. */
3629 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, SCTP_NULL());
3631 return retval;
3635 * sctp_sf_cookie_echoed_prm_abort
3637 * Section: 4 Note: 3
3638 * Verification Tag:
3639 * Inputs
3640 * (endpoint, asoc)
3642 * The RFC does not explcitly address this issue, but is the route through the
3643 * state table when someone issues an abort while in COOKIE_ECHOED state.
3645 * Outputs
3646 * (timers)
3648 sctp_disposition_t sctp_sf_cookie_echoed_prm_abort(const sctp_endpoint_t *ep,
3649 const sctp_association_t *asoc,
3650 const sctp_subtype_t type,
3651 void *arg,
3652 sctp_cmd_seq_t *commands)
3654 /* There is a single T1 timer, so we should be able to use
3655 * common function with the COOKIE-WAIT state.
3657 return sctp_sf_cookie_wait_prm_abort(ep, asoc, type, arg, commands);
3661 * sctp_sf_shutdown_pending_prm_abort
3663 * Inputs
3664 * (endpoint, asoc)
3666 * The RFC does not explicitly address this issue, but is the route through the
3667 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
3669 * Outputs
3670 * (timers)
3672 sctp_disposition_t sctp_sf_shutdown_pending_prm_abort(
3673 const sctp_endpoint_t *ep,
3674 const sctp_association_t *asoc,
3675 const sctp_subtype_t type,
3676 void *arg,
3677 sctp_cmd_seq_t *commands)
3679 /* Stop the T5-shutdown guard timer. */
3680 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3681 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3683 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
3687 * sctp_sf_shutdown_sent_prm_abort
3689 * Inputs
3690 * (endpoint, asoc)
3692 * The RFC does not explicitly address this issue, but is the route through the
3693 * state table when someone issues an abort while in SHUTDOWN-SENT state.
3695 * Outputs
3696 * (timers)
3698 sctp_disposition_t sctp_sf_shutdown_sent_prm_abort(
3699 const sctp_endpoint_t *ep,
3700 const sctp_association_t *asoc,
3701 const sctp_subtype_t type,
3702 void *arg,
3703 sctp_cmd_seq_t *commands)
3705 /* Stop the T2-shutdown timer. */
3706 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3707 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3709 /* Stop the T5-shutdown guard timer. */
3710 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3711 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3713 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
3717 * sctp_sf_cookie_echoed_prm_abort
3719 * Inputs
3720 * (endpoint, asoc)
3722 * The RFC does not explcitly address this issue, but is the route through the
3723 * state table when someone issues an abort while in COOKIE_ECHOED state.
3725 * Outputs
3726 * (timers)
3728 sctp_disposition_t sctp_sf_shutdown_ack_sent_prm_abort(
3729 const sctp_endpoint_t *ep,
3730 const sctp_association_t *asoc,
3731 const sctp_subtype_t type,
3732 void *arg,
3733 sctp_cmd_seq_t *commands)
3735 /* The same T2 timer, so we should be able to use
3736 * common function with the SHUTDOWN-SENT state.
3738 return sctp_sf_shutdown_sent_prm_abort(ep, asoc, type, arg, commands);
3742 * Process the REQUESTHEARTBEAT primitive
3744 * 10.1 ULP-to-SCTP
3745 * J) Request Heartbeat
3747 * Format: REQUESTHEARTBEAT(association id, destination transport address)
3749 * -> result
3751 * Instructs the local endpoint to perform a HeartBeat on the specified
3752 * destination transport address of the given association. The returned
3753 * result should indicate whether the transmission of the HEARTBEAT
3754 * chunk to the destination address is successful.
3756 * Mandatory attributes:
3758 * o association id - local handle to the SCTP association
3760 * o destination transport address - the transport address of the
3761 * asociation on which a heartbeat should be issued.
3763 sctp_disposition_t sctp_sf_do_prm_requestheartbeat(
3764 const sctp_endpoint_t *ep,
3765 const sctp_association_t *asoc,
3766 const sctp_subtype_t type,
3767 void *arg,
3768 sctp_cmd_seq_t *commands)
3770 return sctp_sf_heartbeat(ep, asoc, type, (sctp_transport_t *)arg,
3771 commands);
3775 * Ignore the primitive event
3777 * The return value is the disposition of the primitive.
3779 sctp_disposition_t sctp_sf_ignore_primitive(const sctp_endpoint_t *ep,
3780 const sctp_association_t *asoc,
3781 const sctp_subtype_t type,
3782 void *arg,
3783 sctp_cmd_seq_t *commands)
3785 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type.primitive);
3786 return SCTP_DISPOSITION_DISCARD;
3789 /***************************************************************************
3790 * These are the state functions for the OTHER events.
3791 ***************************************************************************/
3794 * Start the shutdown negotiation.
3796 * From Section 9.2:
3797 * Once all its outstanding data has been acknowledged, the endpoint
3798 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
3799 * TSN Ack field the last sequential TSN it has received from the peer.
3800 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
3801 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
3802 * with the updated last sequential TSN received from its peer.
3804 * The return value is the disposition.
3806 sctp_disposition_t sctp_sf_do_9_2_start_shutdown(const sctp_endpoint_t *ep,
3807 const sctp_association_t *asoc,
3808 const sctp_subtype_t type,
3809 void *arg,
3810 sctp_cmd_seq_t *commands)
3812 sctp_chunk_t *reply;
3814 /* Once all its outstanding data has been acknowledged, the
3815 * endpoint shall send a SHUTDOWN chunk to its peer including
3816 * in the Cumulative TSN Ack field the last sequential TSN it
3817 * has received from the peer.
3819 reply = sctp_make_shutdown(asoc);
3820 if (!reply)
3821 goto nomem;
3823 /* Set the transport for the SHUTDOWN chunk and the timeout for the
3824 * T2-shutdown timer.
3826 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
3828 /* It shall then start the T2-shutdown timer */
3829 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
3830 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3832 if (asoc->autoclose)
3833 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3834 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
3836 /* and enter the SHUTDOWN-SENT state. */
3837 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3838 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT));
3840 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
3842 return SCTP_DISPOSITION_CONSUME;
3844 nomem:
3845 return SCTP_DISPOSITION_NOMEM;
3849 * Generate a SHUTDOWN ACK now that everything is SACK'd.
3851 * From Section 9.2:
3853 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
3854 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
3855 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
3856 * endpoint must re-send the SHUTDOWN ACK.
3858 * The return value is the disposition.
3860 sctp_disposition_t sctp_sf_do_9_2_shutdown_ack(const sctp_endpoint_t *ep,
3861 const sctp_association_t *asoc,
3862 const sctp_subtype_t type,
3863 void *arg,
3864 sctp_cmd_seq_t *commands)
3866 sctp_chunk_t *chunk = (sctp_chunk_t *) arg;
3867 sctp_chunk_t *reply;
3869 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
3870 * shall send a SHUTDOWN ACK ...
3872 reply = sctp_make_shutdown_ack(asoc, chunk);
3873 if (!reply)
3874 goto nomem;
3876 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
3877 * the T2-shutdown timer.
3879 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
3881 /* and start/restart a T2-shutdown timer of its own, */
3882 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3883 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3885 if (asoc->autoclose)
3886 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3887 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
3889 /* Enter the SHUTDOWN-ACK-SENT state. */
3890 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3891 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT));
3892 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
3894 return SCTP_DISPOSITION_CONSUME;
3896 nomem:
3897 return SCTP_DISPOSITION_NOMEM;
3901 * Ignore the event defined as other
3903 * The return value is the disposition of the event.
3905 sctp_disposition_t sctp_sf_ignore_other(const sctp_endpoint_t *ep,
3906 const sctp_association_t *asoc,
3907 const sctp_subtype_t type,
3908 void *arg,
3909 sctp_cmd_seq_t *commands)
3911 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type.other);
3912 return SCTP_DISPOSITION_DISCARD;
3915 /************************************************************
3916 * These are the state functions for handling timeout events.
3917 ************************************************************/
3920 * RTX Timeout
3922 * Section: 6.3.3 Handle T3-rtx Expiration
3924 * Whenever the retransmission timer T3-rtx expires for a destination
3925 * address, do the following:
3926 * [See below]
3928 * The return value is the disposition of the chunk.
3930 sctp_disposition_t sctp_sf_do_6_3_3_rtx(const sctp_endpoint_t *ep,
3931 const sctp_association_t *asoc,
3932 const sctp_subtype_t type,
3933 void *arg,
3934 sctp_cmd_seq_t *commands)
3936 sctp_transport_t *transport = arg;
3938 if (asoc->overall_error_count >= asoc->overall_error_threshold) {
3939 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
3940 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_NULL());
3941 return SCTP_DISPOSITION_DELETE_TCB;
3944 /* E1) For the destination address for which the timer
3945 * expires, adjust its ssthresh with rules defined in Section
3946 * 7.2.3 and set the cwnd <- MTU.
3949 /* E2) For the destination address for which the timer
3950 * expires, set RTO <- RTO * 2 ("back off the timer"). The
3951 * maximum value discussed in rule C7 above (RTO.max) may be
3952 * used to provide an upper bound to this doubling operation.
3955 /* E3) Determine how many of the earliest (i.e., lowest TSN)
3956 * outstanding DATA chunks for the address for which the
3957 * T3-rtx has expired will fit into a single packet, subject
3958 * to the MTU constraint for the path corresponding to the
3959 * destination transport address to which the retransmission
3960 * is being sent (this may be different from the address for
3961 * which the timer expires [see Section 6.4]). Call this
3962 * value K. Bundle and retransmit those K DATA chunks in a
3963 * single packet to the destination endpoint.
3965 * Note: Any DATA chunks that were sent to the address for
3966 * which the T3-rtx timer expired but did not fit in one MTU
3967 * (rule E3 above), should be marked for retransmission and
3968 * sent as soon as cwnd allows (normally when a SACK arrives).
3971 /* NB: Rules E4 and F1 are implicit in R1. */
3972 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport));
3974 /* Do some failure management (Section 8.2). */
3975 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
3977 return SCTP_DISPOSITION_CONSUME;
3981 * Generate delayed SACK on timeout
3983 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
3985 * The guidelines on delayed acknowledgement algorithm specified in
3986 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
3987 * acknowledgement SHOULD be generated for at least every second packet
3988 * (not every second DATA chunk) received, and SHOULD be generated
3989 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
3990 * some situations it may be beneficial for an SCTP transmitter to be
3991 * more conservative than the algorithms detailed in this document
3992 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
3993 * the following algorithms allow.
3995 sctp_disposition_t sctp_sf_do_6_2_sack(const sctp_endpoint_t *ep,
3996 const sctp_association_t *asoc,
3997 const sctp_subtype_t type,
3998 void *arg,
3999 sctp_cmd_seq_t *commands)
4001 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
4002 return SCTP_DISPOSITION_CONSUME;
4006 * sctp_sf_t1_timer_expire
4008 * Section: 4 Note: 2
4009 * Verification Tag:
4010 * Inputs
4011 * (endpoint, asoc)
4013 * RFC 2960 Section 4 Notes
4014 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
4015 * and re-start the T1-init timer without changing state. This MUST
4016 * be repeated up to 'Max.Init.Retransmits' times. After that, the
4017 * endpoint MUST abort the initialization process and report the
4018 * error to SCTP user.
4020 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
4021 * COOKIE ECHO and re-start the T1-cookie timer without changing
4022 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
4023 * After that, the endpoint MUST abort the initialization process and
4024 * report the error to SCTP user.
4026 * Outputs
4027 * (timers, events)
4030 sctp_disposition_t sctp_sf_t1_timer_expire(const sctp_endpoint_t *ep,
4031 const sctp_association_t *asoc,
4032 const sctp_subtype_t type,
4033 void *arg,
4034 sctp_cmd_seq_t *commands)
4036 sctp_chunk_t *repl;
4037 sctp_bind_addr_t *bp;
4038 sctp_event_timeout_t timer = (sctp_event_timeout_t) arg;
4039 int timeout;
4040 int attempts;
4042 timeout = asoc->timeouts[timer];
4043 attempts = asoc->counters[SCTP_COUNTER_INIT_ERROR] + 1;
4044 repl = NULL;
4046 SCTP_DEBUG_PRINTK("Timer T1 expired.\n");
4048 if ((timeout < asoc->max_init_timeo) &&
4049 (attempts < asoc->max_init_attempts)) {
4050 switch (timer) {
4051 case SCTP_EVENT_TIMEOUT_T1_INIT:
4052 bp = (sctp_bind_addr_t *) &asoc->base.bind_addr;
4053 repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0);
4054 break;
4056 case SCTP_EVENT_TIMEOUT_T1_COOKIE:
4057 repl = sctp_make_cookie_echo(asoc, NULL);
4058 break;
4060 default:
4061 BUG();
4062 break;
4065 if (!repl)
4066 goto nomem;
4068 /* Issue a sideeffect to do the needed accounting. */
4069 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART,
4070 SCTP_TO(timer));
4071 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
4072 } else {
4073 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, SCTP_NULL());
4074 return SCTP_DISPOSITION_DELETE_TCB;
4077 return SCTP_DISPOSITION_CONSUME;
4079 nomem:
4080 return SCTP_DISPOSITION_NOMEM;
4083 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
4084 * with the updated last sequential TSN received from its peer.
4086 * An endpoint should limit the number of retransmissions of the
4087 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
4088 * If this threshold is exceeded the endpoint should destroy the TCB and
4089 * MUST report the peer endpoint unreachable to the upper layer (and
4090 * thus the association enters the CLOSED state). The reception of any
4091 * packet from its peer (i.e. as the peer sends all of its queued DATA
4092 * chunks) should clear the endpoint's retransmission count and restart
4093 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
4094 * all of its queued DATA chunks that have not yet been sent.
4096 sctp_disposition_t sctp_sf_t2_timer_expire(const sctp_endpoint_t *ep,
4097 const sctp_association_t *asoc,
4098 const sctp_subtype_t type,
4099 void *arg,
4100 sctp_cmd_seq_t *commands)
4102 sctp_chunk_t *reply = NULL;
4104 SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
4105 if (asoc->overall_error_count >= asoc->overall_error_threshold) {
4106 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
4107 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_NULL());
4108 return SCTP_DISPOSITION_DELETE_TCB;
4111 switch (asoc->state) {
4112 case SCTP_STATE_SHUTDOWN_SENT:
4113 reply = sctp_make_shutdown(asoc);
4114 break;
4116 case SCTP_STATE_SHUTDOWN_ACK_SENT:
4117 reply = sctp_make_shutdown_ack(asoc, NULL);
4118 break;
4120 default:
4121 BUG();
4122 break;
4125 if (!reply)
4126 goto nomem;
4128 /* Do some failure management (Section 8.2). */
4129 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
4130 SCTP_TRANSPORT(asoc->shutdown_last_sent_to));
4132 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
4133 * the T2-shutdown timer.
4135 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4137 /* Restart the T2-shutdown timer. */
4138 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4139 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4140 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4141 return SCTP_DISPOSITION_CONSUME;
4143 nomem:
4144 return SCTP_DISPOSITION_NOMEM;
4147 /* sctpimpguide-05 Section 2.12.2
4148 * The sender of the SHUTDOWN MAY also start an overall guard timer
4149 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4150 * At the expiration of this timer the sender SHOULD abort the association
4151 * by sending an ABORT chunk.
4153 sctp_disposition_t sctp_sf_t5_timer_expire(const sctp_endpoint_t *ep,
4154 const sctp_association_t *asoc,
4155 const sctp_subtype_t type,
4156 void *arg,
4157 sctp_cmd_seq_t *commands)
4159 sctp_chunk_t *reply = NULL;
4161 SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
4163 reply = sctp_make_abort(asoc, NULL, 0);
4164 if (!reply)
4165 goto nomem;
4167 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4168 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_NULL());
4170 return SCTP_DISPOSITION_DELETE_TCB;
4171 nomem:
4172 return SCTP_DISPOSITION_NOMEM;
4175 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
4176 * the association is automatically closed by starting the shutdown process.
4177 * The work that needs to be done is same as when SHUTDOWN is initiated by
4178 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
4180 sctp_disposition_t sctp_sf_autoclose_timer_expire(const sctp_endpoint_t *ep,
4181 const sctp_association_t *asoc,
4182 const sctp_subtype_t type,
4183 void *arg,
4184 sctp_cmd_seq_t *commands)
4186 int disposition;
4188 /* From 9.2 Shutdown of an Association
4189 * Upon receipt of the SHUTDOWN primitive from its upper
4190 * layer, the endpoint enters SHUTDOWN-PENDING state and
4191 * remains there until all outstanding data has been
4192 * acknowledged by its peer. The endpoint accepts no new data
4193 * from its upper layer, but retransmits data to the far end
4194 * if necessary to fill gaps.
4196 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4197 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
4199 /* sctpimpguide-05 Section 2.12.2
4200 * The sender of the SHUTDOWN MAY also start an overall guard timer
4201 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4203 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4204 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4205 disposition = SCTP_DISPOSITION_CONSUME;
4206 if (sctp_outqueue_is_empty(&asoc->outqueue)) {
4207 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
4208 arg, commands);
4210 return disposition;
4213 /*****************************************************************************
4214 * These are sa state functions which could apply to all types of events.
4215 ****************************************************************************/
4218 * This table entry is not implemented.
4220 * Inputs
4221 * (endpoint, asoc, chunk)
4223 * The return value is the disposition of the chunk.
4225 sctp_disposition_t sctp_sf_not_impl(const sctp_endpoint_t *ep,
4226 const sctp_association_t *asoc,
4227 const sctp_subtype_t type,
4228 void *arg,
4229 sctp_cmd_seq_t *commands)
4231 return SCTP_DISPOSITION_NOT_IMPL;
4235 * This table entry represents a bug.
4237 * Inputs
4238 * (endpoint, asoc, chunk)
4240 * The return value is the disposition of the chunk.
4242 sctp_disposition_t sctp_sf_bug(const sctp_endpoint_t *ep,
4243 const sctp_association_t *asoc,
4244 const sctp_subtype_t type,
4245 void *arg,
4246 sctp_cmd_seq_t *commands)
4248 return SCTP_DISPOSITION_BUG;
4252 * This table entry represents the firing of a timer in the wrong state.
4253 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
4254 * when the association is in the wrong state. This event should
4255 * be ignored, so as to prevent any rearming of the timer.
4257 * Inputs
4258 * (endpoint, asoc, chunk)
4260 * The return value is the disposition of the chunk.
4262 sctp_disposition_t sctp_sf_timer_ignore(const sctp_endpoint_t *ep,
4263 const sctp_association_t *asoc,
4264 const sctp_subtype_t type,
4265 void *arg,
4266 sctp_cmd_seq_t *commands)
4268 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type.chunk);
4269 return SCTP_DISPOSITION_CONSUME;
4272 /********************************************************************
4273 * 2nd Level Abstractions
4274 ********************************************************************/
4276 /* Pull the SACK chunk based on the SACK header. */
4277 sctp_sackhdr_t *sctp_sm_pull_sack(sctp_chunk_t *chunk)
4279 sctp_sackhdr_t *sack;
4280 __u16 num_blocks;
4281 __u16 num_dup_tsns;
4283 sack = (sctp_sackhdr_t *) chunk->skb->data;
4284 skb_pull(chunk->skb, sizeof(sctp_sackhdr_t));
4286 num_blocks = ntohs(sack->num_gap_ack_blocks);
4287 num_dup_tsns = ntohs(sack->num_dup_tsns);
4289 skb_pull(chunk->skb, (num_blocks + num_dup_tsns) * sizeof(__u32));
4290 return sack;
4293 /* Create an ABORT packet to be sent as a response, with the specified
4294 * error causes.
4296 sctp_packet_t *sctp_abort_pkt_new(const sctp_endpoint_t *ep,
4297 const sctp_association_t *asoc,
4298 sctp_chunk_t *chunk,
4299 const void *payload,
4300 size_t paylen)
4302 sctp_packet_t *packet;
4303 sctp_chunk_t *abort;
4305 packet = sctp_ootb_pkt_new(asoc, chunk);
4307 if (packet) {
4308 /* Make an ABORT.
4309 * The T bit will be set if the asoc is NULL.
4311 abort = sctp_make_abort(asoc, chunk, paylen);
4312 if (!abort) {
4313 sctp_ootb_pkt_free(packet);
4314 return NULL;
4316 /* Add specified error causes, i.e., payload, to the
4317 * end of the chunk.
4319 sctp_addto_chunk(abort, paylen, payload);
4321 /* Set the skb to the belonging sock for accounting. */
4322 abort->skb->sk = ep->base.sk;
4324 sctp_packet_append_chunk(packet, abort);
4328 return packet;
4331 /* Allocate a packet for responding in the OOTB conditions. */
4332 sctp_packet_t *sctp_ootb_pkt_new(const sctp_association_t *asoc,
4333 const sctp_chunk_t *chunk)
4335 sctp_packet_t *packet;
4336 sctp_transport_t *transport;
4337 __u16 sport;
4338 __u16 dport;
4339 __u32 vtag;
4341 /* Get the source and destination port from the inbound packet. */
4342 sport = ntohs(chunk->sctp_hdr->dest);
4343 dport = ntohs(chunk->sctp_hdr->source);
4345 /* The V-tag is going to be the same as the inbound packet if no
4346 * association exists, otherwise, use the peer's vtag.
4348 if (asoc) {
4349 vtag = asoc->peer.i.init_tag;
4350 } else {
4351 /* Special case the INIT as there is no vtag yet. */
4352 if (SCTP_CID_INIT == chunk->chunk_hdr->type) {
4353 sctp_init_chunk_t *init;
4354 init = (sctp_init_chunk_t *)chunk->chunk_hdr;
4355 vtag = ntohl(init->init_hdr.init_tag);
4356 } else {
4357 vtag = ntohl(chunk->sctp_hdr->vtag);
4361 /* Make a transport for the bucket, Eliza... */
4362 transport = sctp_transport_new(sctp_source(chunk), GFP_ATOMIC);
4364 if (!transport)
4365 goto nomem;
4367 /* Allocate a new packet for sending the response. */
4368 packet = t_new(sctp_packet_t, GFP_ATOMIC);
4369 if (!packet)
4370 goto nomem_packet;
4372 /* Cache a route for the transport with the chunk's destination as
4373 * the source address.
4375 sctp_transport_route(transport, (union sctp_addr *)&chunk->dest,
4376 sctp_sk(sctp_get_ctl_sock()));
4378 packet = sctp_packet_init(packet, transport, sport, dport);
4379 packet = sctp_packet_config(packet, vtag, 0, NULL);
4381 return packet;
4383 nomem_packet:
4384 sctp_transport_free(transport);
4385 nomem:
4386 return NULL;
4389 /* Free the packet allocated earlier for responding in the OOTB condition. */
4390 void sctp_ootb_pkt_free(sctp_packet_t *packet)
4392 sctp_transport_free(packet->transport);
4393 sctp_packet_free(packet);
4396 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
4397 void sctp_send_stale_cookie_err(const sctp_endpoint_t *ep,
4398 const sctp_association_t *asoc,
4399 const sctp_chunk_t *chunk,
4400 sctp_cmd_seq_t *commands,
4401 sctp_chunk_t *err_chunk)
4403 sctp_packet_t *packet;
4405 if (err_chunk) {
4406 packet = sctp_ootb_pkt_new(asoc, chunk);
4407 if (packet) {
4408 /* Set the skb to the belonging sock for accounting. */
4409 err_chunk->skb->sk = ep->base.sk;
4410 sctp_packet_append_chunk(packet, err_chunk);
4411 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
4412 SCTP_PACKET(packet));
4413 } else
4414 sctp_free_chunk (err_chunk);