1 /* SCTP kernel implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
6 * This file is part of the SCTP kernel implementation
8 * These functions work with the state functions in sctp_sm_statefuns.c
9 * to implement that state operations. These functions implement the
10 * steps which require modifying existing data structures.
12 * This SCTP implementation is free software;
13 * you can redistribute it and/or modify it under the terms of
14 * the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * This SCTP implementation is distributed in the hope that it
19 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
20 * ************************
21 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 * See the GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with GNU CC; see the file COPYING. If not, write to
26 * the Free Software Foundation, 59 Temple Place - Suite 330,
27 * Boston, MA 02111-1307, USA.
29 * Please send any bug reports or fixes you make to the
31 * lksctp developers <lksctp-developers@lists.sourceforge.net>
33 * Or submit a bug report through the following website:
34 * http://www.sf.net/projects/lksctp
36 * Written or modified by:
37 * La Monte H.P. Yarroll <piggy@acm.org>
38 * Karl Knutson <karl@athena.chicago.il.us>
39 * Jon Grimm <jgrimm@austin.ibm.com>
40 * Hui Huang <hui.huang@nokia.com>
41 * Dajiang Zhang <dajiang.zhang@nokia.com>
42 * Daisy Chang <daisyc@us.ibm.com>
43 * Sridhar Samudrala <sri@us.ibm.com>
44 * Ardelle Fan <ardelle.fan@intel.com>
46 * Any bugs reported given to us we will try to fix... any fixes shared will
47 * be incorporated into the next SCTP release.
50 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
52 #include <linux/skbuff.h>
53 #include <linux/types.h>
54 #include <linux/socket.h>
56 #include <linux/gfp.h>
58 #include <net/sctp/sctp.h>
59 #include <net/sctp/sm.h>
61 static int sctp_cmd_interpreter(sctp_event_t event_type,
62 sctp_subtype_t subtype,
64 struct sctp_endpoint *ep,
65 struct sctp_association *asoc,
67 sctp_disposition_t status,
68 sctp_cmd_seq_t *commands,
70 static int sctp_side_effects(sctp_event_t event_type, sctp_subtype_t subtype,
72 struct sctp_endpoint *ep,
73 struct sctp_association *asoc,
75 sctp_disposition_t status,
76 sctp_cmd_seq_t *commands,
79 /********************************************************************
81 ********************************************************************/
83 /* A helper function for delayed processing of INET ECN CE bit. */
84 static void sctp_do_ecn_ce_work(struct sctp_association *asoc,
87 /* Save the TSN away for comparison when we receive CWR */
89 asoc->last_ecne_tsn = lowest_tsn;
93 /* Helper function for delayed processing of SCTP ECNE chunk. */
94 /* RFC 2960 Appendix A
96 * RFC 2481 details a specific bit for a sender to send in
97 * the header of its next outbound TCP segment to indicate to
98 * its peer that it has reduced its congestion window. This
99 * is termed the CWR bit. For SCTP the same indication is made
100 * by including the CWR chunk. This chunk contains one data
101 * element, i.e. the TSN number that was sent in the ECNE chunk.
102 * This element represents the lowest TSN number in the datagram
103 * that was originally marked with the CE bit.
105 static struct sctp_chunk *sctp_do_ecn_ecne_work(struct sctp_association *asoc,
107 struct sctp_chunk *chunk)
109 struct sctp_chunk *repl;
111 /* Our previously transmitted packet ran into some congestion
112 * so we should take action by reducing cwnd and ssthresh
113 * and then ACK our peer that we we've done so by
117 /* First, try to determine if we want to actually lower
118 * our cwnd variables. Only lower them if the ECNE looks more
119 * recent than the last response.
121 if (TSN_lt(asoc->last_cwr_tsn, lowest_tsn)) {
122 struct sctp_transport *transport;
124 /* Find which transport's congestion variables
125 * need to be adjusted.
127 transport = sctp_assoc_lookup_tsn(asoc, lowest_tsn);
129 /* Update the congestion variables. */
131 sctp_transport_lower_cwnd(transport,
132 SCTP_LOWER_CWND_ECNE);
133 asoc->last_cwr_tsn = lowest_tsn;
136 /* Always try to quiet the other end. In case of lost CWR,
137 * resend last_cwr_tsn.
139 repl = sctp_make_cwr(asoc, asoc->last_cwr_tsn, chunk);
141 /* If we run out of memory, it will look like a lost CWR. We'll
142 * get back in sync eventually.
147 /* Helper function to do delayed processing of ECN CWR chunk. */
148 static void sctp_do_ecn_cwr_work(struct sctp_association *asoc,
151 /* Turn off ECNE getting auto-prepended to every outgoing
157 /* Generate SACK if necessary. We call this at the end of a packet. */
158 static int sctp_gen_sack(struct sctp_association *asoc, int force,
159 sctp_cmd_seq_t *commands)
161 __u32 ctsn, max_tsn_seen;
162 struct sctp_chunk *sack;
163 struct sctp_transport *trans = asoc->peer.last_data_from;
167 (!trans && (asoc->param_flags & SPP_SACKDELAY_DISABLE)) ||
168 (trans && (trans->param_flags & SPP_SACKDELAY_DISABLE)))
169 asoc->peer.sack_needed = 1;
171 ctsn = sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map);
172 max_tsn_seen = sctp_tsnmap_get_max_tsn_seen(&asoc->peer.tsn_map);
174 /* From 12.2 Parameters necessary per association (i.e. the TCB):
176 * Ack State : This flag indicates if the next received packet
177 * : is to be responded to with a SACK. ...
178 * : When DATA chunks are out of order, SACK's
179 * : are not delayed (see Section 6).
181 * [This is actually not mentioned in Section 6, but we
182 * implement it here anyway. --piggy]
184 if (max_tsn_seen != ctsn)
185 asoc->peer.sack_needed = 1;
187 /* From 6.2 Acknowledgement on Reception of DATA Chunks:
189 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically,
190 * an acknowledgement SHOULD be generated for at least every
191 * second packet (not every second DATA chunk) received, and
192 * SHOULD be generated within 200 ms of the arrival of any
193 * unacknowledged DATA chunk. ...
195 if (!asoc->peer.sack_needed) {
196 asoc->peer.sack_cnt++;
198 /* Set the SACK delay timeout based on the
199 * SACK delay for the last transport
200 * data was received from, or the default
201 * for the association.
204 /* We will need a SACK for the next packet. */
205 if (asoc->peer.sack_cnt >= trans->sackfreq - 1)
206 asoc->peer.sack_needed = 1;
208 asoc->timeouts[SCTP_EVENT_TIMEOUT_SACK] =
211 /* We will need a SACK for the next packet. */
212 if (asoc->peer.sack_cnt >= asoc->sackfreq - 1)
213 asoc->peer.sack_needed = 1;
215 asoc->timeouts[SCTP_EVENT_TIMEOUT_SACK] =
219 /* Restart the SACK timer. */
220 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
221 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
223 asoc->a_rwnd = asoc->rwnd;
224 sack = sctp_make_sack(asoc);
228 asoc->peer.sack_needed = 0;
229 asoc->peer.sack_cnt = 0;
231 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(sack));
233 /* Stop the SACK timer. */
234 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
235 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
244 /* When the T3-RTX timer expires, it calls this function to create the
245 * relevant state machine event.
247 void sctp_generate_t3_rtx_event(unsigned long peer)
250 struct sctp_transport *transport = (struct sctp_transport *) peer;
251 struct sctp_association *asoc = transport->asoc;
252 struct sock *sk = asoc->base.sk;
254 /* Check whether a task is in the sock. */
256 sctp_bh_lock_sock(sk);
257 if (sock_owned_by_user(sk)) {
258 SCTP_DEBUG_PRINTK("%s:Sock is busy.\n", __func__);
260 /* Try again later. */
261 if (!mod_timer(&transport->T3_rtx_timer, jiffies + (HZ/20)))
262 sctp_transport_hold(transport);
266 /* Is this transport really dead and just waiting around for
267 * the timer to let go of the reference?
272 /* Run through the state machine. */
273 error = sctp_do_sm(SCTP_EVENT_T_TIMEOUT,
274 SCTP_ST_TIMEOUT(SCTP_EVENT_TIMEOUT_T3_RTX),
277 transport, GFP_ATOMIC);
283 sctp_bh_unlock_sock(sk);
284 sctp_transport_put(transport);
287 /* This is a sa interface for producing timeout events. It works
288 * for timeouts which use the association as their parameter.
290 static void sctp_generate_timeout_event(struct sctp_association *asoc,
291 sctp_event_timeout_t timeout_type)
293 struct sock *sk = asoc->base.sk;
296 sctp_bh_lock_sock(sk);
297 if (sock_owned_by_user(sk)) {
298 SCTP_DEBUG_PRINTK("%s:Sock is busy: timer %d\n",
302 /* Try again later. */
303 if (!mod_timer(&asoc->timers[timeout_type], jiffies + (HZ/20)))
304 sctp_association_hold(asoc);
308 /* Is this association really dead and just waiting around for
309 * the timer to let go of the reference?
314 /* Run through the state machine. */
315 error = sctp_do_sm(SCTP_EVENT_T_TIMEOUT,
316 SCTP_ST_TIMEOUT(timeout_type),
317 asoc->state, asoc->ep, asoc,
318 (void *)timeout_type, GFP_ATOMIC);
324 sctp_bh_unlock_sock(sk);
325 sctp_association_put(asoc);
328 static void sctp_generate_t1_cookie_event(unsigned long data)
330 struct sctp_association *asoc = (struct sctp_association *) data;
331 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T1_COOKIE);
334 static void sctp_generate_t1_init_event(unsigned long data)
336 struct sctp_association *asoc = (struct sctp_association *) data;
337 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T1_INIT);
340 static void sctp_generate_t2_shutdown_event(unsigned long data)
342 struct sctp_association *asoc = (struct sctp_association *) data;
343 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T2_SHUTDOWN);
346 static void sctp_generate_t4_rto_event(unsigned long data)
348 struct sctp_association *asoc = (struct sctp_association *) data;
349 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T4_RTO);
352 static void sctp_generate_t5_shutdown_guard_event(unsigned long data)
354 struct sctp_association *asoc = (struct sctp_association *)data;
355 sctp_generate_timeout_event(asoc,
356 SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD);
358 } /* sctp_generate_t5_shutdown_guard_event() */
360 static void sctp_generate_autoclose_event(unsigned long data)
362 struct sctp_association *asoc = (struct sctp_association *) data;
363 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_AUTOCLOSE);
366 /* Generate a heart beat event. If the sock is busy, reschedule. Make
367 * sure that the transport is still valid.
369 void sctp_generate_heartbeat_event(unsigned long data)
372 struct sctp_transport *transport = (struct sctp_transport *) data;
373 struct sctp_association *asoc = transport->asoc;
374 struct sock *sk = asoc->base.sk;
376 sctp_bh_lock_sock(sk);
377 if (sock_owned_by_user(sk)) {
378 SCTP_DEBUG_PRINTK("%s:Sock is busy.\n", __func__);
380 /* Try again later. */
381 if (!mod_timer(&transport->hb_timer, jiffies + (HZ/20)))
382 sctp_transport_hold(transport);
386 /* Is this structure just waiting around for us to actually
392 error = sctp_do_sm(SCTP_EVENT_T_TIMEOUT,
393 SCTP_ST_TIMEOUT(SCTP_EVENT_TIMEOUT_HEARTBEAT),
394 asoc->state, asoc->ep, asoc,
395 transport, GFP_ATOMIC);
401 sctp_bh_unlock_sock(sk);
402 sctp_transport_put(transport);
405 /* Handle the timeout of the ICMP protocol unreachable timer. Trigger
406 * the correct state machine transition that will close the association.
408 void sctp_generate_proto_unreach_event(unsigned long data)
410 struct sctp_transport *transport = (struct sctp_transport *) data;
411 struct sctp_association *asoc = transport->asoc;
412 struct sock *sk = asoc->base.sk;
414 sctp_bh_lock_sock(sk);
415 if (sock_owned_by_user(sk)) {
416 SCTP_DEBUG_PRINTK("%s:Sock is busy.\n", __func__);
418 /* Try again later. */
419 if (!mod_timer(&transport->proto_unreach_timer,
421 sctp_association_hold(asoc);
425 /* Is this structure just waiting around for us to actually
431 sctp_do_sm(SCTP_EVENT_T_OTHER,
432 SCTP_ST_OTHER(SCTP_EVENT_ICMP_PROTO_UNREACH),
433 asoc->state, asoc->ep, asoc, transport, GFP_ATOMIC);
436 sctp_bh_unlock_sock(sk);
437 sctp_association_put(asoc);
441 /* Inject a SACK Timeout event into the state machine. */
442 static void sctp_generate_sack_event(unsigned long data)
444 struct sctp_association *asoc = (struct sctp_association *) data;
445 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
448 sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
450 sctp_generate_t1_cookie_event,
451 sctp_generate_t1_init_event,
452 sctp_generate_t2_shutdown_event,
454 sctp_generate_t4_rto_event,
455 sctp_generate_t5_shutdown_guard_event,
457 sctp_generate_sack_event,
458 sctp_generate_autoclose_event,
462 /* RFC 2960 8.2 Path Failure Detection
464 * When its peer endpoint is multi-homed, an endpoint should keep a
465 * error counter for each of the destination transport addresses of the
468 * Each time the T3-rtx timer expires on any address, or when a
469 * HEARTBEAT sent to an idle address is not acknowledged within a RTO,
470 * the error counter of that destination address will be incremented.
471 * When the value in the error counter exceeds the protocol parameter
472 * 'Path.Max.Retrans' of that destination address, the endpoint should
473 * mark the destination transport address as inactive, and a
474 * notification SHOULD be sent to the upper layer.
477 static void sctp_do_8_2_transport_strike(struct sctp_association *asoc,
478 struct sctp_transport *transport,
481 /* The check for association's overall error counter exceeding the
482 * threshold is done in the state function.
484 /* We are here due to a timer expiration. If the timer was
485 * not a HEARTBEAT, then normal error tracking is done.
486 * If the timer was a heartbeat, we only increment error counts
487 * when we already have an outstanding HEARTBEAT that has not
489 * Additionally, some tranport states inhibit error increments.
492 asoc->overall_error_count++;
493 if (transport->state != SCTP_INACTIVE)
494 transport->error_count++;
495 } else if (transport->hb_sent) {
496 if (transport->state != SCTP_UNCONFIRMED)
497 asoc->overall_error_count++;
498 if (transport->state != SCTP_INACTIVE)
499 transport->error_count++;
502 if (transport->state != SCTP_INACTIVE &&
503 (transport->error_count > transport->pathmaxrxt)) {
504 SCTP_DEBUG_PRINTK_IPADDR("transport_strike:association %p",
505 " transport IP: port:%d failed.\n",
507 (&transport->ipaddr),
508 ntohs(transport->ipaddr.v4.sin_port));
509 sctp_assoc_control_transport(asoc, transport,
511 SCTP_FAILED_THRESHOLD);
514 /* E2) For the destination address for which the timer
515 * expires, set RTO <- RTO * 2 ("back off the timer"). The
516 * maximum value discussed in rule C7 above (RTO.max) may be
517 * used to provide an upper bound to this doubling operation.
519 * Special Case: the first HB doesn't trigger exponential backoff.
520 * The first unacknowledged HB triggers it. We do this with a flag
521 * that indicates that we have an outstanding HB.
523 if (!is_hb || transport->hb_sent) {
524 transport->rto = min((transport->rto * 2), transport->asoc->rto_max);
528 /* Worker routine to handle INIT command failure. */
529 static void sctp_cmd_init_failed(sctp_cmd_seq_t *commands,
530 struct sctp_association *asoc,
533 struct sctp_ulpevent *event;
535 event = sctp_ulpevent_make_assoc_change(asoc,0, SCTP_CANT_STR_ASSOC,
536 (__u16)error, 0, 0, NULL,
540 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
541 SCTP_ULPEVENT(event));
543 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
544 SCTP_STATE(SCTP_STATE_CLOSED));
546 /* SEND_FAILED sent later when cleaning up the association. */
547 asoc->outqueue.error = error;
548 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
551 /* Worker routine to handle SCTP_CMD_ASSOC_FAILED. */
552 static void sctp_cmd_assoc_failed(sctp_cmd_seq_t *commands,
553 struct sctp_association *asoc,
554 sctp_event_t event_type,
555 sctp_subtype_t subtype,
556 struct sctp_chunk *chunk,
559 struct sctp_ulpevent *event;
561 /* Cancel any partial delivery in progress. */
562 sctp_ulpq_abort_pd(&asoc->ulpq, GFP_ATOMIC);
564 if (event_type == SCTP_EVENT_T_CHUNK && subtype.chunk == SCTP_CID_ABORT)
565 event = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_LOST,
566 (__u16)error, 0, 0, chunk,
569 event = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_LOST,
570 (__u16)error, 0, 0, NULL,
573 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
574 SCTP_ULPEVENT(event));
576 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
577 SCTP_STATE(SCTP_STATE_CLOSED));
579 /* SEND_FAILED sent later when cleaning up the association. */
580 asoc->outqueue.error = error;
581 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
584 /* Process an init chunk (may be real INIT/INIT-ACK or an embedded INIT
585 * inside the cookie. In reality, this is only used for INIT-ACK processing
586 * since all other cases use "temporary" associations and can do all
587 * their work in statefuns directly.
589 static int sctp_cmd_process_init(sctp_cmd_seq_t *commands,
590 struct sctp_association *asoc,
591 struct sctp_chunk *chunk,
592 sctp_init_chunk_t *peer_init,
597 /* We only process the init as a sideeffect in a single
598 * case. This is when we process the INIT-ACK. If we
599 * fail during INIT processing (due to malloc problems),
600 * just return the error and stop processing the stack.
602 if (!sctp_process_init(asoc, chunk, sctp_source(chunk), peer_init, gfp))
610 /* Helper function to break out starting up of heartbeat timers. */
611 static void sctp_cmd_hb_timers_start(sctp_cmd_seq_t *cmds,
612 struct sctp_association *asoc)
614 struct sctp_transport *t;
616 /* Start a heartbeat timer for each transport on the association.
617 * hold a reference on the transport to make sure none of
618 * the needed data structures go away.
620 list_for_each_entry(t, &asoc->peer.transport_addr_list, transports) {
622 if (!mod_timer(&t->hb_timer, sctp_transport_timeout(t)))
623 sctp_transport_hold(t);
627 static void sctp_cmd_hb_timers_stop(sctp_cmd_seq_t *cmds,
628 struct sctp_association *asoc)
630 struct sctp_transport *t;
632 /* Stop all heartbeat timers. */
634 list_for_each_entry(t, &asoc->peer.transport_addr_list,
636 if (del_timer(&t->hb_timer))
637 sctp_transport_put(t);
641 /* Helper function to stop any pending T3-RTX timers */
642 static void sctp_cmd_t3_rtx_timers_stop(sctp_cmd_seq_t *cmds,
643 struct sctp_association *asoc)
645 struct sctp_transport *t;
647 list_for_each_entry(t, &asoc->peer.transport_addr_list,
649 if (timer_pending(&t->T3_rtx_timer) &&
650 del_timer(&t->T3_rtx_timer)) {
651 sctp_transport_put(t);
657 /* Helper function to update the heartbeat timer. */
658 static void sctp_cmd_hb_timer_update(sctp_cmd_seq_t *cmds,
659 struct sctp_transport *t)
661 /* Update the heartbeat timer. */
662 if (!mod_timer(&t->hb_timer, sctp_transport_timeout(t)))
663 sctp_transport_hold(t);
666 /* Helper function to handle the reception of an HEARTBEAT ACK. */
667 static void sctp_cmd_transport_on(sctp_cmd_seq_t *cmds,
668 struct sctp_association *asoc,
669 struct sctp_transport *t,
670 struct sctp_chunk *chunk)
672 sctp_sender_hb_info_t *hbinfo;
674 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of the
675 * HEARTBEAT should clear the error counter of the destination
676 * transport address to which the HEARTBEAT was sent.
681 * Although RFC4960 specifies that the overall error count must
682 * be cleared when a HEARTBEAT ACK is received, we make an
683 * exception while in SHUTDOWN PENDING. If the peer keeps its
684 * window shut forever, we may never be able to transmit our
685 * outstanding data and rely on the retransmission limit be reached
686 * to shutdown the association.
688 if (t->asoc->state < SCTP_STATE_SHUTDOWN_PENDING)
689 t->asoc->overall_error_count = 0;
691 /* Clear the hb_sent flag to signal that we had a good
696 /* Mark the destination transport address as active if it is not so
699 if ((t->state == SCTP_INACTIVE) || (t->state == SCTP_UNCONFIRMED))
700 sctp_assoc_control_transport(asoc, t, SCTP_TRANSPORT_UP,
701 SCTP_HEARTBEAT_SUCCESS);
703 /* The receiver of the HEARTBEAT ACK should also perform an
704 * RTT measurement for that destination transport address
705 * using the time value carried in the HEARTBEAT ACK chunk.
706 * If the transport's rto_pending variable has been cleared,
707 * it was most likely due to a retransmit. However, we want
708 * to re-enable it to properly update the rto.
710 if (t->rto_pending == 0)
713 hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data;
714 sctp_transport_update_rto(t, (jiffies - hbinfo->sent_at));
716 /* Update the heartbeat timer. */
717 if (!mod_timer(&t->hb_timer, sctp_transport_timeout(t)))
718 sctp_transport_hold(t);
722 /* Helper function to process the process SACK command. */
723 static int sctp_cmd_process_sack(sctp_cmd_seq_t *cmds,
724 struct sctp_association *asoc,
725 struct sctp_sackhdr *sackh)
729 if (sctp_outq_sack(&asoc->outqueue, sackh)) {
730 /* There are no more TSNs awaiting SACK. */
731 err = sctp_do_sm(SCTP_EVENT_T_OTHER,
732 SCTP_ST_OTHER(SCTP_EVENT_NO_PENDING_TSN),
733 asoc->state, asoc->ep, asoc, NULL,
740 /* Helper function to set the timeout value for T2-SHUTDOWN timer and to set
741 * the transport for a shutdown chunk.
743 static void sctp_cmd_setup_t2(sctp_cmd_seq_t *cmds,
744 struct sctp_association *asoc,
745 struct sctp_chunk *chunk)
747 struct sctp_transport *t;
749 if (chunk->transport)
750 t = chunk->transport;
752 t = sctp_assoc_choose_alter_transport(asoc,
753 asoc->shutdown_last_sent_to);
754 chunk->transport = t;
756 asoc->shutdown_last_sent_to = t;
757 asoc->timeouts[SCTP_EVENT_TIMEOUT_T2_SHUTDOWN] = t->rto;
760 /* Helper function to change the state of an association. */
761 static void sctp_cmd_new_state(sctp_cmd_seq_t *cmds,
762 struct sctp_association *asoc,
765 struct sock *sk = asoc->base.sk;
769 SCTP_DEBUG_PRINTK("sctp_cmd_new_state: asoc %p[%s]\n",
770 asoc, sctp_state_tbl[state]);
772 if (sctp_style(sk, TCP)) {
773 /* Change the sk->sk_state of a TCP-style socket that has
774 * successfully completed a connect() call.
776 if (sctp_state(asoc, ESTABLISHED) && sctp_sstate(sk, CLOSED))
777 sk->sk_state = SCTP_SS_ESTABLISHED;
779 /* Set the RCV_SHUTDOWN flag when a SHUTDOWN is received. */
780 if (sctp_state(asoc, SHUTDOWN_RECEIVED) &&
781 sctp_sstate(sk, ESTABLISHED))
782 sk->sk_shutdown |= RCV_SHUTDOWN;
785 if (sctp_state(asoc, COOKIE_WAIT)) {
786 /* Reset init timeouts since they may have been
787 * increased due to timer expirations.
789 asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_INIT] =
791 asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE] =
795 if (sctp_state(asoc, ESTABLISHED) ||
796 sctp_state(asoc, CLOSED) ||
797 sctp_state(asoc, SHUTDOWN_RECEIVED)) {
798 /* Wake up any processes waiting in the asoc's wait queue in
799 * sctp_wait_for_connect() or sctp_wait_for_sndbuf().
801 if (waitqueue_active(&asoc->wait))
802 wake_up_interruptible(&asoc->wait);
804 /* Wake up any processes waiting in the sk's sleep queue of
805 * a TCP-style or UDP-style peeled-off socket in
806 * sctp_wait_for_accept() or sctp_wait_for_packet().
807 * For a UDP-style socket, the waiters are woken up by the
810 if (!sctp_style(sk, UDP))
811 sk->sk_state_change(sk);
815 /* Helper function to delete an association. */
816 static void sctp_cmd_delete_tcb(sctp_cmd_seq_t *cmds,
817 struct sctp_association *asoc)
819 struct sock *sk = asoc->base.sk;
821 /* If it is a non-temporary association belonging to a TCP-style
822 * listening socket that is not closed, do not free it so that accept()
823 * can pick it up later.
825 if (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING) &&
826 (!asoc->temp) && (sk->sk_shutdown != SHUTDOWN_MASK))
829 sctp_unhash_established(asoc);
830 sctp_association_free(asoc);
834 * ADDIP Section 4.1 ASCONF Chunk Procedures
835 * A4) Start a T-4 RTO timer, using the RTO value of the selected
836 * destination address (we use active path instead of primary path just
837 * because primary path may be inactive.
839 static void sctp_cmd_setup_t4(sctp_cmd_seq_t *cmds,
840 struct sctp_association *asoc,
841 struct sctp_chunk *chunk)
843 struct sctp_transport *t;
845 t = sctp_assoc_choose_alter_transport(asoc, chunk->transport);
846 asoc->timeouts[SCTP_EVENT_TIMEOUT_T4_RTO] = t->rto;
847 chunk->transport = t;
850 /* Process an incoming Operation Error Chunk. */
851 static void sctp_cmd_process_operr(sctp_cmd_seq_t *cmds,
852 struct sctp_association *asoc,
853 struct sctp_chunk *chunk)
855 struct sctp_errhdr *err_hdr;
856 struct sctp_ulpevent *ev;
858 while (chunk->chunk_end > chunk->skb->data) {
859 err_hdr = (struct sctp_errhdr *)(chunk->skb->data);
861 ev = sctp_ulpevent_make_remote_error(asoc, chunk, 0,
866 sctp_ulpq_tail_event(&asoc->ulpq, ev);
868 switch (err_hdr->cause) {
869 case SCTP_ERROR_UNKNOWN_CHUNK:
871 sctp_chunkhdr_t *unk_chunk_hdr;
873 unk_chunk_hdr = (sctp_chunkhdr_t *)err_hdr->variable;
874 switch (unk_chunk_hdr->type) {
875 /* ADDIP 4.1 A9) If the peer responds to an ASCONF with
876 * an ERROR chunk reporting that it did not recognized
877 * the ASCONF chunk type, the sender of the ASCONF MUST
878 * NOT send any further ASCONF chunks and MUST stop its
881 case SCTP_CID_ASCONF:
882 if (asoc->peer.asconf_capable == 0)
885 asoc->peer.asconf_capable = 0;
886 sctp_add_cmd_sf(cmds, SCTP_CMD_TIMER_STOP,
887 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
900 /* Process variable FWDTSN chunk information. */
901 static void sctp_cmd_process_fwdtsn(struct sctp_ulpq *ulpq,
902 struct sctp_chunk *chunk)
904 struct sctp_fwdtsn_skip *skip;
905 /* Walk through all the skipped SSNs */
906 sctp_walk_fwdtsn(skip, chunk) {
907 sctp_ulpq_skip(ulpq, ntohs(skip->stream), ntohs(skip->ssn));
911 /* Helper function to remove the association non-primary peer
914 static void sctp_cmd_del_non_primary(struct sctp_association *asoc)
916 struct sctp_transport *t;
917 struct list_head *pos;
918 struct list_head *temp;
920 list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
921 t = list_entry(pos, struct sctp_transport, transports);
922 if (!sctp_cmp_addr_exact(&t->ipaddr,
923 &asoc->peer.primary_addr)) {
924 sctp_assoc_del_peer(asoc, &t->ipaddr);
929 /* Helper function to set sk_err on a 1-1 style socket. */
930 static void sctp_cmd_set_sk_err(struct sctp_association *asoc, int error)
932 struct sock *sk = asoc->base.sk;
934 if (!sctp_style(sk, UDP))
938 /* Helper function to generate an association change event */
939 static void sctp_cmd_assoc_change(sctp_cmd_seq_t *commands,
940 struct sctp_association *asoc,
943 struct sctp_ulpevent *ev;
945 ev = sctp_ulpevent_make_assoc_change(asoc, 0, state, 0,
946 asoc->c.sinit_num_ostreams,
947 asoc->c.sinit_max_instreams,
950 sctp_ulpq_tail_event(&asoc->ulpq, ev);
953 /* Helper function to generate an adaptation indication event */
954 static void sctp_cmd_adaptation_ind(sctp_cmd_seq_t *commands,
955 struct sctp_association *asoc)
957 struct sctp_ulpevent *ev;
959 ev = sctp_ulpevent_make_adaptation_indication(asoc, GFP_ATOMIC);
962 sctp_ulpq_tail_event(&asoc->ulpq, ev);
966 static void sctp_cmd_t1_timer_update(struct sctp_association *asoc,
967 sctp_event_timeout_t timer,
970 struct sctp_transport *t;
972 t = asoc->init_last_sent_to;
973 asoc->init_err_counter++;
975 if (t->init_sent_count > (asoc->init_cycle + 1)) {
976 asoc->timeouts[timer] *= 2;
977 if (asoc->timeouts[timer] > asoc->max_init_timeo) {
978 asoc->timeouts[timer] = asoc->max_init_timeo;
982 "T1 %s Timeout adjustment"
983 " init_err_counter: %d"
987 asoc->init_err_counter,
989 asoc->timeouts[timer]);
994 /* Send the whole message, chunk by chunk, to the outqueue.
995 * This way the whole message is queued up and bundling if
996 * encouraged for small fragments.
998 static int sctp_cmd_send_msg(struct sctp_association *asoc,
999 struct sctp_datamsg *msg)
1001 struct sctp_chunk *chunk;
1004 list_for_each_entry(chunk, &msg->chunks, frag_list) {
1005 error = sctp_outq_tail(&asoc->outqueue, chunk);
1014 /* Sent the next ASCONF packet currently stored in the association.
1015 * This happens after the ASCONF_ACK was succeffully processed.
1017 static void sctp_cmd_send_asconf(struct sctp_association *asoc)
1019 /* Send the next asconf chunk from the addip chunk
1022 if (!list_empty(&asoc->addip_chunk_list)) {
1023 struct list_head *entry = asoc->addip_chunk_list.next;
1024 struct sctp_chunk *asconf = list_entry(entry,
1025 struct sctp_chunk, list);
1026 list_del_init(entry);
1028 /* Hold the chunk until an ASCONF_ACK is received. */
1029 sctp_chunk_hold(asconf);
1030 if (sctp_primitive_ASCONF(asoc, asconf))
1031 sctp_chunk_free(asconf);
1033 asoc->addip_last_asconf = asconf;
1038 /* These three macros allow us to pull the debugging code out of the
1039 * main flow of sctp_do_sm() to keep attention focused on the real
1040 * functionality there.
1043 SCTP_DEBUG_PRINTK("sctp_do_sm prefn: " \
1044 "ep %p, %s, %s, asoc %p[%s], %s\n", \
1045 ep, sctp_evttype_tbl[event_type], \
1046 (*debug_fn)(subtype), asoc, \
1047 sctp_state_tbl[state], state_fn->name)
1049 #define DEBUG_POST \
1050 SCTP_DEBUG_PRINTK("sctp_do_sm postfn: " \
1051 "asoc %p, status: %s\n", \
1052 asoc, sctp_status_tbl[status])
1054 #define DEBUG_POST_SFX \
1055 SCTP_DEBUG_PRINTK("sctp_do_sm post sfx: error %d, asoc %p[%s]\n", \
1057 sctp_state_tbl[(asoc && sctp_id2assoc(ep->base.sk, \
1058 sctp_assoc2id(asoc)))?asoc->state:SCTP_STATE_CLOSED])
1061 * This is the master state machine processing function.
1063 * If you want to understand all of lksctp, this is a
1064 * good place to start.
1066 int sctp_do_sm(sctp_event_t event_type, sctp_subtype_t subtype,
1068 struct sctp_endpoint *ep,
1069 struct sctp_association *asoc,
1073 sctp_cmd_seq_t commands;
1074 const sctp_sm_table_entry_t *state_fn;
1075 sctp_disposition_t status;
1077 typedef const char *(printfn_t)(sctp_subtype_t);
1079 static printfn_t *table[] = {
1080 NULL, sctp_cname, sctp_tname, sctp_oname, sctp_pname,
1082 printfn_t *debug_fn __attribute__ ((unused)) = table[event_type];
1084 /* Look up the state function, run it, and then process the
1085 * side effects. These three steps are the heart of lksctp.
1087 state_fn = sctp_sm_lookup_event(event_type, state, subtype);
1089 sctp_init_cmd_seq(&commands);
1092 status = (*state_fn->fn)(ep, asoc, subtype, event_arg, &commands);
1095 error = sctp_side_effects(event_type, subtype, state,
1096 ep, asoc, event_arg, status,
1106 /*****************************************************************
1107 * This the master state function side effect processing function.
1108 *****************************************************************/
1109 static int sctp_side_effects(sctp_event_t event_type, sctp_subtype_t subtype,
1111 struct sctp_endpoint *ep,
1112 struct sctp_association *asoc,
1114 sctp_disposition_t status,
1115 sctp_cmd_seq_t *commands,
1120 /* FIXME - Most of the dispositions left today would be categorized
1121 * as "exceptional" dispositions. For those dispositions, it
1122 * may not be proper to run through any of the commands at all.
1123 * For example, the command interpreter might be run only with
1124 * disposition SCTP_DISPOSITION_CONSUME.
1126 if (0 != (error = sctp_cmd_interpreter(event_type, subtype, state,
1133 case SCTP_DISPOSITION_DISCARD:
1134 SCTP_DEBUG_PRINTK("Ignored sctp protocol event - state %d, "
1135 "event_type %d, event_id %d\n",
1136 state, event_type, subtype.chunk);
1139 case SCTP_DISPOSITION_NOMEM:
1140 /* We ran out of memory, so we need to discard this
1143 /* BUG--we should now recover some memory, probably by
1149 case SCTP_DISPOSITION_DELETE_TCB:
1150 /* This should now be a command. */
1153 case SCTP_DISPOSITION_CONSUME:
1154 case SCTP_DISPOSITION_ABORT:
1156 * We should no longer have much work to do here as the
1157 * real work has been done as explicit commands above.
1161 case SCTP_DISPOSITION_VIOLATION:
1162 if (net_ratelimit())
1163 pr_err("protocol violation state %d chunkid %d\n",
1164 state, subtype.chunk);
1167 case SCTP_DISPOSITION_NOT_IMPL:
1168 pr_warn("unimplemented feature in state %d, event_type %d, event_id %d\n",
1169 state, event_type, subtype.chunk);
1172 case SCTP_DISPOSITION_BUG:
1173 pr_err("bug in state %d, event_type %d, event_id %d\n",
1174 state, event_type, subtype.chunk);
1179 pr_err("impossible disposition %d in state %d, event_type %d, event_id %d\n",
1180 status, state, event_type, subtype.chunk);
1189 /********************************************************************
1190 * 2nd Level Abstractions
1191 ********************************************************************/
1193 /* This is the side-effect interpreter. */
1194 static int sctp_cmd_interpreter(sctp_event_t event_type,
1195 sctp_subtype_t subtype,
1197 struct sctp_endpoint *ep,
1198 struct sctp_association *asoc,
1200 sctp_disposition_t status,
1201 sctp_cmd_seq_t *commands,
1207 struct sctp_chunk *new_obj;
1208 struct sctp_chunk *chunk = NULL;
1209 struct sctp_packet *packet;
1210 struct timer_list *timer;
1211 unsigned long timeout;
1212 struct sctp_transport *t;
1213 struct sctp_sackhdr sackh;
1216 if (SCTP_EVENT_T_TIMEOUT != event_type)
1219 /* Note: This whole file is a huge candidate for rework.
1220 * For example, each command could either have its own handler, so
1221 * the loop would look like:
1223 * cmd->handle(x, y, z)
1226 while (NULL != (cmd = sctp_next_cmd(commands))) {
1227 switch (cmd->verb) {
1232 case SCTP_CMD_NEW_ASOC:
1233 /* Register a new association. */
1235 sctp_outq_uncork(&asoc->outqueue);
1238 asoc = cmd->obj.ptr;
1239 /* Register with the endpoint. */
1240 sctp_endpoint_add_asoc(ep, asoc);
1241 sctp_hash_established(asoc);
1244 case SCTP_CMD_UPDATE_ASSOC:
1245 sctp_assoc_update(asoc, cmd->obj.ptr);
1248 case SCTP_CMD_PURGE_OUTQUEUE:
1249 sctp_outq_teardown(&asoc->outqueue);
1252 case SCTP_CMD_DELETE_TCB:
1254 sctp_outq_uncork(&asoc->outqueue);
1257 /* Delete the current association. */
1258 sctp_cmd_delete_tcb(commands, asoc);
1262 case SCTP_CMD_NEW_STATE:
1263 /* Enter a new state. */
1264 sctp_cmd_new_state(commands, asoc, cmd->obj.state);
1267 case SCTP_CMD_REPORT_TSN:
1268 /* Record the arrival of a TSN. */
1269 error = sctp_tsnmap_mark(&asoc->peer.tsn_map,
1273 case SCTP_CMD_REPORT_FWDTSN:
1274 /* Move the Cumulattive TSN Ack ahead. */
1275 sctp_tsnmap_skip(&asoc->peer.tsn_map, cmd->obj.u32);
1277 /* purge the fragmentation queue */
1278 sctp_ulpq_reasm_flushtsn(&asoc->ulpq, cmd->obj.u32);
1280 /* Abort any in progress partial delivery. */
1281 sctp_ulpq_abort_pd(&asoc->ulpq, GFP_ATOMIC);
1284 case SCTP_CMD_PROCESS_FWDTSN:
1285 sctp_cmd_process_fwdtsn(&asoc->ulpq, cmd->obj.ptr);
1288 case SCTP_CMD_GEN_SACK:
1289 /* Generate a Selective ACK.
1290 * The argument tells us whether to just count
1291 * the packet and MAYBE generate a SACK, or
1294 force = cmd->obj.i32;
1295 error = sctp_gen_sack(asoc, force, commands);
1298 case SCTP_CMD_PROCESS_SACK:
1299 /* Process an inbound SACK. */
1300 error = sctp_cmd_process_sack(commands, asoc,
1304 case SCTP_CMD_GEN_INIT_ACK:
1305 /* Generate an INIT ACK chunk. */
1306 new_obj = sctp_make_init_ack(asoc, chunk, GFP_ATOMIC,
1311 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1312 SCTP_CHUNK(new_obj));
1315 case SCTP_CMD_PEER_INIT:
1316 /* Process a unified INIT from the peer.
1317 * Note: Only used during INIT-ACK processing. If
1318 * there is an error just return to the outter
1319 * layer which will bail.
1321 error = sctp_cmd_process_init(commands, asoc, chunk,
1325 case SCTP_CMD_GEN_COOKIE_ECHO:
1326 /* Generate a COOKIE ECHO chunk. */
1327 new_obj = sctp_make_cookie_echo(asoc, chunk);
1330 sctp_chunk_free(cmd->obj.ptr);
1333 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1334 SCTP_CHUNK(new_obj));
1336 /* If there is an ERROR chunk to be sent along with
1337 * the COOKIE_ECHO, send it, too.
1340 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1341 SCTP_CHUNK(cmd->obj.ptr));
1343 if (new_obj->transport) {
1344 new_obj->transport->init_sent_count++;
1345 asoc->init_last_sent_to = new_obj->transport;
1348 /* FIXME - Eventually come up with a cleaner way to
1349 * enabling COOKIE-ECHO + DATA bundling during
1350 * multihoming stale cookie scenarios, the following
1351 * command plays with asoc->peer.retran_path to
1352 * avoid the problem of sending the COOKIE-ECHO and
1353 * DATA in different paths, which could result
1354 * in the association being ABORTed if the DATA chunk
1355 * is processed first by the server. Checking the
1356 * init error counter simply causes this command
1357 * to be executed only during failed attempts of
1358 * association establishment.
1360 if ((asoc->peer.retran_path !=
1361 asoc->peer.primary_path) &&
1362 (asoc->init_err_counter > 0)) {
1363 sctp_add_cmd_sf(commands,
1364 SCTP_CMD_FORCE_PRIM_RETRAN,
1370 case SCTP_CMD_GEN_SHUTDOWN:
1371 /* Generate SHUTDOWN when in SHUTDOWN_SENT state.
1372 * Reset error counts.
1374 asoc->overall_error_count = 0;
1376 /* Generate a SHUTDOWN chunk. */
1377 new_obj = sctp_make_shutdown(asoc, chunk);
1380 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1381 SCTP_CHUNK(new_obj));
1384 case SCTP_CMD_CHUNK_ULP:
1385 /* Send a chunk to the sockets layer. */
1386 SCTP_DEBUG_PRINTK("sm_sideff: %s %p, %s %p.\n",
1387 "chunk_up:", cmd->obj.ptr,
1388 "ulpq:", &asoc->ulpq);
1389 sctp_ulpq_tail_data(&asoc->ulpq, cmd->obj.ptr,
1393 case SCTP_CMD_EVENT_ULP:
1394 /* Send a notification to the sockets layer. */
1395 SCTP_DEBUG_PRINTK("sm_sideff: %s %p, %s %p.\n",
1396 "event_up:",cmd->obj.ptr,
1397 "ulpq:",&asoc->ulpq);
1398 sctp_ulpq_tail_event(&asoc->ulpq, cmd->obj.ptr);
1401 case SCTP_CMD_REPLY:
1402 /* If an caller has not already corked, do cork. */
1403 if (!asoc->outqueue.cork) {
1404 sctp_outq_cork(&asoc->outqueue);
1407 /* Send a chunk to our peer. */
1408 error = sctp_outq_tail(&asoc->outqueue, cmd->obj.ptr);
1411 case SCTP_CMD_SEND_PKT:
1412 /* Send a full packet to our peer. */
1413 packet = cmd->obj.ptr;
1414 sctp_packet_transmit(packet);
1415 sctp_ootb_pkt_free(packet);
1418 case SCTP_CMD_T1_RETRAN:
1419 /* Mark a transport for retransmission. */
1420 sctp_retransmit(&asoc->outqueue, cmd->obj.transport,
1424 case SCTP_CMD_RETRAN:
1425 /* Mark a transport for retransmission. */
1426 sctp_retransmit(&asoc->outqueue, cmd->obj.transport,
1430 case SCTP_CMD_ECN_CE:
1431 /* Do delayed CE processing. */
1432 sctp_do_ecn_ce_work(asoc, cmd->obj.u32);
1435 case SCTP_CMD_ECN_ECNE:
1436 /* Do delayed ECNE processing. */
1437 new_obj = sctp_do_ecn_ecne_work(asoc, cmd->obj.u32,
1440 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1441 SCTP_CHUNK(new_obj));
1444 case SCTP_CMD_ECN_CWR:
1445 /* Do delayed CWR processing. */
1446 sctp_do_ecn_cwr_work(asoc, cmd->obj.u32);
1449 case SCTP_CMD_SETUP_T2:
1450 sctp_cmd_setup_t2(commands, asoc, cmd->obj.ptr);
1453 case SCTP_CMD_TIMER_START_ONCE:
1454 timer = &asoc->timers[cmd->obj.to];
1456 if (timer_pending(timer))
1460 case SCTP_CMD_TIMER_START:
1461 timer = &asoc->timers[cmd->obj.to];
1462 timeout = asoc->timeouts[cmd->obj.to];
1465 timer->expires = jiffies + timeout;
1466 sctp_association_hold(asoc);
1470 case SCTP_CMD_TIMER_RESTART:
1471 timer = &asoc->timers[cmd->obj.to];
1472 timeout = asoc->timeouts[cmd->obj.to];
1473 if (!mod_timer(timer, jiffies + timeout))
1474 sctp_association_hold(asoc);
1477 case SCTP_CMD_TIMER_STOP:
1478 timer = &asoc->timers[cmd->obj.to];
1479 if (timer_pending(timer) && del_timer(timer))
1480 sctp_association_put(asoc);
1483 case SCTP_CMD_INIT_CHOOSE_TRANSPORT:
1484 chunk = cmd->obj.ptr;
1485 t = sctp_assoc_choose_alter_transport(asoc,
1486 asoc->init_last_sent_to);
1487 asoc->init_last_sent_to = t;
1488 chunk->transport = t;
1489 t->init_sent_count++;
1490 /* Set the new transport as primary */
1491 sctp_assoc_set_primary(asoc, t);
1494 case SCTP_CMD_INIT_RESTART:
1495 /* Do the needed accounting and updates
1496 * associated with restarting an initialization
1497 * timer. Only multiply the timeout by two if
1498 * all transports have been tried at the current
1501 sctp_cmd_t1_timer_update(asoc,
1502 SCTP_EVENT_TIMEOUT_T1_INIT,
1505 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
1506 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
1509 case SCTP_CMD_COOKIEECHO_RESTART:
1510 /* Do the needed accounting and updates
1511 * associated with restarting an initialization
1512 * timer. Only multiply the timeout by two if
1513 * all transports have been tried at the current
1516 sctp_cmd_t1_timer_update(asoc,
1517 SCTP_EVENT_TIMEOUT_T1_COOKIE,
1520 /* If we've sent any data bundled with
1521 * COOKIE-ECHO we need to resend.
1523 list_for_each_entry(t, &asoc->peer.transport_addr_list,
1525 sctp_retransmit_mark(&asoc->outqueue, t,
1529 sctp_add_cmd_sf(commands,
1530 SCTP_CMD_TIMER_RESTART,
1531 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
1534 case SCTP_CMD_INIT_FAILED:
1535 sctp_cmd_init_failed(commands, asoc, cmd->obj.err);
1538 case SCTP_CMD_ASSOC_FAILED:
1539 sctp_cmd_assoc_failed(commands, asoc, event_type,
1540 subtype, chunk, cmd->obj.err);
1543 case SCTP_CMD_INIT_COUNTER_INC:
1544 asoc->init_err_counter++;
1547 case SCTP_CMD_INIT_COUNTER_RESET:
1548 asoc->init_err_counter = 0;
1549 asoc->init_cycle = 0;
1550 list_for_each_entry(t, &asoc->peer.transport_addr_list,
1552 t->init_sent_count = 0;
1556 case SCTP_CMD_REPORT_DUP:
1557 sctp_tsnmap_mark_dup(&asoc->peer.tsn_map,
1561 case SCTP_CMD_REPORT_BAD_TAG:
1562 SCTP_DEBUG_PRINTK("vtag mismatch!\n");
1565 case SCTP_CMD_STRIKE:
1566 /* Mark one strike against a transport. */
1567 sctp_do_8_2_transport_strike(asoc, cmd->obj.transport,
1571 case SCTP_CMD_TRANSPORT_IDLE:
1572 t = cmd->obj.transport;
1573 sctp_transport_lower_cwnd(t, SCTP_LOWER_CWND_INACTIVE);
1576 case SCTP_CMD_TRANSPORT_HB_SENT:
1577 t = cmd->obj.transport;
1578 sctp_do_8_2_transport_strike(asoc, t, 1);
1582 case SCTP_CMD_TRANSPORT_ON:
1583 t = cmd->obj.transport;
1584 sctp_cmd_transport_on(commands, asoc, t, chunk);
1587 case SCTP_CMD_HB_TIMERS_START:
1588 sctp_cmd_hb_timers_start(commands, asoc);
1591 case SCTP_CMD_HB_TIMER_UPDATE:
1592 t = cmd->obj.transport;
1593 sctp_cmd_hb_timer_update(commands, t);
1596 case SCTP_CMD_HB_TIMERS_STOP:
1597 sctp_cmd_hb_timers_stop(commands, asoc);
1600 case SCTP_CMD_REPORT_ERROR:
1601 error = cmd->obj.error;
1604 case SCTP_CMD_PROCESS_CTSN:
1605 /* Dummy up a SACK for processing. */
1606 sackh.cum_tsn_ack = cmd->obj.be32;
1607 sackh.a_rwnd = asoc->peer.rwnd +
1608 asoc->outqueue.outstanding_bytes;
1609 sackh.num_gap_ack_blocks = 0;
1610 sackh.num_dup_tsns = 0;
1611 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK,
1612 SCTP_SACKH(&sackh));
1615 case SCTP_CMD_DISCARD_PACKET:
1616 /* We need to discard the whole packet.
1617 * Uncork the queue since there might be
1620 chunk->pdiscard = 1;
1622 sctp_outq_uncork(&asoc->outqueue);
1627 case SCTP_CMD_RTO_PENDING:
1628 t = cmd->obj.transport;
1632 case SCTP_CMD_PART_DELIVER:
1633 sctp_ulpq_partial_delivery(&asoc->ulpq, cmd->obj.ptr,
1637 case SCTP_CMD_RENEGE:
1638 sctp_ulpq_renege(&asoc->ulpq, cmd->obj.ptr,
1642 case SCTP_CMD_SETUP_T4:
1643 sctp_cmd_setup_t4(commands, asoc, cmd->obj.ptr);
1646 case SCTP_CMD_PROCESS_OPERR:
1647 sctp_cmd_process_operr(commands, asoc, chunk);
1649 case SCTP_CMD_CLEAR_INIT_TAG:
1650 asoc->peer.i.init_tag = 0;
1652 case SCTP_CMD_DEL_NON_PRIMARY:
1653 sctp_cmd_del_non_primary(asoc);
1655 case SCTP_CMD_T3_RTX_TIMERS_STOP:
1656 sctp_cmd_t3_rtx_timers_stop(commands, asoc);
1658 case SCTP_CMD_FORCE_PRIM_RETRAN:
1659 t = asoc->peer.retran_path;
1660 asoc->peer.retran_path = asoc->peer.primary_path;
1661 error = sctp_outq_uncork(&asoc->outqueue);
1663 asoc->peer.retran_path = t;
1665 case SCTP_CMD_SET_SK_ERR:
1666 sctp_cmd_set_sk_err(asoc, cmd->obj.error);
1668 case SCTP_CMD_ASSOC_CHANGE:
1669 sctp_cmd_assoc_change(commands, asoc,
1672 case SCTP_CMD_ADAPTATION_IND:
1673 sctp_cmd_adaptation_ind(commands, asoc);
1676 case SCTP_CMD_ASSOC_SHKEY:
1677 error = sctp_auth_asoc_init_active_key(asoc,
1680 case SCTP_CMD_UPDATE_INITTAG:
1681 asoc->peer.i.init_tag = cmd->obj.u32;
1683 case SCTP_CMD_SEND_MSG:
1684 if (!asoc->outqueue.cork) {
1685 sctp_outq_cork(&asoc->outqueue);
1688 error = sctp_cmd_send_msg(asoc, cmd->obj.msg);
1690 case SCTP_CMD_SEND_NEXT_ASCONF:
1691 sctp_cmd_send_asconf(asoc);
1693 case SCTP_CMD_PURGE_ASCONF_QUEUE:
1694 sctp_asconf_queue_teardown(asoc);
1697 case SCTP_CMD_SET_ASOC:
1698 asoc = cmd->obj.asoc;
1702 pr_warn("Impossible command: %u, %p\n",
1703 cmd->verb, cmd->obj.ptr);
1712 /* If this is in response to a received chunk, wait until
1713 * we are done with the packet to open the queue so that we don't
1714 * send multiple packets in response to a single request.
1716 if (asoc && SCTP_EVENT_T_CHUNK == event_type && chunk) {
1717 if (chunk->end_of_packet || chunk->singleton)
1718 error = sctp_outq_uncork(&asoc->outqueue);
1719 } else if (local_cork)
1720 error = sctp_outq_uncork(&asoc->outqueue);