blob: 3b7230ef77c234f69582588a82ed48da02959a34 [file] [log] [blame]
Vlad Yasevich60c778b2008-01-11 09:57:09 -05001/* SCTP kernel implementation
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 *
Vlad Yasevich60c778b2008-01-11 09:57:09 -05006 * This file is part of the SCTP kernel implementation
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
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.
11 *
Vlad Yasevich60c778b2008-01-11 09:57:09 -050012 * This SCTP implementation is free software;
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * 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)
16 * any later version.
17 *
Vlad Yasevich60c778b2008-01-11 09:57:09 -050018 * This SCTP implementation is distributed in the hope that it
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 * 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.
23 *
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.
28 *
29 * Please send any bug reports or fixes you make to the
30 * email address(es):
31 * lksctp developers <lksctp-developers@lists.sourceforge.net>
32 *
33 * Or submit a bug report through the following website:
34 * http://www.sf.net/projects/lksctp
35 *
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>
45 *
46 * Any bugs reported given to us we will try to fix... any fixes shared will
47 * be incorporated into the next SCTP release.
48 */
49
50#include <linux/skbuff.h>
51#include <linux/types.h>
52#include <linux/socket.h>
53#include <linux/ip.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090054#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include <net/sock.h>
56#include <net/sctp/sctp.h>
57#include <net/sctp/sm.h>
58
59static int sctp_cmd_interpreter(sctp_event_t event_type,
60 sctp_subtype_t subtype,
61 sctp_state_t state,
62 struct sctp_endpoint *ep,
63 struct sctp_association *asoc,
64 void *event_arg,
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +090065 sctp_disposition_t status,
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 sctp_cmd_seq_t *commands,
Al Virodd0fc662005-10-07 07:46:04 +010067 gfp_t gfp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068static int sctp_side_effects(sctp_event_t event_type, sctp_subtype_t subtype,
69 sctp_state_t state,
70 struct sctp_endpoint *ep,
71 struct sctp_association *asoc,
72 void *event_arg,
73 sctp_disposition_t status,
74 sctp_cmd_seq_t *commands,
Al Virodd0fc662005-10-07 07:46:04 +010075 gfp_t gfp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77/********************************************************************
78 * Helper functions
79 ********************************************************************/
80
81/* A helper function for delayed processing of INET ECN CE bit. */
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +090082static void sctp_do_ecn_ce_work(struct sctp_association *asoc,
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 __u32 lowest_tsn)
84{
85 /* Save the TSN away for comparison when we receive CWR */
86
87 asoc->last_ecne_tsn = lowest_tsn;
88 asoc->need_ecne = 1;
89}
90
91/* Helper function for delayed processing of SCTP ECNE chunk. */
92/* RFC 2960 Appendix A
93 *
94 * RFC 2481 details a specific bit for a sender to send in
95 * the header of its next outbound TCP segment to indicate to
96 * its peer that it has reduced its congestion window. This
97 * is termed the CWR bit. For SCTP the same indication is made
98 * by including the CWR chunk. This chunk contains one data
99 * element, i.e. the TSN number that was sent in the ECNE chunk.
100 * This element represents the lowest TSN number in the datagram
101 * that was originally marked with the CE bit.
102 */
103static struct sctp_chunk *sctp_do_ecn_ecne_work(struct sctp_association *asoc,
104 __u32 lowest_tsn,
105 struct sctp_chunk *chunk)
106{
107 struct sctp_chunk *repl;
108
109 /* Our previously transmitted packet ran into some congestion
110 * so we should take action by reducing cwnd and ssthresh
111 * and then ACK our peer that we we've done so by
112 * sending a CWR.
113 */
114
115 /* First, try to determine if we want to actually lower
116 * our cwnd variables. Only lower them if the ECNE looks more
117 * recent than the last response.
118 */
119 if (TSN_lt(asoc->last_cwr_tsn, lowest_tsn)) {
120 struct sctp_transport *transport;
121
122 /* Find which transport's congestion variables
123 * need to be adjusted.
124 */
125 transport = sctp_assoc_lookup_tsn(asoc, lowest_tsn);
126
127 /* Update the congestion variables. */
128 if (transport)
129 sctp_transport_lower_cwnd(transport,
130 SCTP_LOWER_CWND_ECNE);
131 asoc->last_cwr_tsn = lowest_tsn;
132 }
133
134 /* Always try to quiet the other end. In case of lost CWR,
135 * resend last_cwr_tsn.
136 */
137 repl = sctp_make_cwr(asoc, asoc->last_cwr_tsn, chunk);
138
139 /* If we run out of memory, it will look like a lost CWR. We'll
140 * get back in sync eventually.
141 */
142 return repl;
143}
144
145/* Helper function to do delayed processing of ECN CWR chunk. */
146static void sctp_do_ecn_cwr_work(struct sctp_association *asoc,
147 __u32 lowest_tsn)
148{
149 /* Turn off ECNE getting auto-prepended to every outgoing
150 * packet
151 */
152 asoc->need_ecne = 0;
153}
154
155/* Generate SACK if necessary. We call this at the end of a packet. */
156static int sctp_gen_sack(struct sctp_association *asoc, int force,
157 sctp_cmd_seq_t *commands)
158{
159 __u32 ctsn, max_tsn_seen;
160 struct sctp_chunk *sack;
Frank Filz52ccb8e2005-12-22 11:36:46 -0800161 struct sctp_transport *trans = asoc->peer.last_data_from;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 int error = 0;
163
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900164 if (force ||
Frank Filz52ccb8e2005-12-22 11:36:46 -0800165 (!trans && (asoc->param_flags & SPP_SACKDELAY_DISABLE)) ||
166 (trans && (trans->param_flags & SPP_SACKDELAY_DISABLE)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 asoc->peer.sack_needed = 1;
168
169 ctsn = sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map);
170 max_tsn_seen = sctp_tsnmap_get_max_tsn_seen(&asoc->peer.tsn_map);
171
172 /* From 12.2 Parameters necessary per association (i.e. the TCB):
173 *
174 * Ack State : This flag indicates if the next received packet
175 * : is to be responded to with a SACK. ...
176 * : When DATA chunks are out of order, SACK's
177 * : are not delayed (see Section 6).
178 *
179 * [This is actually not mentioned in Section 6, but we
180 * implement it here anyway. --piggy]
181 */
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900182 if (max_tsn_seen != ctsn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 asoc->peer.sack_needed = 1;
184
185 /* From 6.2 Acknowledgement on Reception of DATA Chunks:
186 *
187 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically,
188 * an acknowledgement SHOULD be generated for at least every
189 * second packet (not every second DATA chunk) received, and
190 * SHOULD be generated within 200 ms of the arrival of any
191 * unacknowledged DATA chunk. ...
192 */
193 if (!asoc->peer.sack_needed) {
Wei Yongjund364d922008-05-09 15:13:26 -0700194 asoc->peer.sack_cnt++;
Frank Filz52ccb8e2005-12-22 11:36:46 -0800195
196 /* Set the SACK delay timeout based on the
197 * SACK delay for the last transport
198 * data was received from, or the default
199 * for the association.
200 */
Wei Yongjund364d922008-05-09 15:13:26 -0700201 if (trans) {
202 /* We will need a SACK for the next packet. */
203 if (asoc->peer.sack_cnt >= trans->sackfreq - 1)
204 asoc->peer.sack_needed = 1;
205
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900206 asoc->timeouts[SCTP_EVENT_TIMEOUT_SACK] =
Frank Filz52ccb8e2005-12-22 11:36:46 -0800207 trans->sackdelay;
Wei Yongjund364d922008-05-09 15:13:26 -0700208 } else {
209 /* We will need a SACK for the next packet. */
210 if (asoc->peer.sack_cnt >= asoc->sackfreq - 1)
211 asoc->peer.sack_needed = 1;
212
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900213 asoc->timeouts[SCTP_EVENT_TIMEOUT_SACK] =
Frank Filz52ccb8e2005-12-22 11:36:46 -0800214 asoc->sackdelay;
Wei Yongjund364d922008-05-09 15:13:26 -0700215 }
Frank Filz52ccb8e2005-12-22 11:36:46 -0800216
217 /* Restart the SACK timer. */
218 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
219 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 } else {
Vlad Yasevich90f2f532009-11-23 15:53:57 -0500221 asoc->a_rwnd = asoc->rwnd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 sack = sctp_make_sack(asoc);
223 if (!sack)
224 goto nomem;
225
226 asoc->peer.sack_needed = 0;
Wei Yongjund364d922008-05-09 15:13:26 -0700227 asoc->peer.sack_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
Vlad Yasevich732ba352007-01-15 19:20:21 -0800229 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(sack));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231 /* Stop the SACK timer. */
232 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
233 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
234 }
Frank Filz52ccb8e2005-12-22 11:36:46 -0800235
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 return error;
237nomem:
238 error = -ENOMEM;
239 return error;
240}
241
242/* When the T3-RTX timer expires, it calls this function to create the
243 * relevant state machine event.
244 */
245void sctp_generate_t3_rtx_event(unsigned long peer)
246{
247 int error;
248 struct sctp_transport *transport = (struct sctp_transport *) peer;
249 struct sctp_association *asoc = transport->asoc;
250
251 /* Check whether a task is in the sock. */
252
253 sctp_bh_lock_sock(asoc->base.sk);
254 if (sock_owned_by_user(asoc->base.sk)) {
Harvey Harrison0dc47872008-03-05 20:47:47 -0800255 SCTP_DEBUG_PRINTK("%s:Sock is busy.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257 /* Try again later. */
258 if (!mod_timer(&transport->T3_rtx_timer, jiffies + (HZ/20)))
259 sctp_transport_hold(transport);
260 goto out_unlock;
261 }
262
263 /* Is this transport really dead and just waiting around for
264 * the timer to let go of the reference?
265 */
266 if (transport->dead)
267 goto out_unlock;
268
269 /* Run through the state machine. */
270 error = sctp_do_sm(SCTP_EVENT_T_TIMEOUT,
271 SCTP_ST_TIMEOUT(SCTP_EVENT_TIMEOUT_T3_RTX),
272 asoc->state,
273 asoc->ep, asoc,
274 transport, GFP_ATOMIC);
275
276 if (error)
277 asoc->base.sk->sk_err = -error;
278
279out_unlock:
280 sctp_bh_unlock_sock(asoc->base.sk);
281 sctp_transport_put(transport);
282}
283
284/* This is a sa interface for producing timeout events. It works
285 * for timeouts which use the association as their parameter.
286 */
287static void sctp_generate_timeout_event(struct sctp_association *asoc,
288 sctp_event_timeout_t timeout_type)
289{
290 int error = 0;
291
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",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800295 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 timeout_type);
297
298 /* Try again later. */
299 if (!mod_timer(&asoc->timers[timeout_type], jiffies + (HZ/20)))
300 sctp_association_hold(asoc);
301 goto out_unlock;
302 }
303
304 /* Is this association really dead and just waiting around for
305 * the timer to let go of the reference?
306 */
307 if (asoc->base.dead)
308 goto out_unlock;
309
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);
315
316 if (error)
317 asoc->base.sk->sk_err = -error;
318
319out_unlock:
320 sctp_bh_unlock_sock(asoc->base.sk);
321 sctp_association_put(asoc);
322}
323
324static void sctp_generate_t1_cookie_event(unsigned long data)
325{
326 struct sctp_association *asoc = (struct sctp_association *) data;
327 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T1_COOKIE);
328}
329
330static void sctp_generate_t1_init_event(unsigned long data)
331{
332 struct sctp_association *asoc = (struct sctp_association *) data;
333 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T1_INIT);
334}
335
336static void sctp_generate_t2_shutdown_event(unsigned long data)
337{
338 struct sctp_association *asoc = (struct sctp_association *) data;
339 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T2_SHUTDOWN);
340}
341
342static void sctp_generate_t4_rto_event(unsigned long data)
343{
344 struct sctp_association *asoc = (struct sctp_association *) data;
345 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T4_RTO);
346}
347
348static void sctp_generate_t5_shutdown_guard_event(unsigned long data)
349{
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900350 struct sctp_association *asoc = (struct sctp_association *)data;
351 sctp_generate_timeout_event(asoc,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD);
353
354} /* sctp_generate_t5_shutdown_guard_event() */
355
356static void sctp_generate_autoclose_event(unsigned long data)
357{
358 struct sctp_association *asoc = (struct sctp_association *) data;
359 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_AUTOCLOSE);
360}
361
362/* Generate a heart beat event. If the sock is busy, reschedule. Make
363 * sure that the transport is still valid.
364 */
365void sctp_generate_heartbeat_event(unsigned long data)
366{
367 int error = 0;
368 struct sctp_transport *transport = (struct sctp_transport *) data;
369 struct sctp_association *asoc = transport->asoc;
370
371 sctp_bh_lock_sock(asoc->base.sk);
372 if (sock_owned_by_user(asoc->base.sk)) {
Harvey Harrison0dc47872008-03-05 20:47:47 -0800373 SCTP_DEBUG_PRINTK("%s:Sock is busy.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
375 /* Try again later. */
376 if (!mod_timer(&transport->hb_timer, jiffies + (HZ/20)))
377 sctp_transport_hold(transport);
378 goto out_unlock;
379 }
380
381 /* Is this structure just waiting around for us to actually
382 * get destroyed?
383 */
384 if (transport->dead)
385 goto out_unlock;
386
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);
391
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900392 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 asoc->base.sk->sk_err = -error;
394
395out_unlock:
396 sctp_bh_unlock_sock(asoc->base.sk);
397 sctp_transport_put(transport);
398}
399
400/* Inject a SACK Timeout event into the state machine. */
401static void sctp_generate_sack_event(unsigned long data)
402{
403 struct sctp_association *asoc = (struct sctp_association *) data;
404 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
405}
406
407sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
408 NULL,
409 sctp_generate_t1_cookie_event,
410 sctp_generate_t1_init_event,
411 sctp_generate_t2_shutdown_event,
412 NULL,
413 sctp_generate_t4_rto_event,
414 sctp_generate_t5_shutdown_guard_event,
Vladislav Yasevich1e7d3d92005-11-11 16:06:16 -0800415 NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 sctp_generate_sack_event,
417 sctp_generate_autoclose_event,
418};
419
420
421/* RFC 2960 8.2 Path Failure Detection
422 *
423 * When its peer endpoint is multi-homed, an endpoint should keep a
424 * error counter for each of the destination transport addresses of the
425 * peer endpoint.
426 *
427 * Each time the T3-rtx timer expires on any address, or when a
428 * HEARTBEAT sent to an idle address is not acknowledged within a RTO,
429 * the error counter of that destination address will be incremented.
430 * When the value in the error counter exceeds the protocol parameter
431 * 'Path.Max.Retrans' of that destination address, the endpoint should
432 * mark the destination transport address as inactive, and a
433 * notification SHOULD be sent to the upper layer.
434 *
435 */
436static void sctp_do_8_2_transport_strike(struct sctp_association *asoc,
Vlad Yasevich7e990132009-03-02 09:46:14 +0000437 struct sctp_transport *transport,
438 int is_hb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
440 /* The check for association's overall error counter exceeding the
441 * threshold is done in the state function.
442 */
Vlad Yasevichb9f84782009-08-26 09:36:25 -0400443 /* We are here due to a timer expiration. If the timer was
444 * not a HEARTBEAT, then normal error tracking is done.
445 * If the timer was a heartbeat, we only increment error counts
446 * when we already have an outstanding HEARTBEAT that has not
447 * been acknowledged.
448 * Additionaly, some tranport states inhibit error increments.
Sridhar Samudralaad8fec12006-07-21 14:48:50 -0700449 */
Vlad Yasevichb9f84782009-08-26 09:36:25 -0400450 if (!is_hb) {
Sridhar Samudralaad8fec12006-07-21 14:48:50 -0700451 asoc->overall_error_count++;
Vlad Yasevichb9f84782009-08-26 09:36:25 -0400452 if (transport->state != SCTP_INACTIVE)
453 transport->error_count++;
454 } else if (transport->hb_sent) {
455 if (transport->state != SCTP_UNCONFIRMED)
456 asoc->overall_error_count++;
457 if (transport->state != SCTP_INACTIVE)
458 transport->error_count++;
459 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Frank Filz3f7a87d2005-06-20 13:14:57 -0700461 if (transport->state != SCTP_INACTIVE &&
Vlad Yasevichb9f84782009-08-26 09:36:25 -0400462 (transport->error_count > transport->pathmaxrxt)) {
Frank Filz3f7a87d2005-06-20 13:14:57 -0700463 SCTP_DEBUG_PRINTK_IPADDR("transport_strike:association %p",
464 " transport IP: port:%d failed.\n",
465 asoc,
Al Virob3f5b3b2006-11-20 17:22:43 -0800466 (&transport->ipaddr),
467 ntohs(transport->ipaddr.v4.sin_port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 sctp_assoc_control_transport(asoc, transport,
469 SCTP_TRANSPORT_DOWN,
470 SCTP_FAILED_THRESHOLD);
471 }
472
473 /* E2) For the destination address for which the timer
474 * expires, set RTO <- RTO * 2 ("back off the timer"). The
475 * maximum value discussed in rule C7 above (RTO.max) may be
476 * used to provide an upper bound to this doubling operation.
Vlad Yasevichfaee47c2009-02-13 08:33:43 +0000477 *
478 * Special Case: the first HB doesn't trigger exponential backoff.
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800479 * The first unacknowledged HB triggers it. We do this with a flag
Vlad Yasevichfaee47c2009-02-13 08:33:43 +0000480 * that indicates that we have an outstanding HB.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 */
Vlad Yasevich7e990132009-03-02 09:46:14 +0000482 if (!is_hb || transport->hb_sent) {
Vlad Yasevichfaee47c2009-02-13 08:33:43 +0000483 transport->rto = min((transport->rto * 2), transport->asoc->rto_max);
484 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485}
486
487/* Worker routine to handle INIT command failure. */
488static void sctp_cmd_init_failed(sctp_cmd_seq_t *commands,
489 struct sctp_association *asoc,
490 unsigned error)
491{
492 struct sctp_ulpevent *event;
493
494 event = sctp_ulpevent_make_assoc_change(asoc,0, SCTP_CANT_STR_ASSOC,
Vlad Yasevicha5a35e72007-03-23 11:34:08 -0700495 (__u16)error, 0, 0, NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 GFP_ATOMIC);
497
498 if (event)
499 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
500 SCTP_ULPEVENT(event));
501
502 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
503 SCTP_STATE(SCTP_STATE_CLOSED));
504
505 /* SEND_FAILED sent later when cleaning up the association. */
506 asoc->outqueue.error = error;
507 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
508}
509
510/* Worker routine to handle SCTP_CMD_ASSOC_FAILED. */
511static void sctp_cmd_assoc_failed(sctp_cmd_seq_t *commands,
512 struct sctp_association *asoc,
513 sctp_event_t event_type,
514 sctp_subtype_t subtype,
515 struct sctp_chunk *chunk,
516 unsigned error)
517{
518 struct sctp_ulpevent *event;
519
520 /* Cancel any partial delivery in progress. */
521 sctp_ulpq_abort_pd(&asoc->ulpq, GFP_ATOMIC);
522
Vlad Yasevicha5a35e72007-03-23 11:34:08 -0700523 if (event_type == SCTP_EVENT_T_CHUNK && subtype.chunk == SCTP_CID_ABORT)
524 event = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_LOST,
525 (__u16)error, 0, 0, chunk,
526 GFP_ATOMIC);
527 else
528 event = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_LOST,
529 (__u16)error, 0, 0, NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 GFP_ATOMIC);
531 if (event)
532 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
533 SCTP_ULPEVENT(event));
534
535 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
536 SCTP_STATE(SCTP_STATE_CLOSED));
537
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 /* SEND_FAILED sent later when cleaning up the association. */
539 asoc->outqueue.error = error;
540 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
541}
542
543/* Process an init chunk (may be real INIT/INIT-ACK or an embedded INIT
544 * inside the cookie. In reality, this is only used for INIT-ACK processing
545 * since all other cases use "temporary" associations and can do all
546 * their work in statefuns directly.
547 */
548static int sctp_cmd_process_init(sctp_cmd_seq_t *commands,
549 struct sctp_association *asoc,
550 struct sctp_chunk *chunk,
Alexey Dobriyan3182cd82005-07-11 20:57:47 -0700551 sctp_init_chunk_t *peer_init,
Al Virodd0fc662005-10-07 07:46:04 +0100552 gfp_t gfp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553{
554 int error;
555
556 /* We only process the init as a sideeffect in a single
557 * case. This is when we process the INIT-ACK. If we
558 * fail during INIT processing (due to malloc problems),
559 * just return the error and stop processing the stack.
560 */
561 if (!sctp_process_init(asoc, chunk->chunk_hdr->type,
562 sctp_source(chunk), peer_init, gfp))
563 error = -ENOMEM;
564 else
565 error = 0;
566
567 return error;
568}
569
570/* Helper function to break out starting up of heartbeat timers. */
571static void sctp_cmd_hb_timers_start(sctp_cmd_seq_t *cmds,
572 struct sctp_association *asoc)
573{
574 struct sctp_transport *t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
576 /* Start a heartbeat timer for each transport on the association.
577 * hold a reference on the transport to make sure none of
578 * the needed data structures go away.
579 */
Robert P. J. Day9dbc15f2008-04-12 18:54:24 -0700580 list_for_each_entry(t, &asoc->peer.transport_addr_list, transports) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
582 if (!mod_timer(&t->hb_timer, sctp_transport_timeout(t)))
583 sctp_transport_hold(t);
584 }
585}
586
587static void sctp_cmd_hb_timers_stop(sctp_cmd_seq_t *cmds,
588 struct sctp_association *asoc)
589{
590 struct sctp_transport *t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
592 /* Stop all heartbeat timers. */
593
Robert P. J. Day9dbc15f2008-04-12 18:54:24 -0700594 list_for_each_entry(t, &asoc->peer.transport_addr_list,
595 transports) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 if (del_timer(&t->hb_timer))
597 sctp_transport_put(t);
598 }
599}
600
601/* Helper function to stop any pending T3-RTX timers */
602static void sctp_cmd_t3_rtx_timers_stop(sctp_cmd_seq_t *cmds,
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900603 struct sctp_association *asoc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604{
605 struct sctp_transport *t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Robert P. J. Day9dbc15f2008-04-12 18:54:24 -0700607 list_for_each_entry(t, &asoc->peer.transport_addr_list,
608 transports) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 if (timer_pending(&t->T3_rtx_timer) &&
610 del_timer(&t->T3_rtx_timer)) {
611 sctp_transport_put(t);
612 }
613 }
614}
615
616
617/* Helper function to update the heartbeat timer. */
618static void sctp_cmd_hb_timer_update(sctp_cmd_seq_t *cmds,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 struct sctp_transport *t)
620{
621 /* Update the heartbeat timer. */
622 if (!mod_timer(&t->hb_timer, sctp_transport_timeout(t)))
623 sctp_transport_hold(t);
624}
625
626/* Helper function to handle the reception of an HEARTBEAT ACK. */
627static void sctp_cmd_transport_on(sctp_cmd_seq_t *cmds,
628 struct sctp_association *asoc,
629 struct sctp_transport *t,
630 struct sctp_chunk *chunk)
631{
632 sctp_sender_hb_info_t *hbinfo;
633
634 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of the
635 * HEARTBEAT should clear the error counter of the destination
636 * transport address to which the HEARTBEAT was sent.
637 * The association's overall error count is also cleared.
638 */
639 t->error_count = 0;
640 t->asoc->overall_error_count = 0;
641
Vlad Yasevichfaee47c2009-02-13 08:33:43 +0000642 /* Clear the hb_sent flag to signal that we had a good
643 * acknowledgement.
644 */
645 t->hb_sent = 0;
646
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 /* Mark the destination transport address as active if it is not so
648 * marked.
649 */
Sridhar Samudralaad8fec12006-07-21 14:48:50 -0700650 if ((t->state == SCTP_INACTIVE) || (t->state == SCTP_UNCONFIRMED))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 sctp_assoc_control_transport(asoc, t, SCTP_TRANSPORT_UP,
652 SCTP_HEARTBEAT_SUCCESS);
653
654 /* The receiver of the HEARTBEAT ACK should also perform an
655 * RTT measurement for that destination transport address
656 * using the time value carried in the HEARTBEAT ACK chunk.
Vlad Yaseviche533ca12007-01-30 14:36:14 -0800657 * If the transport's rto_pending variable has been cleared,
658 * it was most likely due to a retransmit. However, we want
659 * to re-enable it to properly update the rto.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 */
Vlad Yaseviche533ca12007-01-30 14:36:14 -0800661 if (t->rto_pending == 0)
662 t->rto_pending = 1;
663
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data;
665 sctp_transport_update_rto(t, (jiffies - hbinfo->sent_at));
Sridhar Samudralaad8fec12006-07-21 14:48:50 -0700666
667 /* Update the heartbeat timer. */
668 if (!mod_timer(&t->hb_timer, sctp_transport_timeout(t)))
669 sctp_transport_hold(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670}
671
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
673/* Helper function to process the process SACK command. */
674static int sctp_cmd_process_sack(sctp_cmd_seq_t *cmds,
675 struct sctp_association *asoc,
676 struct sctp_sackhdr *sackh)
677{
Vlad Yasevich2e3216c2008-06-19 16:08:18 -0700678 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
680 if (sctp_outq_sack(&asoc->outqueue, sackh)) {
681 /* There are no more TSNs awaiting SACK. */
682 err = sctp_do_sm(SCTP_EVENT_T_OTHER,
683 SCTP_ST_OTHER(SCTP_EVENT_NO_PENDING_TSN),
684 asoc->state, asoc->ep, asoc, NULL,
685 GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 }
687
688 return err;
689}
690
691/* Helper function to set the timeout value for T2-SHUTDOWN timer and to set
692 * the transport for a shutdown chunk.
693 */
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900694static void sctp_cmd_setup_t2(sctp_cmd_seq_t *cmds,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 struct sctp_association *asoc,
696 struct sctp_chunk *chunk)
697{
698 struct sctp_transport *t;
699
Vlad Yasevichc17b02b2010-04-30 21:42:43 -0400700 if (chunk->transport)
701 t = chunk->transport;
702 else {
703 t = sctp_assoc_choose_alter_transport(asoc,
Wei Yongjun9919b452009-05-12 21:52:51 +0800704 asoc->shutdown_last_sent_to);
Vlad Yasevichc17b02b2010-04-30 21:42:43 -0400705 chunk->transport = t;
706 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 asoc->shutdown_last_sent_to = t;
708 asoc->timeouts[SCTP_EVENT_TIMEOUT_T2_SHUTDOWN] = t->rto;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709}
710
711/* Helper function to change the state of an association. */
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900712static void sctp_cmd_new_state(sctp_cmd_seq_t *cmds,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 struct sctp_association *asoc,
714 sctp_state_t state)
715{
716 struct sock *sk = asoc->base.sk;
717
718 asoc->state = state;
719
Frank Filz3f7a87d2005-06-20 13:14:57 -0700720 SCTP_DEBUG_PRINTK("sctp_cmd_new_state: asoc %p[%s]\n",
721 asoc, sctp_state_tbl[state]);
722
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 if (sctp_style(sk, TCP)) {
Frank Filz3f7a87d2005-06-20 13:14:57 -0700724 /* Change the sk->sk_state of a TCP-style socket that has
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200725 * successfully completed a connect() call.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 */
727 if (sctp_state(asoc, ESTABLISHED) && sctp_sstate(sk, CLOSED))
728 sk->sk_state = SCTP_SS_ESTABLISHED;
729
730 /* Set the RCV_SHUTDOWN flag when a SHUTDOWN is received. */
731 if (sctp_state(asoc, SHUTDOWN_RECEIVED) &&
732 sctp_sstate(sk, ESTABLISHED))
733 sk->sk_shutdown |= RCV_SHUTDOWN;
734 }
735
Frank Filz3f7a87d2005-06-20 13:14:57 -0700736 if (sctp_state(asoc, COOKIE_WAIT)) {
737 /* Reset init timeouts since they may have been
738 * increased due to timer expirations.
739 */
740 asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_INIT] =
Vladislav Yasevich1e7d3d92005-11-11 16:06:16 -0800741 asoc->rto_initial;
Frank Filz3f7a87d2005-06-20 13:14:57 -0700742 asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE] =
Vladislav Yasevich1e7d3d92005-11-11 16:06:16 -0800743 asoc->rto_initial;
Frank Filz3f7a87d2005-06-20 13:14:57 -0700744 }
745
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 if (sctp_state(asoc, ESTABLISHED) ||
747 sctp_state(asoc, CLOSED) ||
748 sctp_state(asoc, SHUTDOWN_RECEIVED)) {
749 /* Wake up any processes waiting in the asoc's wait queue in
750 * sctp_wait_for_connect() or sctp_wait_for_sndbuf().
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900751 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 if (waitqueue_active(&asoc->wait))
753 wake_up_interruptible(&asoc->wait);
754
755 /* Wake up any processes waiting in the sk's sleep queue of
756 * a TCP-style or UDP-style peeled-off socket in
757 * sctp_wait_for_accept() or sctp_wait_for_packet().
758 * For a UDP-style socket, the waiters are woken up by the
759 * notifications.
760 */
761 if (!sctp_style(sk, UDP))
762 sk->sk_state_change(sk);
763 }
764}
765
766/* Helper function to delete an association. */
767static void sctp_cmd_delete_tcb(sctp_cmd_seq_t *cmds,
768 struct sctp_association *asoc)
769{
770 struct sock *sk = asoc->base.sk;
771
772 /* If it is a non-temporary association belonging to a TCP-style
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900773 * listening socket that is not closed, do not free it so that accept()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 * can pick it up later.
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900775 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 if (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING) &&
777 (!asoc->temp) && (sk->sk_shutdown != SHUTDOWN_MASK))
778 return;
779
780 sctp_unhash_established(asoc);
781 sctp_association_free(asoc);
782}
783
784/*
785 * ADDIP Section 4.1 ASCONF Chunk Procedures
786 * A4) Start a T-4 RTO timer, using the RTO value of the selected
787 * destination address (we use active path instead of primary path just
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900788 * because primary path may be inactive.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 */
790static void sctp_cmd_setup_t4(sctp_cmd_seq_t *cmds,
791 struct sctp_association *asoc,
792 struct sctp_chunk *chunk)
793{
794 struct sctp_transport *t;
795
Wei Yongjun9919b452009-05-12 21:52:51 +0800796 t = sctp_assoc_choose_alter_transport(asoc, chunk->transport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 asoc->timeouts[SCTP_EVENT_TIMEOUT_T4_RTO] = t->rto;
798 chunk->transport = t;
799}
800
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900801/* Process an incoming Operation Error Chunk. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802static void sctp_cmd_process_operr(sctp_cmd_seq_t *cmds,
803 struct sctp_association *asoc,
804 struct sctp_chunk *chunk)
805{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 struct sctp_errhdr *err_hdr;
Wei Yongjun3df26782009-03-02 06:46:51 +0000807 struct sctp_ulpevent *ev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Wei Yongjun3df26782009-03-02 06:46:51 +0000809 while (chunk->chunk_end > chunk->skb->data) {
810 err_hdr = (struct sctp_errhdr *)(chunk->skb->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
Wei Yongjun3df26782009-03-02 06:46:51 +0000812 ev = sctp_ulpevent_make_remote_error(asoc, chunk, 0,
813 GFP_ATOMIC);
814 if (!ev)
815 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Wei Yongjun3df26782009-03-02 06:46:51 +0000817 sctp_ulpq_tail_event(&asoc->ulpq, ev);
818
819 switch (err_hdr->cause) {
820 case SCTP_ERROR_UNKNOWN_CHUNK:
821 {
822 sctp_chunkhdr_t *unk_chunk_hdr;
823
824 unk_chunk_hdr = (sctp_chunkhdr_t *)err_hdr->variable;
825 switch (unk_chunk_hdr->type) {
826 /* ADDIP 4.1 A9) If the peer responds to an ASCONF with
827 * an ERROR chunk reporting that it did not recognized
828 * the ASCONF chunk type, the sender of the ASCONF MUST
829 * NOT send any further ASCONF chunks and MUST stop its
830 * T-4 timer.
831 */
832 case SCTP_CID_ASCONF:
833 if (asoc->peer.asconf_capable == 0)
834 break;
835
836 asoc->peer.asconf_capable = 0;
837 sctp_add_cmd_sf(cmds, SCTP_CMD_TIMER_STOP,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
Wei Yongjun3df26782009-03-02 06:46:51 +0000839 break;
840 default:
841 break;
842 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 break;
Wei Yongjun3df26782009-03-02 06:46:51 +0000844 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 default:
846 break;
847 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 }
849}
850
851/* Process variable FWDTSN chunk information. */
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900852static void sctp_cmd_process_fwdtsn(struct sctp_ulpq *ulpq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 struct sctp_chunk *chunk)
854{
855 struct sctp_fwdtsn_skip *skip;
856 /* Walk through all the skipped SSNs */
857 sctp_walk_fwdtsn(skip, chunk) {
858 sctp_ulpq_skip(ulpq, ntohs(skip->stream), ntohs(skip->ssn));
859 }
860
861 return;
862}
863
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900864/* Helper function to remove the association non-primary peer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 * transports.
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900866 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867static void sctp_cmd_del_non_primary(struct sctp_association *asoc)
868{
869 struct sctp_transport *t;
870 struct list_head *pos;
871 struct list_head *temp;
872
873 list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
874 t = list_entry(pos, struct sctp_transport, transports);
Al Viro5f242a12006-11-20 17:05:23 -0800875 if (!sctp_cmp_addr_exact(&t->ipaddr,
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900876 &asoc->peer.primary_addr)) {
Al Viro38a03142006-11-20 17:06:45 -0800877 sctp_assoc_del_peer(asoc, &t->ipaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 }
879 }
880
881 return;
882}
883
Sridhar Samudrala8de8c872006-05-19 10:58:12 -0700884/* Helper function to set sk_err on a 1-1 style socket. */
885static void sctp_cmd_set_sk_err(struct sctp_association *asoc, int error)
886{
887 struct sock *sk = asoc->base.sk;
888
889 if (!sctp_style(sk, UDP))
890 sk->sk_err = error;
891}
892
Vlad Yasevich07d93962007-05-04 13:55:27 -0700893/* Helper function to generate an association change event */
894static void sctp_cmd_assoc_change(sctp_cmd_seq_t *commands,
895 struct sctp_association *asoc,
896 u8 state)
897{
898 struct sctp_ulpevent *ev;
899
900 ev = sctp_ulpevent_make_assoc_change(asoc, 0, state, 0,
901 asoc->c.sinit_num_ostreams,
902 asoc->c.sinit_max_instreams,
903 NULL, GFP_ATOMIC);
904 if (ev)
905 sctp_ulpq_tail_event(&asoc->ulpq, ev);
906}
907
908/* Helper function to generate an adaptation indication event */
909static void sctp_cmd_adaptation_ind(sctp_cmd_seq_t *commands,
910 struct sctp_association *asoc)
911{
912 struct sctp_ulpevent *ev;
913
914 ev = sctp_ulpevent_make_adaptation_indication(asoc, GFP_ATOMIC);
915
916 if (ev)
917 sctp_ulpq_tail_event(&asoc->ulpq, ev);
918}
919
Vlad Yasevich96cd0d32008-09-08 14:00:26 -0400920
921static void sctp_cmd_t1_timer_update(struct sctp_association *asoc,
922 sctp_event_timeout_t timer,
923 char *name)
924{
925 struct sctp_transport *t;
926
927 t = asoc->init_last_sent_to;
928 asoc->init_err_counter++;
929
930 if (t->init_sent_count > (asoc->init_cycle + 1)) {
931 asoc->timeouts[timer] *= 2;
932 if (asoc->timeouts[timer] > asoc->max_init_timeo) {
933 asoc->timeouts[timer] = asoc->max_init_timeo;
934 }
935 asoc->init_cycle++;
936 SCTP_DEBUG_PRINTK(
937 "T1 %s Timeout adjustment"
938 " init_err_counter: %d"
939 " cycle: %d"
940 " timeout: %ld\n",
941 name,
942 asoc->init_err_counter,
943 asoc->init_cycle,
944 asoc->timeouts[timer]);
945 }
946
947}
948
Vlad Yasevich9c5c62b2009-08-10 13:51:03 -0400949/* Send the whole message, chunk by chunk, to the outqueue.
950 * This way the whole message is queued up and bundling if
951 * encouraged for small fragments.
952 */
953static int sctp_cmd_send_msg(struct sctp_association *asoc,
954 struct sctp_datamsg *msg)
955{
956 struct sctp_chunk *chunk;
957 int error = 0;
958
959 list_for_each_entry(chunk, &msg->chunks, frag_list) {
960 error = sctp_outq_tail(&asoc->outqueue, chunk);
961 if (error)
962 break;
963 }
964
965 return error;
966}
967
968
Vlad Yasevichc0786692010-04-28 08:47:22 +0000969/* Sent the next ASCONF packet currently stored in the association.
970 * This happens after the ASCONF_ACK was succeffully processed.
971 */
972static void sctp_cmd_send_asconf(struct sctp_association *asoc)
973{
974 /* Send the next asconf chunk from the addip chunk
975 * queue.
976 */
977 if (!list_empty(&asoc->addip_chunk_list)) {
978 struct list_head *entry = asoc->addip_chunk_list.next;
979 struct sctp_chunk *asconf = list_entry(entry,
980 struct sctp_chunk, list);
981 list_del_init(entry);
982
983 /* Hold the chunk until an ASCONF_ACK is received. */
984 sctp_chunk_hold(asconf);
985 if (sctp_primitive_ASCONF(asoc, asconf))
986 sctp_chunk_free(asconf);
987 else
988 asoc->addip_last_asconf = asconf;
989 }
990}
991
Vlad Yasevich9c5c62b2009-08-10 13:51:03 -0400992
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993/* These three macros allow us to pull the debugging code out of the
994 * main flow of sctp_do_sm() to keep attention focused on the real
995 * functionality there.
996 */
997#define DEBUG_PRE \
998 SCTP_DEBUG_PRINTK("sctp_do_sm prefn: " \
999 "ep %p, %s, %s, asoc %p[%s], %s\n", \
1000 ep, sctp_evttype_tbl[event_type], \
1001 (*debug_fn)(subtype), asoc, \
1002 sctp_state_tbl[state], state_fn->name)
1003
1004#define DEBUG_POST \
1005 SCTP_DEBUG_PRINTK("sctp_do_sm postfn: " \
1006 "asoc %p, status: %s\n", \
1007 asoc, sctp_status_tbl[status])
1008
1009#define DEBUG_POST_SFX \
1010 SCTP_DEBUG_PRINTK("sctp_do_sm post sfx: error %d, asoc %p[%s]\n", \
1011 error, asoc, \
1012 sctp_state_tbl[(asoc && sctp_id2assoc(ep->base.sk, \
1013 sctp_assoc2id(asoc)))?asoc->state:SCTP_STATE_CLOSED])
1014
1015/*
1016 * This is the master state machine processing function.
1017 *
1018 * If you want to understand all of lksctp, this is a
1019 * good place to start.
1020 */
1021int sctp_do_sm(sctp_event_t event_type, sctp_subtype_t subtype,
1022 sctp_state_t state,
1023 struct sctp_endpoint *ep,
1024 struct sctp_association *asoc,
1025 void *event_arg,
Al Virodd0fc662005-10-07 07:46:04 +01001026 gfp_t gfp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027{
1028 sctp_cmd_seq_t commands;
1029 const sctp_sm_table_entry_t *state_fn;
1030 sctp_disposition_t status;
1031 int error = 0;
1032 typedef const char *(printfn_t)(sctp_subtype_t);
1033
1034 static printfn_t *table[] = {
1035 NULL, sctp_cname, sctp_tname, sctp_oname, sctp_pname,
1036 };
1037 printfn_t *debug_fn __attribute__ ((unused)) = table[event_type];
1038
1039 /* Look up the state function, run it, and then process the
1040 * side effects. These three steps are the heart of lksctp.
1041 */
1042 state_fn = sctp_sm_lookup_event(event_type, state, subtype);
1043
1044 sctp_init_cmd_seq(&commands);
1045
1046 DEBUG_PRE;
1047 status = (*state_fn->fn)(ep, asoc, subtype, event_arg, &commands);
1048 DEBUG_POST;
1049
1050 error = sctp_side_effects(event_type, subtype, state,
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001051 ep, asoc, event_arg, status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 &commands, gfp);
1053 DEBUG_POST_SFX;
1054
1055 return error;
1056}
1057
1058#undef DEBUG_PRE
1059#undef DEBUG_POST
1060
1061/*****************************************************************
1062 * This the master state function side effect processing function.
1063 *****************************************************************/
1064static int sctp_side_effects(sctp_event_t event_type, sctp_subtype_t subtype,
1065 sctp_state_t state,
1066 struct sctp_endpoint *ep,
1067 struct sctp_association *asoc,
1068 void *event_arg,
1069 sctp_disposition_t status,
1070 sctp_cmd_seq_t *commands,
Al Virodd0fc662005-10-07 07:46:04 +01001071 gfp_t gfp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072{
1073 int error;
1074
1075 /* FIXME - Most of the dispositions left today would be categorized
1076 * as "exceptional" dispositions. For those dispositions, it
1077 * may not be proper to run through any of the commands at all.
1078 * For example, the command interpreter might be run only with
1079 * disposition SCTP_DISPOSITION_CONSUME.
1080 */
1081 if (0 != (error = sctp_cmd_interpreter(event_type, subtype, state,
1082 ep, asoc,
1083 event_arg, status,
1084 commands, gfp)))
1085 goto bail;
1086
1087 switch (status) {
1088 case SCTP_DISPOSITION_DISCARD:
1089 SCTP_DEBUG_PRINTK("Ignored sctp protocol event - state %d, "
1090 "event_type %d, event_id %d\n",
1091 state, event_type, subtype.chunk);
1092 break;
1093
1094 case SCTP_DISPOSITION_NOMEM:
1095 /* We ran out of memory, so we need to discard this
1096 * packet.
1097 */
1098 /* BUG--we should now recover some memory, probably by
1099 * reneging...
1100 */
1101 error = -ENOMEM;
1102 break;
1103
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001104 case SCTP_DISPOSITION_DELETE_TCB:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 /* This should now be a command. */
1106 break;
1107
1108 case SCTP_DISPOSITION_CONSUME:
1109 case SCTP_DISPOSITION_ABORT:
1110 /*
1111 * We should no longer have much work to do here as the
1112 * real work has been done as explicit commands above.
1113 */
1114 break;
1115
1116 case SCTP_DISPOSITION_VIOLATION:
Wei Yongjund99fa422007-08-27 11:19:24 +08001117 if (net_ratelimit())
1118 printk(KERN_ERR "sctp protocol violation state %d "
1119 "chunkid %d\n", state, subtype.chunk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 break;
1121
1122 case SCTP_DISPOSITION_NOT_IMPL:
1123 printk(KERN_WARNING "sctp unimplemented feature in state %d, "
1124 "event_type %d, event_id %d\n",
1125 state, event_type, subtype.chunk);
1126 break;
1127
1128 case SCTP_DISPOSITION_BUG:
1129 printk(KERN_ERR "sctp bug in state %d, "
1130 "event_type %d, event_id %d\n",
1131 state, event_type, subtype.chunk);
1132 BUG();
1133 break;
1134
1135 default:
1136 printk(KERN_ERR "sctp impossible disposition %d "
1137 "in state %d, event_type %d, event_id %d\n",
1138 status, state, event_type, subtype.chunk);
1139 BUG();
1140 break;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -07001141 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
1143bail:
1144 return error;
1145}
1146
1147/********************************************************************
1148 * 2nd Level Abstractions
1149 ********************************************************************/
1150
1151/* This is the side-effect interpreter. */
1152static int sctp_cmd_interpreter(sctp_event_t event_type,
1153 sctp_subtype_t subtype,
1154 sctp_state_t state,
1155 struct sctp_endpoint *ep,
1156 struct sctp_association *asoc,
1157 void *event_arg,
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001158 sctp_disposition_t status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 sctp_cmd_seq_t *commands,
Al Virodd0fc662005-10-07 07:46:04 +01001160 gfp_t gfp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161{
1162 int error = 0;
1163 int force;
1164 sctp_cmd_t *cmd;
1165 struct sctp_chunk *new_obj;
1166 struct sctp_chunk *chunk = NULL;
1167 struct sctp_packet *packet;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 struct timer_list *timer;
1169 unsigned long timeout;
1170 struct sctp_transport *t;
1171 struct sctp_sackhdr sackh;
1172 int local_cork = 0;
1173
1174 if (SCTP_EVENT_T_TIMEOUT != event_type)
1175 chunk = (struct sctp_chunk *) event_arg;
1176
1177 /* Note: This whole file is a huge candidate for rework.
1178 * For example, each command could either have its own handler, so
1179 * the loop would look like:
1180 * while (cmds)
1181 * cmd->handle(x, y, z)
1182 * --jgrimm
1183 */
1184 while (NULL != (cmd = sctp_next_cmd(commands))) {
1185 switch (cmd->verb) {
1186 case SCTP_CMD_NOP:
1187 /* Do nothing. */
1188 break;
1189
1190 case SCTP_CMD_NEW_ASOC:
1191 /* Register a new association. */
1192 if (local_cork) {
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001193 sctp_outq_uncork(&asoc->outqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 local_cork = 0;
1195 }
1196 asoc = cmd->obj.ptr;
1197 /* Register with the endpoint. */
1198 sctp_endpoint_add_asoc(ep, asoc);
1199 sctp_hash_established(asoc);
1200 break;
1201
1202 case SCTP_CMD_UPDATE_ASSOC:
1203 sctp_assoc_update(asoc, cmd->obj.ptr);
1204 break;
1205
1206 case SCTP_CMD_PURGE_OUTQUEUE:
1207 sctp_outq_teardown(&asoc->outqueue);
1208 break;
1209
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001210 case SCTP_CMD_DELETE_TCB:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 if (local_cork) {
1212 sctp_outq_uncork(&asoc->outqueue);
1213 local_cork = 0;
1214 }
1215 /* Delete the current association. */
1216 sctp_cmd_delete_tcb(commands, asoc);
1217 asoc = NULL;
1218 break;
1219
1220 case SCTP_CMD_NEW_STATE:
1221 /* Enter a new state. */
1222 sctp_cmd_new_state(commands, asoc, cmd->obj.state);
1223 break;
1224
1225 case SCTP_CMD_REPORT_TSN:
1226 /* Record the arrival of a TSN. */
Vlad Yasevich8e1ee182008-10-08 14:18:39 -07001227 error = sctp_tsnmap_mark(&asoc->peer.tsn_map,
1228 cmd->obj.u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 break;
1230
1231 case SCTP_CMD_REPORT_FWDTSN:
1232 /* Move the Cumulattive TSN Ack ahead. */
1233 sctp_tsnmap_skip(&asoc->peer.tsn_map, cmd->obj.u32);
1234
Vlad Yasevichea2dfb32007-07-13 17:01:19 -04001235 /* purge the fragmentation queue */
1236 sctp_ulpq_reasm_flushtsn(&asoc->ulpq, cmd->obj.u32);
1237
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 /* Abort any in progress partial delivery. */
1239 sctp_ulpq_abort_pd(&asoc->ulpq, GFP_ATOMIC);
1240 break;
1241
1242 case SCTP_CMD_PROCESS_FWDTSN:
1243 sctp_cmd_process_fwdtsn(&asoc->ulpq, cmd->obj.ptr);
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001244 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
1246 case SCTP_CMD_GEN_SACK:
1247 /* Generate a Selective ACK.
1248 * The argument tells us whether to just count
1249 * the packet and MAYBE generate a SACK, or
1250 * force a SACK out.
1251 */
1252 force = cmd->obj.i32;
1253 error = sctp_gen_sack(asoc, force, commands);
1254 break;
1255
1256 case SCTP_CMD_PROCESS_SACK:
1257 /* Process an inbound SACK. */
1258 error = sctp_cmd_process_sack(commands, asoc,
1259 cmd->obj.ptr);
1260 break;
1261
1262 case SCTP_CMD_GEN_INIT_ACK:
1263 /* Generate an INIT ACK chunk. */
1264 new_obj = sctp_make_init_ack(asoc, chunk, GFP_ATOMIC,
1265 0);
1266 if (!new_obj)
1267 goto nomem;
1268
1269 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1270 SCTP_CHUNK(new_obj));
1271 break;
1272
1273 case SCTP_CMD_PEER_INIT:
1274 /* Process a unified INIT from the peer.
1275 * Note: Only used during INIT-ACK processing. If
1276 * there is an error just return to the outter
1277 * layer which will bail.
1278 */
1279 error = sctp_cmd_process_init(commands, asoc, chunk,
1280 cmd->obj.ptr, gfp);
1281 break;
1282
1283 case SCTP_CMD_GEN_COOKIE_ECHO:
1284 /* Generate a COOKIE ECHO chunk. */
1285 new_obj = sctp_make_cookie_echo(asoc, chunk);
1286 if (!new_obj) {
1287 if (cmd->obj.ptr)
1288 sctp_chunk_free(cmd->obj.ptr);
1289 goto nomem;
1290 }
1291 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1292 SCTP_CHUNK(new_obj));
1293
1294 /* If there is an ERROR chunk to be sent along with
1295 * the COOKIE_ECHO, send it, too.
1296 */
1297 if (cmd->obj.ptr)
1298 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1299 SCTP_CHUNK(cmd->obj.ptr));
1300
Vlad Yasevich96cd0d32008-09-08 14:00:26 -04001301 if (new_obj->transport) {
1302 new_obj->transport->init_sent_count++;
1303 asoc->init_last_sent_to = new_obj->transport;
1304 }
1305
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 /* FIXME - Eventually come up with a cleaner way to
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001307 * enabling COOKIE-ECHO + DATA bundling during
1308 * multihoming stale cookie scenarios, the following
1309 * command plays with asoc->peer.retran_path to
1310 * avoid the problem of sending the COOKIE-ECHO and
1311 * DATA in different paths, which could result
1312 * in the association being ABORTed if the DATA chunk
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 * is processed first by the server. Checking the
1314 * init error counter simply causes this command
1315 * to be executed only during failed attempts of
1316 * association establishment.
1317 */
Frank Filz3f7a87d2005-06-20 13:14:57 -07001318 if ((asoc->peer.retran_path !=
1319 asoc->peer.primary_path) &&
1320 (asoc->init_err_counter > 0)) {
1321 sctp_add_cmd_sf(commands,
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09001322 SCTP_CMD_FORCE_PRIM_RETRAN,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 SCTP_NULL());
1324 }
1325
1326 break;
1327
1328 case SCTP_CMD_GEN_SHUTDOWN:
1329 /* Generate SHUTDOWN when in SHUTDOWN_SENT state.
1330 * Reset error counts.
1331 */
1332 asoc->overall_error_count = 0;
1333
1334 /* Generate a SHUTDOWN chunk. */
1335 new_obj = sctp_make_shutdown(asoc, chunk);
1336 if (!new_obj)
1337 goto nomem;
1338 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1339 SCTP_CHUNK(new_obj));
1340 break;
1341
1342 case SCTP_CMD_CHUNK_ULP:
1343 /* Send a chunk to the sockets layer. */
1344 SCTP_DEBUG_PRINTK("sm_sideff: %s %p, %s %p.\n",
1345 "chunk_up:", cmd->obj.ptr,
1346 "ulpq:", &asoc->ulpq);
1347 sctp_ulpq_tail_data(&asoc->ulpq, cmd->obj.ptr,
1348 GFP_ATOMIC);
1349 break;
1350
1351 case SCTP_CMD_EVENT_ULP:
1352 /* Send a notification to the sockets layer. */
1353 SCTP_DEBUG_PRINTK("sm_sideff: %s %p, %s %p.\n",
1354 "event_up:",cmd->obj.ptr,
1355 "ulpq:",&asoc->ulpq);
1356 sctp_ulpq_tail_event(&asoc->ulpq, cmd->obj.ptr);
1357 break;
1358
1359 case SCTP_CMD_REPLY:
1360 /* If an caller has not already corked, do cork. */
1361 if (!asoc->outqueue.cork) {
1362 sctp_outq_cork(&asoc->outqueue);
1363 local_cork = 1;
1364 }
1365 /* Send a chunk to our peer. */
1366 error = sctp_outq_tail(&asoc->outqueue, cmd->obj.ptr);
1367 break;
1368
1369 case SCTP_CMD_SEND_PKT:
1370 /* Send a full packet to our peer. */
1371 packet = cmd->obj.ptr;
1372 sctp_packet_transmit(packet);
1373 sctp_ootb_pkt_free(packet);
1374 break;
1375
Vlad Yasevichb6157d82007-10-24 15:59:16 -04001376 case SCTP_CMD_T1_RETRAN:
1377 /* Mark a transport for retransmission. */
1378 sctp_retransmit(&asoc->outqueue, cmd->obj.transport,
1379 SCTP_RTXR_T1_RTX);
1380 break;
1381
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 case SCTP_CMD_RETRAN:
1383 /* Mark a transport for retransmission. */
1384 sctp_retransmit(&asoc->outqueue, cmd->obj.transport,
1385 SCTP_RTXR_T3_RTX);
1386 break;
1387
1388 case SCTP_CMD_TRANSMIT:
1389 /* Kick start transmission. */
1390 error = sctp_outq_uncork(&asoc->outqueue);
1391 local_cork = 0;
1392 break;
1393
1394 case SCTP_CMD_ECN_CE:
1395 /* Do delayed CE processing. */
1396 sctp_do_ecn_ce_work(asoc, cmd->obj.u32);
1397 break;
1398
1399 case SCTP_CMD_ECN_ECNE:
1400 /* Do delayed ECNE processing. */
1401 new_obj = sctp_do_ecn_ecne_work(asoc, cmd->obj.u32,
1402 chunk);
1403 if (new_obj)
1404 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1405 SCTP_CHUNK(new_obj));
1406 break;
1407
1408 case SCTP_CMD_ECN_CWR:
1409 /* Do delayed CWR processing. */
1410 sctp_do_ecn_cwr_work(asoc, cmd->obj.u32);
1411 break;
1412
1413 case SCTP_CMD_SETUP_T2:
1414 sctp_cmd_setup_t2(commands, asoc, cmd->obj.ptr);
1415 break;
1416
1417 case SCTP_CMD_TIMER_START:
1418 timer = &asoc->timers[cmd->obj.to];
1419 timeout = asoc->timeouts[cmd->obj.to];
Kris Katterjohn09a62662006-01-08 22:24:28 -08001420 BUG_ON(!timeout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
1422 timer->expires = jiffies + timeout;
1423 sctp_association_hold(asoc);
1424 add_timer(timer);
1425 break;
1426
1427 case SCTP_CMD_TIMER_RESTART:
1428 timer = &asoc->timers[cmd->obj.to];
1429 timeout = asoc->timeouts[cmd->obj.to];
1430 if (!mod_timer(timer, jiffies + timeout))
1431 sctp_association_hold(asoc);
1432 break;
1433
1434 case SCTP_CMD_TIMER_STOP:
1435 timer = &asoc->timers[cmd->obj.to];
1436 if (timer_pending(timer) && del_timer(timer))
1437 sctp_association_put(asoc);
1438 break;
1439
Frank Filz3f7a87d2005-06-20 13:14:57 -07001440 case SCTP_CMD_INIT_CHOOSE_TRANSPORT:
1441 chunk = cmd->obj.ptr;
Wei Yongjun9919b452009-05-12 21:52:51 +08001442 t = sctp_assoc_choose_alter_transport(asoc,
1443 asoc->init_last_sent_to);
Frank Filz3f7a87d2005-06-20 13:14:57 -07001444 asoc->init_last_sent_to = t;
1445 chunk->transport = t;
1446 t->init_sent_count++;
Vlad Yaseviche0e9db12009-11-23 15:53:57 -05001447 /* Set the new transport as primary */
1448 sctp_assoc_set_primary(asoc, t);
Frank Filz3f7a87d2005-06-20 13:14:57 -07001449 break;
1450
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 case SCTP_CMD_INIT_RESTART:
1452 /* Do the needed accounting and updates
1453 * associated with restarting an initialization
Frank Filz3f7a87d2005-06-20 13:14:57 -07001454 * timer. Only multiply the timeout by two if
1455 * all transports have been tried at the current
1456 * timeout.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 */
Vlad Yasevich96cd0d32008-09-08 14:00:26 -04001458 sctp_cmd_t1_timer_update(asoc,
1459 SCTP_EVENT_TIMEOUT_T1_INIT,
1460 "INIT");
Frank Filz3f7a87d2005-06-20 13:14:57 -07001461
1462 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
1463 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
1464 break;
1465
1466 case SCTP_CMD_COOKIEECHO_RESTART:
1467 /* Do the needed accounting and updates
1468 * associated with restarting an initialization
1469 * timer. Only multiply the timeout by two if
1470 * all transports have been tried at the current
1471 * timeout.
1472 */
Vlad Yasevich96cd0d32008-09-08 14:00:26 -04001473 sctp_cmd_t1_timer_update(asoc,
1474 SCTP_EVENT_TIMEOUT_T1_COOKIE,
1475 "COOKIE");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
1477 /* If we've sent any data bundled with
1478 * COOKIE-ECHO we need to resend.
1479 */
Robert P. J. Day9dbc15f2008-04-12 18:54:24 -07001480 list_for_each_entry(t, &asoc->peer.transport_addr_list,
1481 transports) {
Vlad Yasevichb6157d82007-10-24 15:59:16 -04001482 sctp_retransmit_mark(&asoc->outqueue, t,
1483 SCTP_RTXR_T1_RTX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 }
1485
1486 sctp_add_cmd_sf(commands,
1487 SCTP_CMD_TIMER_RESTART,
Frank Filz3f7a87d2005-06-20 13:14:57 -07001488 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 break;
1490
1491 case SCTP_CMD_INIT_FAILED:
Al Virodc251b22006-11-20 17:00:44 -08001492 sctp_cmd_init_failed(commands, asoc, cmd->obj.err);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 break;
1494
1495 case SCTP_CMD_ASSOC_FAILED:
1496 sctp_cmd_assoc_failed(commands, asoc, event_type,
Al Viro5be291f2006-11-20 17:01:06 -08001497 subtype, chunk, cmd->obj.err);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 break;
1499
Frank Filz3f7a87d2005-06-20 13:14:57 -07001500 case SCTP_CMD_INIT_COUNTER_INC:
1501 asoc->init_err_counter++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 break;
1503
Frank Filz3f7a87d2005-06-20 13:14:57 -07001504 case SCTP_CMD_INIT_COUNTER_RESET:
1505 asoc->init_err_counter = 0;
1506 asoc->init_cycle = 0;
Vlad Yasevich96cd0d32008-09-08 14:00:26 -04001507 list_for_each_entry(t, &asoc->peer.transport_addr_list,
1508 transports) {
1509 t->init_sent_count = 0;
1510 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 break;
1512
1513 case SCTP_CMD_REPORT_DUP:
1514 sctp_tsnmap_mark_dup(&asoc->peer.tsn_map,
1515 cmd->obj.u32);
1516 break;
1517
1518 case SCTP_CMD_REPORT_BAD_TAG:
1519 SCTP_DEBUG_PRINTK("vtag mismatch!\n");
1520 break;
1521
1522 case SCTP_CMD_STRIKE:
1523 /* Mark one strike against a transport. */
Vlad Yasevich7e990132009-03-02 09:46:14 +00001524 sctp_do_8_2_transport_strike(asoc, cmd->obj.transport,
1525 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 break;
1527
Vlad Yasevich7e990132009-03-02 09:46:14 +00001528 case SCTP_CMD_TRANSPORT_IDLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 t = cmd->obj.transport;
Vlad Yasevich7e990132009-03-02 09:46:14 +00001530 sctp_transport_lower_cwnd(t, SCTP_LOWER_CWND_INACTIVE);
1531 break;
1532
1533 case SCTP_CMD_TRANSPORT_HB_SENT:
1534 t = cmd->obj.transport;
1535 sctp_do_8_2_transport_strike(asoc, t, 1);
1536 t->hb_sent = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 break;
1538
1539 case SCTP_CMD_TRANSPORT_ON:
1540 t = cmd->obj.transport;
1541 sctp_cmd_transport_on(commands, asoc, t, chunk);
1542 break;
1543
1544 case SCTP_CMD_HB_TIMERS_START:
1545 sctp_cmd_hb_timers_start(commands, asoc);
1546 break;
1547
1548 case SCTP_CMD_HB_TIMER_UPDATE:
1549 t = cmd->obj.transport;
Gui Jianfeng765ff022008-04-12 18:55:12 -07001550 sctp_cmd_hb_timer_update(commands, t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 break;
1552
1553 case SCTP_CMD_HB_TIMERS_STOP:
1554 sctp_cmd_hb_timers_stop(commands, asoc);
1555 break;
1556
1557 case SCTP_CMD_REPORT_ERROR:
1558 error = cmd->obj.error;
1559 break;
1560
1561 case SCTP_CMD_PROCESS_CTSN:
1562 /* Dummy up a SACK for processing. */
Al Viro2178eda2006-11-20 17:26:53 -08001563 sackh.cum_tsn_ack = cmd->obj.be32;
Vlad Yasevichd4d6fb52009-09-04 18:20:59 -04001564 sackh.a_rwnd = asoc->peer.rwnd +
1565 asoc->outqueue.outstanding_bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 sackh.num_gap_ack_blocks = 0;
1567 sackh.num_dup_tsns = 0;
1568 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK,
1569 SCTP_SACKH(&sackh));
1570 break;
1571
1572 case SCTP_CMD_DISCARD_PACKET:
Vlad Yasevich2e3216c2008-06-19 16:08:18 -07001573 /* We need to discard the whole packet.
1574 * Uncork the queue since there might be
1575 * responses pending
1576 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 chunk->pdiscard = 1;
Vlad Yasevich2e3216c2008-06-19 16:08:18 -07001578 if (asoc) {
1579 sctp_outq_uncork(&asoc->outqueue);
1580 local_cork = 0;
1581 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 break;
1583
1584 case SCTP_CMD_RTO_PENDING:
1585 t = cmd->obj.transport;
1586 t->rto_pending = 1;
1587 break;
1588
1589 case SCTP_CMD_PART_DELIVER:
1590 sctp_ulpq_partial_delivery(&asoc->ulpq, cmd->obj.ptr,
1591 GFP_ATOMIC);
1592 break;
1593
1594 case SCTP_CMD_RENEGE:
1595 sctp_ulpq_renege(&asoc->ulpq, cmd->obj.ptr,
1596 GFP_ATOMIC);
1597 break;
1598
1599 case SCTP_CMD_SETUP_T4:
1600 sctp_cmd_setup_t4(commands, asoc, cmd->obj.ptr);
1601 break;
1602
1603 case SCTP_CMD_PROCESS_OPERR:
1604 sctp_cmd_process_operr(commands, asoc, chunk);
1605 break;
1606 case SCTP_CMD_CLEAR_INIT_TAG:
1607 asoc->peer.i.init_tag = 0;
1608 break;
1609 case SCTP_CMD_DEL_NON_PRIMARY:
1610 sctp_cmd_del_non_primary(asoc);
1611 break;
1612 case SCTP_CMD_T3_RTX_TIMERS_STOP:
1613 sctp_cmd_t3_rtx_timers_stop(commands, asoc);
1614 break;
1615 case SCTP_CMD_FORCE_PRIM_RETRAN:
1616 t = asoc->peer.retran_path;
1617 asoc->peer.retran_path = asoc->peer.primary_path;
1618 error = sctp_outq_uncork(&asoc->outqueue);
1619 local_cork = 0;
1620 asoc->peer.retran_path = t;
1621 break;
Sridhar Samudrala8de8c872006-05-19 10:58:12 -07001622 case SCTP_CMD_SET_SK_ERR:
1623 sctp_cmd_set_sk_err(asoc, cmd->obj.error);
1624 break;
Vlad Yasevich07d93962007-05-04 13:55:27 -07001625 case SCTP_CMD_ASSOC_CHANGE:
1626 sctp_cmd_assoc_change(commands, asoc,
1627 cmd->obj.u8);
1628 break;
1629 case SCTP_CMD_ADAPTATION_IND:
1630 sctp_cmd_adaptation_ind(commands, asoc);
1631 break;
1632
Vlad Yasevich730fc3d2007-09-16 19:32:11 -07001633 case SCTP_CMD_ASSOC_SHKEY:
1634 error = sctp_auth_asoc_init_active_key(asoc,
1635 GFP_ATOMIC);
1636 break;
Gui Jianfengf4ad85c2008-04-12 18:39:34 -07001637 case SCTP_CMD_UPDATE_INITTAG:
1638 asoc->peer.i.init_tag = cmd->obj.u32;
1639 break;
Vlad Yasevich9c5c62b2009-08-10 13:51:03 -04001640 case SCTP_CMD_SEND_MSG:
1641 if (!asoc->outqueue.cork) {
1642 sctp_outq_cork(&asoc->outqueue);
1643 local_cork = 1;
1644 }
1645 error = sctp_cmd_send_msg(asoc, cmd->obj.msg);
1646 break;
Vlad Yasevichc0786692010-04-28 08:47:22 +00001647 case SCTP_CMD_SEND_NEXT_ASCONF:
1648 sctp_cmd_send_asconf(asoc);
1649 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 default:
1651 printk(KERN_WARNING "Impossible command: %u, %p\n",
1652 cmd->verb, cmd->obj.ptr);
1653 break;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -07001654 }
1655
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 if (error)
1657 break;
1658 }
1659
1660out:
Vlad Yasevich2e3216c2008-06-19 16:08:18 -07001661 /* If this is in response to a received chunk, wait until
1662 * we are done with the packet to open the queue so that we don't
1663 * send multiple packets in response to a single request.
1664 */
1665 if (asoc && SCTP_EVENT_T_CHUNK == event_type && chunk) {
1666 if (chunk->end_of_packet || chunk->singleton)
Vlad Yasevichd4d6fb52009-09-04 18:20:59 -04001667 error = sctp_outq_uncork(&asoc->outqueue);
Vlad Yasevich2e3216c2008-06-19 16:08:18 -07001668 } else if (local_cork)
Vlad Yasevichd4d6fb52009-09-04 18:20:59 -04001669 error = sctp_outq_uncork(&asoc->outqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 return error;
1671nomem:
1672 error = -ENOMEM;
1673 goto out;
1674}
1675