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 #include <linux/skbuff.h>
51 #include <linux/types.h>
52 #include <linux/socket.h>
55 #include <net/sctp/sctp.h>
56 #include <net/sctp/sm.h>
58 static int sctp_cmd_interpreter(sctp_event_t event_type
,
59 sctp_subtype_t subtype
,
61 struct sctp_endpoint
*ep
,
62 struct sctp_association
*asoc
,
64 sctp_disposition_t status
,
65 sctp_cmd_seq_t
*commands
,
67 static int sctp_side_effects(sctp_event_t event_type
, sctp_subtype_t subtype
,
69 struct sctp_endpoint
*ep
,
70 struct sctp_association
*asoc
,
72 sctp_disposition_t status
,
73 sctp_cmd_seq_t
*commands
,
76 /********************************************************************
78 ********************************************************************/
80 /* A helper function for delayed processing of INET ECN CE bit. */
81 static void sctp_do_ecn_ce_work(struct sctp_association
*asoc
,
84 /* Save the TSN away for comparison when we receive CWR */
86 asoc
->last_ecne_tsn
= lowest_tsn
;
90 /* Helper function for delayed processing of SCTP ECNE chunk. */
91 /* RFC 2960 Appendix A
93 * RFC 2481 details a specific bit for a sender to send in
94 * the header of its next outbound TCP segment to indicate to
95 * its peer that it has reduced its congestion window. This
96 * is termed the CWR bit. For SCTP the same indication is made
97 * by including the CWR chunk. This chunk contains one data
98 * element, i.e. the TSN number that was sent in the ECNE chunk.
99 * This element represents the lowest TSN number in the datagram
100 * that was originally marked with the CE bit.
102 static struct sctp_chunk
*sctp_do_ecn_ecne_work(struct sctp_association
*asoc
,
104 struct sctp_chunk
*chunk
)
106 struct sctp_chunk
*repl
;
108 /* Our previously transmitted packet ran into some congestion
109 * so we should take action by reducing cwnd and ssthresh
110 * and then ACK our peer that we we've done so by
114 /* First, try to determine if we want to actually lower
115 * our cwnd variables. Only lower them if the ECNE looks more
116 * recent than the last response.
118 if (TSN_lt(asoc
->last_cwr_tsn
, lowest_tsn
)) {
119 struct sctp_transport
*transport
;
121 /* Find which transport's congestion variables
122 * need to be adjusted.
124 transport
= sctp_assoc_lookup_tsn(asoc
, lowest_tsn
);
126 /* Update the congestion variables. */
128 sctp_transport_lower_cwnd(transport
,
129 SCTP_LOWER_CWND_ECNE
);
130 asoc
->last_cwr_tsn
= lowest_tsn
;
133 /* Always try to quiet the other end. In case of lost CWR,
134 * resend last_cwr_tsn.
136 repl
= sctp_make_cwr(asoc
, asoc
->last_cwr_tsn
, chunk
);
138 /* If we run out of memory, it will look like a lost CWR. We'll
139 * get back in sync eventually.
144 /* Helper function to do delayed processing of ECN CWR chunk. */
145 static void sctp_do_ecn_cwr_work(struct sctp_association
*asoc
,
148 /* Turn off ECNE getting auto-prepended to every outgoing
154 /* Generate SACK if necessary. We call this at the end of a packet. */
155 static int sctp_gen_sack(struct sctp_association
*asoc
, int force
,
156 sctp_cmd_seq_t
*commands
)
158 __u32 ctsn
, max_tsn_seen
;
159 struct sctp_chunk
*sack
;
160 struct sctp_transport
*trans
= asoc
->peer
.last_data_from
;
164 (!trans
&& (asoc
->param_flags
& SPP_SACKDELAY_DISABLE
)) ||
165 (trans
&& (trans
->param_flags
& SPP_SACKDELAY_DISABLE
)))
166 asoc
->peer
.sack_needed
= 1;
168 ctsn
= sctp_tsnmap_get_ctsn(&asoc
->peer
.tsn_map
);
169 max_tsn_seen
= sctp_tsnmap_get_max_tsn_seen(&asoc
->peer
.tsn_map
);
171 /* From 12.2 Parameters necessary per association (i.e. the TCB):
173 * Ack State : This flag indicates if the next received packet
174 * : is to be responded to with a SACK. ...
175 * : When DATA chunks are out of order, SACK's
176 * : are not delayed (see Section 6).
178 * [This is actually not mentioned in Section 6, but we
179 * implement it here anyway. --piggy]
181 if (max_tsn_seen
!= ctsn
)
182 asoc
->peer
.sack_needed
= 1;
184 /* From 6.2 Acknowledgement on Reception of DATA Chunks:
186 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically,
187 * an acknowledgement SHOULD be generated for at least every
188 * second packet (not every second DATA chunk) received, and
189 * SHOULD be generated within 200 ms of the arrival of any
190 * unacknowledged DATA chunk. ...
192 if (!asoc
->peer
.sack_needed
) {
193 asoc
->peer
.sack_cnt
++;
195 /* Set the SACK delay timeout based on the
196 * SACK delay for the last transport
197 * data was received from, or the default
198 * for the association.
201 /* We will need a SACK for the next packet. */
202 if (asoc
->peer
.sack_cnt
>= trans
->sackfreq
- 1)
203 asoc
->peer
.sack_needed
= 1;
205 asoc
->timeouts
[SCTP_EVENT_TIMEOUT_SACK
] =
208 /* We will need a SACK for the next packet. */
209 if (asoc
->peer
.sack_cnt
>= asoc
->sackfreq
- 1)
210 asoc
->peer
.sack_needed
= 1;
212 asoc
->timeouts
[SCTP_EVENT_TIMEOUT_SACK
] =
216 /* Restart the SACK timer. */
217 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
218 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK
));
220 if (asoc
->a_rwnd
> asoc
->rwnd
)
221 asoc
->a_rwnd
= asoc
->rwnd
;
222 sack
= sctp_make_sack(asoc
);
226 asoc
->peer
.sack_needed
= 0;
227 asoc
->peer
.sack_cnt
= 0;
229 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(sack
));
231 /* Stop the SACK timer. */
232 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
233 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK
));
242 /* When the T3-RTX timer expires, it calls this function to create the
243 * relevant state machine event.
245 void sctp_generate_t3_rtx_event(unsigned long peer
)
248 struct sctp_transport
*transport
= (struct sctp_transport
*) peer
;
249 struct sctp_association
*asoc
= transport
->asoc
;
251 /* Check whether a task is in the sock. */
253 sctp_bh_lock_sock(asoc
->base
.sk
);
254 if (sock_owned_by_user(asoc
->base
.sk
)) {
255 SCTP_DEBUG_PRINTK("%s:Sock is busy.\n", __func__
);
257 /* Try again later. */
258 if (!mod_timer(&transport
->T3_rtx_timer
, jiffies
+ (HZ
/20)))
259 sctp_transport_hold(transport
);
263 /* Is this transport really dead and just waiting around for
264 * the timer to let go of the reference?
269 /* Run through the state machine. */
270 error
= sctp_do_sm(SCTP_EVENT_T_TIMEOUT
,
271 SCTP_ST_TIMEOUT(SCTP_EVENT_TIMEOUT_T3_RTX
),
274 transport
, GFP_ATOMIC
);
277 asoc
->base
.sk
->sk_err
= -error
;
280 sctp_bh_unlock_sock(asoc
->base
.sk
);
281 sctp_transport_put(transport
);
284 /* This is a sa interface for producing timeout events. It works
285 * for timeouts which use the association as their parameter.
287 static void sctp_generate_timeout_event(struct sctp_association
*asoc
,
288 sctp_event_timeout_t timeout_type
)
292 sctp_bh_lock_sock(asoc
->base
.sk
);
293 if (sock_owned_by_user(asoc
->base
.sk
)) {
294 SCTP_DEBUG_PRINTK("%s:Sock is busy: timer %d\n",
298 /* Try again later. */
299 if (!mod_timer(&asoc
->timers
[timeout_type
], jiffies
+ (HZ
/20)))
300 sctp_association_hold(asoc
);
304 /* Is this association really dead and just waiting around for
305 * the timer to let go of the reference?
310 /* Run through the state machine. */
311 error
= sctp_do_sm(SCTP_EVENT_T_TIMEOUT
,
312 SCTP_ST_TIMEOUT(timeout_type
),
313 asoc
->state
, asoc
->ep
, asoc
,
314 (void *)timeout_type
, GFP_ATOMIC
);
317 asoc
->base
.sk
->sk_err
= -error
;
320 sctp_bh_unlock_sock(asoc
->base
.sk
);
321 sctp_association_put(asoc
);
324 static void sctp_generate_t1_cookie_event(unsigned long data
)
326 struct sctp_association
*asoc
= (struct sctp_association
*) data
;
327 sctp_generate_timeout_event(asoc
, SCTP_EVENT_TIMEOUT_T1_COOKIE
);
330 static void sctp_generate_t1_init_event(unsigned long data
)
332 struct sctp_association
*asoc
= (struct sctp_association
*) data
;
333 sctp_generate_timeout_event(asoc
, SCTP_EVENT_TIMEOUT_T1_INIT
);
336 static void sctp_generate_t2_shutdown_event(unsigned long data
)
338 struct sctp_association
*asoc
= (struct sctp_association
*) data
;
339 sctp_generate_timeout_event(asoc
, SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
);
342 static void sctp_generate_t4_rto_event(unsigned long data
)
344 struct sctp_association
*asoc
= (struct sctp_association
*) data
;
345 sctp_generate_timeout_event(asoc
, SCTP_EVENT_TIMEOUT_T4_RTO
);
348 static void sctp_generate_t5_shutdown_guard_event(unsigned long data
)
350 struct sctp_association
*asoc
= (struct sctp_association
*)data
;
351 sctp_generate_timeout_event(asoc
,
352 SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
);
354 } /* sctp_generate_t5_shutdown_guard_event() */
356 static void sctp_generate_autoclose_event(unsigned long data
)
358 struct sctp_association
*asoc
= (struct sctp_association
*) data
;
359 sctp_generate_timeout_event(asoc
, SCTP_EVENT_TIMEOUT_AUTOCLOSE
);
362 /* Generate a heart beat event. If the sock is busy, reschedule. Make
363 * sure that the transport is still valid.
365 void sctp_generate_heartbeat_event(unsigned long data
)
368 struct sctp_transport
*transport
= (struct sctp_transport
*) data
;
369 struct sctp_association
*asoc
= transport
->asoc
;
371 sctp_bh_lock_sock(asoc
->base
.sk
);
372 if (sock_owned_by_user(asoc
->base
.sk
)) {
373 SCTP_DEBUG_PRINTK("%s:Sock is busy.\n", __func__
);
375 /* Try again later. */
376 if (!mod_timer(&transport
->hb_timer
, jiffies
+ (HZ
/20)))
377 sctp_transport_hold(transport
);
381 /* Is this structure just waiting around for us to actually
387 error
= sctp_do_sm(SCTP_EVENT_T_TIMEOUT
,
388 SCTP_ST_TIMEOUT(SCTP_EVENT_TIMEOUT_HEARTBEAT
),
389 asoc
->state
, asoc
->ep
, asoc
,
390 transport
, GFP_ATOMIC
);
393 asoc
->base
.sk
->sk_err
= -error
;
396 sctp_bh_unlock_sock(asoc
->base
.sk
);
397 sctp_transport_put(transport
);
400 /* Handle the timeout of the ICMP protocol unreachable timer. Trigger
401 * the correct state machine transition that will close the association.
403 void sctp_generate_proto_unreach_event(unsigned long data
)
405 struct sctp_transport
*transport
= (struct sctp_transport
*) data
;
406 struct sctp_association
*asoc
= transport
->asoc
;
408 sctp_bh_lock_sock(asoc
->base
.sk
);
409 if (sock_owned_by_user(asoc
->base
.sk
)) {
410 SCTP_DEBUG_PRINTK("%s:Sock is busy.\n", __func__
);
412 /* Try again later. */
413 if (!mod_timer(&transport
->proto_unreach_timer
,
415 sctp_association_hold(asoc
);
419 /* Is this structure just waiting around for us to actually
425 sctp_do_sm(SCTP_EVENT_T_OTHER
,
426 SCTP_ST_OTHER(SCTP_EVENT_ICMP_PROTO_UNREACH
),
427 asoc
->state
, asoc
->ep
, asoc
, transport
, GFP_ATOMIC
);
430 sctp_bh_unlock_sock(asoc
->base
.sk
);
431 sctp_association_put(asoc
);
435 /* Inject a SACK Timeout event into the state machine. */
436 static void sctp_generate_sack_event(unsigned long data
)
438 struct sctp_association
*asoc
= (struct sctp_association
*) data
;
439 sctp_generate_timeout_event(asoc
, SCTP_EVENT_TIMEOUT_SACK
);
442 sctp_timer_event_t
*sctp_timer_events
[SCTP_NUM_TIMEOUT_TYPES
] = {
444 sctp_generate_t1_cookie_event
,
445 sctp_generate_t1_init_event
,
446 sctp_generate_t2_shutdown_event
,
448 sctp_generate_t4_rto_event
,
449 sctp_generate_t5_shutdown_guard_event
,
451 sctp_generate_sack_event
,
452 sctp_generate_autoclose_event
,
456 /* RFC 2960 8.2 Path Failure Detection
458 * When its peer endpoint is multi-homed, an endpoint should keep a
459 * error counter for each of the destination transport addresses of the
462 * Each time the T3-rtx timer expires on any address, or when a
463 * HEARTBEAT sent to an idle address is not acknowledged within a RTO,
464 * the error counter of that destination address will be incremented.
465 * When the value in the error counter exceeds the protocol parameter
466 * 'Path.Max.Retrans' of that destination address, the endpoint should
467 * mark the destination transport address as inactive, and a
468 * notification SHOULD be sent to the upper layer.
471 static void sctp_do_8_2_transport_strike(struct sctp_association
*asoc
,
472 struct sctp_transport
*transport
)
474 /* The check for association's overall error counter exceeding the
475 * threshold is done in the state function.
477 /* When probing UNCONFIRMED addresses, the association overall
478 * error count is NOT incremented
480 if (transport
->state
!= SCTP_UNCONFIRMED
)
481 asoc
->overall_error_count
++;
483 if (transport
->state
!= SCTP_INACTIVE
&&
484 (transport
->error_count
++ >= transport
->pathmaxrxt
)) {
485 SCTP_DEBUG_PRINTK_IPADDR("transport_strike:association %p",
486 " transport IP: port:%d failed.\n",
488 (&transport
->ipaddr
),
489 ntohs(transport
->ipaddr
.v4
.sin_port
));
490 sctp_assoc_control_transport(asoc
, transport
,
492 SCTP_FAILED_THRESHOLD
);
495 /* E2) For the destination address for which the timer
496 * expires, set RTO <- RTO * 2 ("back off the timer"). The
497 * maximum value discussed in rule C7 above (RTO.max) may be
498 * used to provide an upper bound to this doubling operation.
500 transport
->last_rto
= transport
->rto
;
501 transport
->rto
= min((transport
->rto
* 2), transport
->asoc
->rto_max
);
504 /* Worker routine to handle INIT command failure. */
505 static void sctp_cmd_init_failed(sctp_cmd_seq_t
*commands
,
506 struct sctp_association
*asoc
,
509 struct sctp_ulpevent
*event
;
511 event
= sctp_ulpevent_make_assoc_change(asoc
,0, SCTP_CANT_STR_ASSOC
,
512 (__u16
)error
, 0, 0, NULL
,
516 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
517 SCTP_ULPEVENT(event
));
519 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
520 SCTP_STATE(SCTP_STATE_CLOSED
));
522 /* SEND_FAILED sent later when cleaning up the association. */
523 asoc
->outqueue
.error
= error
;
524 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
527 /* Worker routine to handle SCTP_CMD_ASSOC_FAILED. */
528 static void sctp_cmd_assoc_failed(sctp_cmd_seq_t
*commands
,
529 struct sctp_association
*asoc
,
530 sctp_event_t event_type
,
531 sctp_subtype_t subtype
,
532 struct sctp_chunk
*chunk
,
535 struct sctp_ulpevent
*event
;
537 /* Cancel any partial delivery in progress. */
538 sctp_ulpq_abort_pd(&asoc
->ulpq
, GFP_ATOMIC
);
540 if (event_type
== SCTP_EVENT_T_CHUNK
&& subtype
.chunk
== SCTP_CID_ABORT
)
541 event
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_COMM_LOST
,
542 (__u16
)error
, 0, 0, chunk
,
545 event
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_COMM_LOST
,
546 (__u16
)error
, 0, 0, NULL
,
549 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
550 SCTP_ULPEVENT(event
));
552 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
553 SCTP_STATE(SCTP_STATE_CLOSED
));
555 /* SEND_FAILED sent later when cleaning up the association. */
556 asoc
->outqueue
.error
= error
;
557 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
560 /* Process an init chunk (may be real INIT/INIT-ACK or an embedded INIT
561 * inside the cookie. In reality, this is only used for INIT-ACK processing
562 * since all other cases use "temporary" associations and can do all
563 * their work in statefuns directly.
565 static int sctp_cmd_process_init(sctp_cmd_seq_t
*commands
,
566 struct sctp_association
*asoc
,
567 struct sctp_chunk
*chunk
,
568 sctp_init_chunk_t
*peer_init
,
573 /* We only process the init as a sideeffect in a single
574 * case. This is when we process the INIT-ACK. If we
575 * fail during INIT processing (due to malloc problems),
576 * just return the error and stop processing the stack.
578 if (!sctp_process_init(asoc
, chunk
->chunk_hdr
->type
,
579 sctp_source(chunk
), peer_init
, gfp
))
587 /* Helper function to break out starting up of heartbeat timers. */
588 static void sctp_cmd_hb_timers_start(sctp_cmd_seq_t
*cmds
,
589 struct sctp_association
*asoc
)
591 struct sctp_transport
*t
;
593 /* Start a heartbeat timer for each transport on the association.
594 * hold a reference on the transport to make sure none of
595 * the needed data structures go away.
597 list_for_each_entry(t
, &asoc
->peer
.transport_addr_list
, transports
) {
599 if (!mod_timer(&t
->hb_timer
, sctp_transport_timeout(t
)))
600 sctp_transport_hold(t
);
604 static void sctp_cmd_hb_timers_stop(sctp_cmd_seq_t
*cmds
,
605 struct sctp_association
*asoc
)
607 struct sctp_transport
*t
;
609 /* Stop all heartbeat timers. */
611 list_for_each_entry(t
, &asoc
->peer
.transport_addr_list
,
613 if (del_timer(&t
->hb_timer
))
614 sctp_transport_put(t
);
618 /* Helper function to stop any pending T3-RTX timers */
619 static void sctp_cmd_t3_rtx_timers_stop(sctp_cmd_seq_t
*cmds
,
620 struct sctp_association
*asoc
)
622 struct sctp_transport
*t
;
624 list_for_each_entry(t
, &asoc
->peer
.transport_addr_list
,
626 if (timer_pending(&t
->T3_rtx_timer
) &&
627 del_timer(&t
->T3_rtx_timer
)) {
628 sctp_transport_put(t
);
633 /* Sent the next ASCONF packet currently stored in the association.
634 * This happens after the ASCONF_ACK was succeffully processed.
636 static void sctp_cmd_send_asconf(struct sctp_association
*asoc
)
638 /* Send the next asconf chunk from the addip chunk
641 if (!list_empty(&asoc
->addip_chunk_list
)) {
642 struct list_head
*entry
= asoc
->addip_chunk_list
.next
;
643 struct sctp_chunk
*asconf
= list_entry(entry
,
644 struct sctp_chunk
, list
);
645 list_del_init(entry
);
647 /* Hold the chunk until an ASCONF_ACK is received. */
648 sctp_chunk_hold(asconf
);
649 if (sctp_primitive_ASCONF(asoc
, asconf
))
650 sctp_chunk_free(asconf
);
652 asoc
->addip_last_asconf
= asconf
;
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.
677 * The association's overall error count is also cleared.
680 t
->asoc
->overall_error_count
= 0;
682 /* Mark the destination transport address as active if it is not so
685 if ((t
->state
== SCTP_INACTIVE
) || (t
->state
== SCTP_UNCONFIRMED
))
686 sctp_assoc_control_transport(asoc
, t
, SCTP_TRANSPORT_UP
,
687 SCTP_HEARTBEAT_SUCCESS
);
689 /* The receiver of the HEARTBEAT ACK should also perform an
690 * RTT measurement for that destination transport address
691 * using the time value carried in the HEARTBEAT ACK chunk.
692 * If the transport's rto_pending variable has been cleared,
693 * it was most likely due to a retransmit. However, we want
694 * to re-enable it to properly update the rto.
696 if (t
->rto_pending
== 0)
699 hbinfo
= (sctp_sender_hb_info_t
*) chunk
->skb
->data
;
700 sctp_transport_update_rto(t
, (jiffies
- hbinfo
->sent_at
));
702 /* Update the heartbeat timer. */
703 if (!mod_timer(&t
->hb_timer
, sctp_transport_timeout(t
)))
704 sctp_transport_hold(t
);
707 /* Helper function to do a transport reset at the expiry of the hearbeat
710 static void sctp_cmd_transport_reset(sctp_cmd_seq_t
*cmds
,
711 struct sctp_association
*asoc
,
712 struct sctp_transport
*t
)
714 sctp_transport_lower_cwnd(t
, SCTP_LOWER_CWND_INACTIVE
);
716 /* Mark one strike against a transport. */
717 sctp_do_8_2_transport_strike(asoc
, t
);
720 /* Helper function to process the process SACK command. */
721 static int sctp_cmd_process_sack(sctp_cmd_seq_t
*cmds
,
722 struct sctp_association
*asoc
,
723 struct sctp_sackhdr
*sackh
)
727 if (sctp_outq_sack(&asoc
->outqueue
, sackh
)) {
728 /* There are no more TSNs awaiting SACK. */
729 err
= sctp_do_sm(SCTP_EVENT_T_OTHER
,
730 SCTP_ST_OTHER(SCTP_EVENT_NO_PENDING_TSN
),
731 asoc
->state
, asoc
->ep
, asoc
, NULL
,
738 /* Helper function to set the timeout value for T2-SHUTDOWN timer and to set
739 * the transport for a shutdown chunk.
741 static void sctp_cmd_setup_t2(sctp_cmd_seq_t
*cmds
,
742 struct sctp_association
*asoc
,
743 struct sctp_chunk
*chunk
)
745 struct sctp_transport
*t
;
747 t
= sctp_assoc_choose_shutdown_transport(asoc
);
748 asoc
->shutdown_last_sent_to
= t
;
749 asoc
->timeouts
[SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
] = t
->rto
;
750 chunk
->transport
= t
;
753 /* Helper function to change the state of an association. */
754 static void sctp_cmd_new_state(sctp_cmd_seq_t
*cmds
,
755 struct sctp_association
*asoc
,
758 struct sock
*sk
= asoc
->base
.sk
;
762 SCTP_DEBUG_PRINTK("sctp_cmd_new_state: asoc %p[%s]\n",
763 asoc
, sctp_state_tbl
[state
]);
765 if (sctp_style(sk
, TCP
)) {
766 /* Change the sk->sk_state of a TCP-style socket that has
767 * sucessfully completed a connect() call.
769 if (sctp_state(asoc
, ESTABLISHED
) && sctp_sstate(sk
, CLOSED
))
770 sk
->sk_state
= SCTP_SS_ESTABLISHED
;
772 /* Set the RCV_SHUTDOWN flag when a SHUTDOWN is received. */
773 if (sctp_state(asoc
, SHUTDOWN_RECEIVED
) &&
774 sctp_sstate(sk
, ESTABLISHED
))
775 sk
->sk_shutdown
|= RCV_SHUTDOWN
;
778 if (sctp_state(asoc
, COOKIE_WAIT
)) {
779 /* Reset init timeouts since they may have been
780 * increased due to timer expirations.
782 asoc
->timeouts
[SCTP_EVENT_TIMEOUT_T1_INIT
] =
784 asoc
->timeouts
[SCTP_EVENT_TIMEOUT_T1_COOKIE
] =
788 if (sctp_state(asoc
, ESTABLISHED
) ||
789 sctp_state(asoc
, CLOSED
) ||
790 sctp_state(asoc
, SHUTDOWN_RECEIVED
)) {
791 /* Wake up any processes waiting in the asoc's wait queue in
792 * sctp_wait_for_connect() or sctp_wait_for_sndbuf().
794 if (waitqueue_active(&asoc
->wait
))
795 wake_up_interruptible(&asoc
->wait
);
797 /* Wake up any processes waiting in the sk's sleep queue of
798 * a TCP-style or UDP-style peeled-off socket in
799 * sctp_wait_for_accept() or sctp_wait_for_packet().
800 * For a UDP-style socket, the waiters are woken up by the
803 if (!sctp_style(sk
, UDP
))
804 sk
->sk_state_change(sk
);
808 /* Helper function to delete an association. */
809 static void sctp_cmd_delete_tcb(sctp_cmd_seq_t
*cmds
,
810 struct sctp_association
*asoc
)
812 struct sock
*sk
= asoc
->base
.sk
;
814 /* If it is a non-temporary association belonging to a TCP-style
815 * listening socket that is not closed, do not free it so that accept()
816 * can pick it up later.
818 if (sctp_style(sk
, TCP
) && sctp_sstate(sk
, LISTENING
) &&
819 (!asoc
->temp
) && (sk
->sk_shutdown
!= SHUTDOWN_MASK
))
822 sctp_unhash_established(asoc
);
823 sctp_association_free(asoc
);
827 * ADDIP Section 4.1 ASCONF Chunk Procedures
828 * A4) Start a T-4 RTO timer, using the RTO value of the selected
829 * destination address (we use active path instead of primary path just
830 * because primary path may be inactive.
832 static void sctp_cmd_setup_t4(sctp_cmd_seq_t
*cmds
,
833 struct sctp_association
*asoc
,
834 struct sctp_chunk
*chunk
)
836 struct sctp_transport
*t
;
838 t
= asoc
->peer
.active_path
;
839 asoc
->timeouts
[SCTP_EVENT_TIMEOUT_T4_RTO
] = t
->rto
;
840 chunk
->transport
= t
;
843 /* Process an incoming Operation Error Chunk. */
844 static void sctp_cmd_process_operr(sctp_cmd_seq_t
*cmds
,
845 struct sctp_association
*asoc
,
846 struct sctp_chunk
*chunk
)
848 struct sctp_operr_chunk
*operr_chunk
;
849 struct sctp_errhdr
*err_hdr
;
851 operr_chunk
= (struct sctp_operr_chunk
*)chunk
->chunk_hdr
;
852 err_hdr
= &operr_chunk
->err_hdr
;
854 switch (err_hdr
->cause
) {
855 case SCTP_ERROR_UNKNOWN_CHUNK
:
857 struct sctp_chunkhdr
*unk_chunk_hdr
;
859 unk_chunk_hdr
= (struct sctp_chunkhdr
*)err_hdr
->variable
;
860 switch (unk_chunk_hdr
->type
) {
861 /* ADDIP 4.1 A9) If the peer responds to an ASCONF with an
862 * ERROR chunk reporting that it did not recognized the ASCONF
863 * chunk type, the sender of the ASCONF MUST NOT send any
864 * further ASCONF chunks and MUST stop its T-4 timer.
866 case SCTP_CID_ASCONF
:
867 asoc
->peer
.asconf_capable
= 0;
868 sctp_add_cmd_sf(cmds
, SCTP_CMD_TIMER_STOP
,
869 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
871 case SCTP_CMD_SEND_NEXT_ASCONF
:
872 sctp_cmd_send_asconf(asoc
);
884 /* Process variable FWDTSN chunk information. */
885 static void sctp_cmd_process_fwdtsn(struct sctp_ulpq
*ulpq
,
886 struct sctp_chunk
*chunk
)
888 struct sctp_fwdtsn_skip
*skip
;
889 /* Walk through all the skipped SSNs */
890 sctp_walk_fwdtsn(skip
, chunk
) {
891 sctp_ulpq_skip(ulpq
, ntohs(skip
->stream
), ntohs(skip
->ssn
));
897 /* Helper function to remove the association non-primary peer
900 static void sctp_cmd_del_non_primary(struct sctp_association
*asoc
)
902 struct sctp_transport
*t
;
903 struct list_head
*pos
;
904 struct list_head
*temp
;
906 list_for_each_safe(pos
, temp
, &asoc
->peer
.transport_addr_list
) {
907 t
= list_entry(pos
, struct sctp_transport
, transports
);
908 if (!sctp_cmp_addr_exact(&t
->ipaddr
,
909 &asoc
->peer
.primary_addr
)) {
910 sctp_assoc_del_peer(asoc
, &t
->ipaddr
);
917 /* Helper function to set sk_err on a 1-1 style socket. */
918 static void sctp_cmd_set_sk_err(struct sctp_association
*asoc
, int error
)
920 struct sock
*sk
= asoc
->base
.sk
;
922 if (!sctp_style(sk
, UDP
))
926 /* Helper function to generate an association change event */
927 static void sctp_cmd_assoc_change(sctp_cmd_seq_t
*commands
,
928 struct sctp_association
*asoc
,
931 struct sctp_ulpevent
*ev
;
933 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, state
, 0,
934 asoc
->c
.sinit_num_ostreams
,
935 asoc
->c
.sinit_max_instreams
,
938 sctp_ulpq_tail_event(&asoc
->ulpq
, ev
);
941 /* Helper function to generate an adaptation indication event */
942 static void sctp_cmd_adaptation_ind(sctp_cmd_seq_t
*commands
,
943 struct sctp_association
*asoc
)
945 struct sctp_ulpevent
*ev
;
947 ev
= sctp_ulpevent_make_adaptation_indication(asoc
, GFP_ATOMIC
);
950 sctp_ulpq_tail_event(&asoc
->ulpq
, ev
);
953 /* These three macros allow us to pull the debugging code out of the
954 * main flow of sctp_do_sm() to keep attention focused on the real
955 * functionality there.
958 SCTP_DEBUG_PRINTK("sctp_do_sm prefn: " \
959 "ep %p, %s, %s, asoc %p[%s], %s\n", \
960 ep, sctp_evttype_tbl[event_type], \
961 (*debug_fn)(subtype), asoc, \
962 sctp_state_tbl[state], state_fn->name)
965 SCTP_DEBUG_PRINTK("sctp_do_sm postfn: " \
966 "asoc %p, status: %s\n", \
967 asoc, sctp_status_tbl[status])
969 #define DEBUG_POST_SFX \
970 SCTP_DEBUG_PRINTK("sctp_do_sm post sfx: error %d, asoc %p[%s]\n", \
972 sctp_state_tbl[(asoc && sctp_id2assoc(ep->base.sk, \
973 sctp_assoc2id(asoc)))?asoc->state:SCTP_STATE_CLOSED])
976 * This is the master state machine processing function.
978 * If you want to understand all of lksctp, this is a
979 * good place to start.
981 int sctp_do_sm(sctp_event_t event_type
, sctp_subtype_t subtype
,
983 struct sctp_endpoint
*ep
,
984 struct sctp_association
*asoc
,
988 sctp_cmd_seq_t commands
;
989 const sctp_sm_table_entry_t
*state_fn
;
990 sctp_disposition_t status
;
992 typedef const char *(printfn_t
)(sctp_subtype_t
);
994 static printfn_t
*table
[] = {
995 NULL
, sctp_cname
, sctp_tname
, sctp_oname
, sctp_pname
,
997 printfn_t
*debug_fn
__attribute__ ((unused
)) = table
[event_type
];
999 /* Look up the state function, run it, and then process the
1000 * side effects. These three steps are the heart of lksctp.
1002 state_fn
= sctp_sm_lookup_event(event_type
, state
, subtype
);
1004 sctp_init_cmd_seq(&commands
);
1007 status
= (*state_fn
->fn
)(ep
, asoc
, subtype
, event_arg
, &commands
);
1010 error
= sctp_side_effects(event_type
, subtype
, state
,
1011 ep
, asoc
, event_arg
, status
,
1021 /*****************************************************************
1022 * This the master state function side effect processing function.
1023 *****************************************************************/
1024 static int sctp_side_effects(sctp_event_t event_type
, sctp_subtype_t subtype
,
1026 struct sctp_endpoint
*ep
,
1027 struct sctp_association
*asoc
,
1029 sctp_disposition_t status
,
1030 sctp_cmd_seq_t
*commands
,
1035 /* FIXME - Most of the dispositions left today would be categorized
1036 * as "exceptional" dispositions. For those dispositions, it
1037 * may not be proper to run through any of the commands at all.
1038 * For example, the command interpreter might be run only with
1039 * disposition SCTP_DISPOSITION_CONSUME.
1041 if (0 != (error
= sctp_cmd_interpreter(event_type
, subtype
, state
,
1048 case SCTP_DISPOSITION_DISCARD
:
1049 SCTP_DEBUG_PRINTK("Ignored sctp protocol event - state %d, "
1050 "event_type %d, event_id %d\n",
1051 state
, event_type
, subtype
.chunk
);
1054 case SCTP_DISPOSITION_NOMEM
:
1055 /* We ran out of memory, so we need to discard this
1058 /* BUG--we should now recover some memory, probably by
1064 case SCTP_DISPOSITION_DELETE_TCB
:
1065 /* This should now be a command. */
1068 case SCTP_DISPOSITION_CONSUME
:
1069 case SCTP_DISPOSITION_ABORT
:
1071 * We should no longer have much work to do here as the
1072 * real work has been done as explicit commands above.
1076 case SCTP_DISPOSITION_VIOLATION
:
1077 if (net_ratelimit())
1078 printk(KERN_ERR
"sctp protocol violation state %d "
1079 "chunkid %d\n", state
, subtype
.chunk
);
1082 case SCTP_DISPOSITION_NOT_IMPL
:
1083 printk(KERN_WARNING
"sctp unimplemented feature in state %d, "
1084 "event_type %d, event_id %d\n",
1085 state
, event_type
, subtype
.chunk
);
1088 case SCTP_DISPOSITION_BUG
:
1089 printk(KERN_ERR
"sctp bug in state %d, "
1090 "event_type %d, event_id %d\n",
1091 state
, event_type
, subtype
.chunk
);
1096 printk(KERN_ERR
"sctp impossible disposition %d "
1097 "in state %d, event_type %d, event_id %d\n",
1098 status
, state
, event_type
, subtype
.chunk
);
1107 /********************************************************************
1108 * 2nd Level Abstractions
1109 ********************************************************************/
1111 /* This is the side-effect interpreter. */
1112 static int sctp_cmd_interpreter(sctp_event_t event_type
,
1113 sctp_subtype_t subtype
,
1115 struct sctp_endpoint
*ep
,
1116 struct sctp_association
*asoc
,
1118 sctp_disposition_t status
,
1119 sctp_cmd_seq_t
*commands
,
1125 struct sctp_chunk
*new_obj
;
1126 struct sctp_chunk
*chunk
= NULL
;
1127 struct sctp_packet
*packet
;
1128 struct timer_list
*timer
;
1129 unsigned long timeout
;
1130 struct sctp_transport
*t
;
1131 struct sctp_sackhdr sackh
;
1134 if (SCTP_EVENT_T_TIMEOUT
!= event_type
)
1135 chunk
= (struct sctp_chunk
*) event_arg
;
1137 /* Note: This whole file is a huge candidate for rework.
1138 * For example, each command could either have its own handler, so
1139 * the loop would look like:
1141 * cmd->handle(x, y, z)
1144 while (NULL
!= (cmd
= sctp_next_cmd(commands
))) {
1145 switch (cmd
->verb
) {
1150 case SCTP_CMD_NEW_ASOC
:
1151 /* Register a new association. */
1153 sctp_outq_uncork(&asoc
->outqueue
);
1156 asoc
= cmd
->obj
.ptr
;
1157 /* Register with the endpoint. */
1158 sctp_endpoint_add_asoc(ep
, asoc
);
1159 sctp_hash_established(asoc
);
1162 case SCTP_CMD_UPDATE_ASSOC
:
1163 sctp_assoc_update(asoc
, cmd
->obj
.ptr
);
1166 case SCTP_CMD_PURGE_OUTQUEUE
:
1167 sctp_outq_teardown(&asoc
->outqueue
);
1170 case SCTP_CMD_DELETE_TCB
:
1172 sctp_outq_uncork(&asoc
->outqueue
);
1175 /* Delete the current association. */
1176 sctp_cmd_delete_tcb(commands
, asoc
);
1180 case SCTP_CMD_NEW_STATE
:
1181 /* Enter a new state. */
1182 sctp_cmd_new_state(commands
, asoc
, cmd
->obj
.state
);
1185 case SCTP_CMD_REPORT_TSN
:
1186 /* Record the arrival of a TSN. */
1187 sctp_tsnmap_mark(&asoc
->peer
.tsn_map
, cmd
->obj
.u32
);
1190 case SCTP_CMD_REPORT_FWDTSN
:
1191 /* Move the Cumulattive TSN Ack ahead. */
1192 sctp_tsnmap_skip(&asoc
->peer
.tsn_map
, cmd
->obj
.u32
);
1194 /* purge the fragmentation queue */
1195 sctp_ulpq_reasm_flushtsn(&asoc
->ulpq
, cmd
->obj
.u32
);
1197 /* Abort any in progress partial delivery. */
1198 sctp_ulpq_abort_pd(&asoc
->ulpq
, GFP_ATOMIC
);
1201 case SCTP_CMD_PROCESS_FWDTSN
:
1202 sctp_cmd_process_fwdtsn(&asoc
->ulpq
, cmd
->obj
.ptr
);
1205 case SCTP_CMD_GEN_SACK
:
1206 /* Generate a Selective ACK.
1207 * The argument tells us whether to just count
1208 * the packet and MAYBE generate a SACK, or
1211 force
= cmd
->obj
.i32
;
1212 error
= sctp_gen_sack(asoc
, force
, commands
);
1215 case SCTP_CMD_PROCESS_SACK
:
1216 /* Process an inbound SACK. */
1217 error
= sctp_cmd_process_sack(commands
, asoc
,
1221 case SCTP_CMD_GEN_INIT_ACK
:
1222 /* Generate an INIT ACK chunk. */
1223 new_obj
= sctp_make_init_ack(asoc
, chunk
, GFP_ATOMIC
,
1228 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1229 SCTP_CHUNK(new_obj
));
1232 case SCTP_CMD_PEER_INIT
:
1233 /* Process a unified INIT from the peer.
1234 * Note: Only used during INIT-ACK processing. If
1235 * there is an error just return to the outter
1236 * layer which will bail.
1238 error
= sctp_cmd_process_init(commands
, asoc
, chunk
,
1242 case SCTP_CMD_GEN_COOKIE_ECHO
:
1243 /* Generate a COOKIE ECHO chunk. */
1244 new_obj
= sctp_make_cookie_echo(asoc
, chunk
);
1247 sctp_chunk_free(cmd
->obj
.ptr
);
1250 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1251 SCTP_CHUNK(new_obj
));
1253 /* If there is an ERROR chunk to be sent along with
1254 * the COOKIE_ECHO, send it, too.
1257 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1258 SCTP_CHUNK(cmd
->obj
.ptr
));
1260 /* FIXME - Eventually come up with a cleaner way to
1261 * enabling COOKIE-ECHO + DATA bundling during
1262 * multihoming stale cookie scenarios, the following
1263 * command plays with asoc->peer.retran_path to
1264 * avoid the problem of sending the COOKIE-ECHO and
1265 * DATA in different paths, which could result
1266 * in the association being ABORTed if the DATA chunk
1267 * is processed first by the server. Checking the
1268 * init error counter simply causes this command
1269 * to be executed only during failed attempts of
1270 * association establishment.
1272 if ((asoc
->peer
.retran_path
!=
1273 asoc
->peer
.primary_path
) &&
1274 (asoc
->init_err_counter
> 0)) {
1275 sctp_add_cmd_sf(commands
,
1276 SCTP_CMD_FORCE_PRIM_RETRAN
,
1282 case SCTP_CMD_GEN_SHUTDOWN
:
1283 /* Generate SHUTDOWN when in SHUTDOWN_SENT state.
1284 * Reset error counts.
1286 asoc
->overall_error_count
= 0;
1288 /* Generate a SHUTDOWN chunk. */
1289 new_obj
= sctp_make_shutdown(asoc
, chunk
);
1292 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1293 SCTP_CHUNK(new_obj
));
1296 case SCTP_CMD_CHUNK_ULP
:
1297 /* Send a chunk to the sockets layer. */
1298 SCTP_DEBUG_PRINTK("sm_sideff: %s %p, %s %p.\n",
1299 "chunk_up:", cmd
->obj
.ptr
,
1300 "ulpq:", &asoc
->ulpq
);
1301 sctp_ulpq_tail_data(&asoc
->ulpq
, cmd
->obj
.ptr
,
1305 case SCTP_CMD_EVENT_ULP
:
1306 /* Send a notification to the sockets layer. */
1307 SCTP_DEBUG_PRINTK("sm_sideff: %s %p, %s %p.\n",
1308 "event_up:",cmd
->obj
.ptr
,
1309 "ulpq:",&asoc
->ulpq
);
1310 sctp_ulpq_tail_event(&asoc
->ulpq
, cmd
->obj
.ptr
);
1313 case SCTP_CMD_REPLY
:
1314 /* If an caller has not already corked, do cork. */
1315 if (!asoc
->outqueue
.cork
) {
1316 sctp_outq_cork(&asoc
->outqueue
);
1319 /* Send a chunk to our peer. */
1320 error
= sctp_outq_tail(&asoc
->outqueue
, cmd
->obj
.ptr
);
1323 case SCTP_CMD_SEND_PKT
:
1324 /* Send a full packet to our peer. */
1325 packet
= cmd
->obj
.ptr
;
1326 sctp_packet_transmit(packet
);
1327 sctp_ootb_pkt_free(packet
);
1330 case SCTP_CMD_T1_RETRAN
:
1331 /* Mark a transport for retransmission. */
1332 sctp_retransmit(&asoc
->outqueue
, cmd
->obj
.transport
,
1336 case SCTP_CMD_RETRAN
:
1337 /* Mark a transport for retransmission. */
1338 sctp_retransmit(&asoc
->outqueue
, cmd
->obj
.transport
,
1342 case SCTP_CMD_TRANSMIT
:
1343 /* Kick start transmission. */
1344 error
= sctp_outq_uncork(&asoc
->outqueue
);
1348 case SCTP_CMD_ECN_CE
:
1349 /* Do delayed CE processing. */
1350 sctp_do_ecn_ce_work(asoc
, cmd
->obj
.u32
);
1353 case SCTP_CMD_ECN_ECNE
:
1354 /* Do delayed ECNE processing. */
1355 new_obj
= sctp_do_ecn_ecne_work(asoc
, cmd
->obj
.u32
,
1358 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1359 SCTP_CHUNK(new_obj
));
1362 case SCTP_CMD_ECN_CWR
:
1363 /* Do delayed CWR processing. */
1364 sctp_do_ecn_cwr_work(asoc
, cmd
->obj
.u32
);
1367 case SCTP_CMD_SETUP_T2
:
1368 sctp_cmd_setup_t2(commands
, asoc
, cmd
->obj
.ptr
);
1371 case SCTP_CMD_TIMER_START
:
1372 timer
= &asoc
->timers
[cmd
->obj
.to
];
1373 timeout
= asoc
->timeouts
[cmd
->obj
.to
];
1376 timer
->expires
= jiffies
+ timeout
;
1377 sctp_association_hold(asoc
);
1381 case SCTP_CMD_TIMER_RESTART
:
1382 timer
= &asoc
->timers
[cmd
->obj
.to
];
1383 timeout
= asoc
->timeouts
[cmd
->obj
.to
];
1384 if (!mod_timer(timer
, jiffies
+ timeout
))
1385 sctp_association_hold(asoc
);
1388 case SCTP_CMD_TIMER_STOP
:
1389 timer
= &asoc
->timers
[cmd
->obj
.to
];
1390 if (timer_pending(timer
) && del_timer(timer
))
1391 sctp_association_put(asoc
);
1394 case SCTP_CMD_INIT_CHOOSE_TRANSPORT
:
1395 chunk
= cmd
->obj
.ptr
;
1396 t
= sctp_assoc_choose_init_transport(asoc
);
1397 asoc
->init_last_sent_to
= t
;
1398 chunk
->transport
= t
;
1399 t
->init_sent_count
++;
1402 case SCTP_CMD_INIT_RESTART
:
1403 /* Do the needed accounting and updates
1404 * associated with restarting an initialization
1405 * timer. Only multiply the timeout by two if
1406 * all transports have been tried at the current
1409 t
= asoc
->init_last_sent_to
;
1410 asoc
->init_err_counter
++;
1412 if (t
->init_sent_count
> (asoc
->init_cycle
+ 1)) {
1413 asoc
->timeouts
[SCTP_EVENT_TIMEOUT_T1_INIT
] *= 2;
1414 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_T1_INIT
] >
1415 asoc
->max_init_timeo
) {
1416 asoc
->timeouts
[SCTP_EVENT_TIMEOUT_T1_INIT
] =
1417 asoc
->max_init_timeo
;
1421 "T1 INIT Timeout adjustment"
1422 " init_err_counter: %d"
1425 asoc
->init_err_counter
,
1427 asoc
->timeouts
[SCTP_EVENT_TIMEOUT_T1_INIT
]);
1430 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
1431 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
1434 case SCTP_CMD_COOKIEECHO_RESTART
:
1435 /* Do the needed accounting and updates
1436 * associated with restarting an initialization
1437 * timer. Only multiply the timeout by two if
1438 * all transports have been tried at the current
1441 asoc
->init_err_counter
++;
1443 asoc
->timeouts
[SCTP_EVENT_TIMEOUT_T1_COOKIE
] *= 2;
1444 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_T1_COOKIE
] >
1445 asoc
->max_init_timeo
) {
1446 asoc
->timeouts
[SCTP_EVENT_TIMEOUT_T1_COOKIE
] =
1447 asoc
->max_init_timeo
;
1450 "T1 COOKIE Timeout adjustment"
1451 " init_err_counter: %d"
1453 asoc
->init_err_counter
,
1454 asoc
->timeouts
[SCTP_EVENT_TIMEOUT_T1_COOKIE
]);
1456 /* If we've sent any data bundled with
1457 * COOKIE-ECHO we need to resend.
1459 list_for_each_entry(t
, &asoc
->peer
.transport_addr_list
,
1461 sctp_retransmit_mark(&asoc
->outqueue
, t
,
1465 sctp_add_cmd_sf(commands
,
1466 SCTP_CMD_TIMER_RESTART
,
1467 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
1470 case SCTP_CMD_INIT_FAILED
:
1471 sctp_cmd_init_failed(commands
, asoc
, cmd
->obj
.err
);
1474 case SCTP_CMD_ASSOC_FAILED
:
1475 sctp_cmd_assoc_failed(commands
, asoc
, event_type
,
1476 subtype
, chunk
, cmd
->obj
.err
);
1479 case SCTP_CMD_INIT_COUNTER_INC
:
1480 asoc
->init_err_counter
++;
1483 case SCTP_CMD_INIT_COUNTER_RESET
:
1484 asoc
->init_err_counter
= 0;
1485 asoc
->init_cycle
= 0;
1488 case SCTP_CMD_REPORT_DUP
:
1489 sctp_tsnmap_mark_dup(&asoc
->peer
.tsn_map
,
1493 case SCTP_CMD_REPORT_BAD_TAG
:
1494 SCTP_DEBUG_PRINTK("vtag mismatch!\n");
1497 case SCTP_CMD_STRIKE
:
1498 /* Mark one strike against a transport. */
1499 sctp_do_8_2_transport_strike(asoc
, cmd
->obj
.transport
);
1502 case SCTP_CMD_TRANSPORT_RESET
:
1503 t
= cmd
->obj
.transport
;
1504 sctp_cmd_transport_reset(commands
, asoc
, t
);
1507 case SCTP_CMD_TRANSPORT_ON
:
1508 t
= cmd
->obj
.transport
;
1509 sctp_cmd_transport_on(commands
, asoc
, t
, chunk
);
1512 case SCTP_CMD_HB_TIMERS_START
:
1513 sctp_cmd_hb_timers_start(commands
, asoc
);
1516 case SCTP_CMD_HB_TIMER_UPDATE
:
1517 t
= cmd
->obj
.transport
;
1518 sctp_cmd_hb_timer_update(commands
, t
);
1521 case SCTP_CMD_HB_TIMERS_STOP
:
1522 sctp_cmd_hb_timers_stop(commands
, asoc
);
1525 case SCTP_CMD_REPORT_ERROR
:
1526 error
= cmd
->obj
.error
;
1529 case SCTP_CMD_PROCESS_CTSN
:
1530 /* Dummy up a SACK for processing. */
1531 sackh
.cum_tsn_ack
= cmd
->obj
.be32
;
1533 sackh
.num_gap_ack_blocks
= 0;
1534 sackh
.num_dup_tsns
= 0;
1535 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_SACK
,
1536 SCTP_SACKH(&sackh
));
1539 case SCTP_CMD_DISCARD_PACKET
:
1540 /* We need to discard the whole packet.
1541 * Uncork the queue since there might be
1544 chunk
->pdiscard
= 1;
1546 sctp_outq_uncork(&asoc
->outqueue
);
1551 case SCTP_CMD_RTO_PENDING
:
1552 t
= cmd
->obj
.transport
;
1556 case SCTP_CMD_PART_DELIVER
:
1557 sctp_ulpq_partial_delivery(&asoc
->ulpq
, cmd
->obj
.ptr
,
1561 case SCTP_CMD_RENEGE
:
1562 sctp_ulpq_renege(&asoc
->ulpq
, cmd
->obj
.ptr
,
1566 case SCTP_CMD_SETUP_T4
:
1567 sctp_cmd_setup_t4(commands
, asoc
, cmd
->obj
.ptr
);
1570 case SCTP_CMD_PROCESS_OPERR
:
1571 sctp_cmd_process_operr(commands
, asoc
, chunk
);
1573 case SCTP_CMD_CLEAR_INIT_TAG
:
1574 asoc
->peer
.i
.init_tag
= 0;
1576 case SCTP_CMD_DEL_NON_PRIMARY
:
1577 sctp_cmd_del_non_primary(asoc
);
1579 case SCTP_CMD_T3_RTX_TIMERS_STOP
:
1580 sctp_cmd_t3_rtx_timers_stop(commands
, asoc
);
1582 case SCTP_CMD_FORCE_PRIM_RETRAN
:
1583 t
= asoc
->peer
.retran_path
;
1584 asoc
->peer
.retran_path
= asoc
->peer
.primary_path
;
1585 error
= sctp_outq_uncork(&asoc
->outqueue
);
1587 asoc
->peer
.retran_path
= t
;
1589 case SCTP_CMD_SET_SK_ERR
:
1590 sctp_cmd_set_sk_err(asoc
, cmd
->obj
.error
);
1592 case SCTP_CMD_ASSOC_CHANGE
:
1593 sctp_cmd_assoc_change(commands
, asoc
,
1596 case SCTP_CMD_ADAPTATION_IND
:
1597 sctp_cmd_adaptation_ind(commands
, asoc
);
1600 case SCTP_CMD_ASSOC_SHKEY
:
1601 error
= sctp_auth_asoc_init_active_key(asoc
,
1604 case SCTP_CMD_UPDATE_INITTAG
:
1605 asoc
->peer
.i
.init_tag
= cmd
->obj
.u32
;
1609 printk(KERN_WARNING
"Impossible command: %u, %p\n",
1610 cmd
->verb
, cmd
->obj
.ptr
);
1619 /* If this is in response to a received chunk, wait until
1620 * we are done with the packet to open the queue so that we don't
1621 * send multiple packets in response to a single request.
1623 if (asoc
&& SCTP_EVENT_T_CHUNK
== event_type
&& chunk
) {
1624 if (chunk
->end_of_packet
|| chunk
->singleton
)
1625 sctp_outq_uncork(&asoc
->outqueue
);
1626 } else if (local_cork
)
1627 sctp_outq_uncork(&asoc
->outqueue
);