drivers: power: report battery voltage in AOSP compatible format
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / net / sctp / sm_sideeffect.c
CommitLineData
60c778b2 1/* SCTP kernel implementation
1da177e4
LT
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 *
60c778b2 6 * This file is part of the SCTP kernel implementation
1da177e4
LT
7 *
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 *
60c778b2 12 * This SCTP implementation is free software;
1da177e4
LT
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)
16 * any later version.
17 *
60c778b2 18 * This SCTP implementation is distributed in the hope that it
1da177e4
LT
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.
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
145ce502
JP
50#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
51
1da177e4
LT
52#include <linux/skbuff.h>
53#include <linux/types.h>
54#include <linux/socket.h>
55#include <linux/ip.h>
5a0e3ad6 56#include <linux/gfp.h>
1da177e4
LT
57#include <net/sock.h>
58#include <net/sctp/sctp.h>
59#include <net/sctp/sm.h>
60
61static int sctp_cmd_interpreter(sctp_event_t event_type,
62 sctp_subtype_t subtype,
63 sctp_state_t state,
64 struct sctp_endpoint *ep,
65 struct sctp_association *asoc,
66 void *event_arg,
d808ad9a 67 sctp_disposition_t status,
1da177e4 68 sctp_cmd_seq_t *commands,
dd0fc66f 69 gfp_t gfp);
1da177e4
LT
70static int sctp_side_effects(sctp_event_t event_type, sctp_subtype_t subtype,
71 sctp_state_t state,
72 struct sctp_endpoint *ep,
73 struct sctp_association *asoc,
74 void *event_arg,
75 sctp_disposition_t status,
76 sctp_cmd_seq_t *commands,
dd0fc66f 77 gfp_t gfp);
1da177e4 78
5aa93bcf
NH
79static void sctp_cmd_hb_timer_update(sctp_cmd_seq_t *cmds,
80 struct sctp_transport *t);
1da177e4
LT
81/********************************************************************
82 * Helper functions
83 ********************************************************************/
84
85/* A helper function for delayed processing of INET ECN CE bit. */
d808ad9a 86static void sctp_do_ecn_ce_work(struct sctp_association *asoc,
1da177e4
LT
87 __u32 lowest_tsn)
88{
89 /* Save the TSN away for comparison when we receive CWR */
90
91 asoc->last_ecne_tsn = lowest_tsn;
92 asoc->need_ecne = 1;
93}
94
95/* Helper function for delayed processing of SCTP ECNE chunk. */
96/* RFC 2960 Appendix A
97 *
98 * RFC 2481 details a specific bit for a sender to send in
99 * the header of its next outbound TCP segment to indicate to
100 * its peer that it has reduced its congestion window. This
101 * is termed the CWR bit. For SCTP the same indication is made
102 * by including the CWR chunk. This chunk contains one data
103 * element, i.e. the TSN number that was sent in the ECNE chunk.
104 * This element represents the lowest TSN number in the datagram
105 * that was originally marked with the CE bit.
106 */
107static struct sctp_chunk *sctp_do_ecn_ecne_work(struct sctp_association *asoc,
108 __u32 lowest_tsn,
109 struct sctp_chunk *chunk)
110{
111 struct sctp_chunk *repl;
112
113 /* Our previously transmitted packet ran into some congestion
114 * so we should take action by reducing cwnd and ssthresh
115 * and then ACK our peer that we we've done so by
116 * sending a CWR.
117 */
118
119 /* First, try to determine if we want to actually lower
120 * our cwnd variables. Only lower them if the ECNE looks more
121 * recent than the last response.
122 */
123 if (TSN_lt(asoc->last_cwr_tsn, lowest_tsn)) {
124 struct sctp_transport *transport;
125
126 /* Find which transport's congestion variables
127 * need to be adjusted.
128 */
129 transport = sctp_assoc_lookup_tsn(asoc, lowest_tsn);
130
131 /* Update the congestion variables. */
132 if (transport)
133 sctp_transport_lower_cwnd(transport,
134 SCTP_LOWER_CWND_ECNE);
135 asoc->last_cwr_tsn = lowest_tsn;
136 }
137
138 /* Always try to quiet the other end. In case of lost CWR,
139 * resend last_cwr_tsn.
140 */
141 repl = sctp_make_cwr(asoc, asoc->last_cwr_tsn, chunk);
142
143 /* If we run out of memory, it will look like a lost CWR. We'll
144 * get back in sync eventually.
145 */
146 return repl;
147}
148
149/* Helper function to do delayed processing of ECN CWR chunk. */
150static void sctp_do_ecn_cwr_work(struct sctp_association *asoc,
151 __u32 lowest_tsn)
152{
153 /* Turn off ECNE getting auto-prepended to every outgoing
154 * packet
155 */
156 asoc->need_ecne = 0;
157}
158
159/* Generate SACK if necessary. We call this at the end of a packet. */
160static int sctp_gen_sack(struct sctp_association *asoc, int force,
161 sctp_cmd_seq_t *commands)
162{
163 __u32 ctsn, max_tsn_seen;
164 struct sctp_chunk *sack;
52ccb8e9 165 struct sctp_transport *trans = asoc->peer.last_data_from;
1da177e4
LT
166 int error = 0;
167
d808ad9a 168 if (force ||
52ccb8e9
FF
169 (!trans && (asoc->param_flags & SPP_SACKDELAY_DISABLE)) ||
170 (trans && (trans->param_flags & SPP_SACKDELAY_DISABLE)))
1da177e4
LT
171 asoc->peer.sack_needed = 1;
172
173 ctsn = sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map);
174 max_tsn_seen = sctp_tsnmap_get_max_tsn_seen(&asoc->peer.tsn_map);
175
176 /* From 12.2 Parameters necessary per association (i.e. the TCB):
177 *
178 * Ack State : This flag indicates if the next received packet
179 * : is to be responded to with a SACK. ...
180 * : When DATA chunks are out of order, SACK's
181 * : are not delayed (see Section 6).
182 *
183 * [This is actually not mentioned in Section 6, but we
184 * implement it here anyway. --piggy]
185 */
d808ad9a 186 if (max_tsn_seen != ctsn)
1da177e4
LT
187 asoc->peer.sack_needed = 1;
188
189 /* From 6.2 Acknowledgement on Reception of DATA Chunks:
190 *
191 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically,
192 * an acknowledgement SHOULD be generated for at least every
193 * second packet (not every second DATA chunk) received, and
194 * SHOULD be generated within 200 ms of the arrival of any
195 * unacknowledged DATA chunk. ...
196 */
197 if (!asoc->peer.sack_needed) {
d364d927 198 asoc->peer.sack_cnt++;
52ccb8e9
FF
199
200 /* Set the SACK delay timeout based on the
201 * SACK delay for the last transport
202 * data was received from, or the default
203 * for the association.
204 */
d364d927
WY
205 if (trans) {
206 /* We will need a SACK for the next packet. */
207 if (asoc->peer.sack_cnt >= trans->sackfreq - 1)
208 asoc->peer.sack_needed = 1;
209
d808ad9a 210 asoc->timeouts[SCTP_EVENT_TIMEOUT_SACK] =
52ccb8e9 211 trans->sackdelay;
d364d927
WY
212 } else {
213 /* We will need a SACK for the next packet. */
214 if (asoc->peer.sack_cnt >= asoc->sackfreq - 1)
215 asoc->peer.sack_needed = 1;
216
d808ad9a 217 asoc->timeouts[SCTP_EVENT_TIMEOUT_SACK] =
52ccb8e9 218 asoc->sackdelay;
d364d927 219 }
52ccb8e9
FF
220
221 /* Restart the SACK timer. */
222 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
223 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
1da177e4 224 } else {
90f2f531 225 asoc->a_rwnd = asoc->rwnd;
1da177e4
LT
226 sack = sctp_make_sack(asoc);
227 if (!sack)
228 goto nomem;
229
230 asoc->peer.sack_needed = 0;
d364d927 231 asoc->peer.sack_cnt = 0;
1da177e4 232
732ba35e 233 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(sack));
1da177e4
LT
234
235 /* Stop the SACK timer. */
236 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
237 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
238 }
52ccb8e9 239
1da177e4
LT
240 return error;
241nomem:
242 error = -ENOMEM;
243 return error;
244}
245
246/* When the T3-RTX timer expires, it calls this function to create the
247 * relevant state machine event.
248 */
249void sctp_generate_t3_rtx_event(unsigned long peer)
250{
251 int error;
252 struct sctp_transport *transport = (struct sctp_transport *) peer;
253 struct sctp_association *asoc = transport->asoc;
1cf7c76e
KH
254 struct sock *sk = asoc->base.sk;
255 struct net *net = sock_net(sk);
1da177e4
LT
256
257 /* Check whether a task is in the sock. */
258
1cf7c76e
KH
259 sctp_bh_lock_sock(sk);
260 if (sock_owned_by_user(sk)) {
0dc47877 261 SCTP_DEBUG_PRINTK("%s:Sock is busy.\n", __func__);
1da177e4
LT
262
263 /* Try again later. */
264 if (!mod_timer(&transport->T3_rtx_timer, jiffies + (HZ/20)))
265 sctp_transport_hold(transport);
266 goto out_unlock;
267 }
268
269 /* Is this transport really dead and just waiting around for
270 * the timer to let go of the reference?
271 */
272 if (transport->dead)
273 goto out_unlock;
274
275 /* Run through the state machine. */
55e26eb9 276 error = sctp_do_sm(net, SCTP_EVENT_T_TIMEOUT,
1da177e4
LT
277 SCTP_ST_TIMEOUT(SCTP_EVENT_TIMEOUT_T3_RTX),
278 asoc->state,
279 asoc->ep, asoc,
280 transport, GFP_ATOMIC);
281
282 if (error)
1cf7c76e 283 sk->sk_err = -error;
1da177e4
LT
284
285out_unlock:
1cf7c76e 286 sctp_bh_unlock_sock(sk);
1da177e4
LT
287 sctp_transport_put(transport);
288}
289
290/* This is a sa interface for producing timeout events. It works
291 * for timeouts which use the association as their parameter.
292 */
293static void sctp_generate_timeout_event(struct sctp_association *asoc,
294 sctp_event_timeout_t timeout_type)
295{
1cf7c76e
KH
296 struct sock *sk = asoc->base.sk;
297 struct net *net = sock_net(sk);
1da177e4
LT
298 int error = 0;
299
1cf7c76e
KH
300 sctp_bh_lock_sock(sk);
301 if (sock_owned_by_user(sk)) {
1da177e4 302 SCTP_DEBUG_PRINTK("%s:Sock is busy: timer %d\n",
0dc47877 303 __func__,
1da177e4
LT
304 timeout_type);
305
306 /* Try again later. */
307 if (!mod_timer(&asoc->timers[timeout_type], jiffies + (HZ/20)))
308 sctp_association_hold(asoc);
309 goto out_unlock;
310 }
311
312 /* Is this association really dead and just waiting around for
313 * the timer to let go of the reference?
314 */
315 if (asoc->base.dead)
316 goto out_unlock;
317
318 /* Run through the state machine. */
55e26eb9 319 error = sctp_do_sm(net, SCTP_EVENT_T_TIMEOUT,
1da177e4
LT
320 SCTP_ST_TIMEOUT(timeout_type),
321 asoc->state, asoc->ep, asoc,
322 (void *)timeout_type, GFP_ATOMIC);
323
324 if (error)
1cf7c76e 325 sk->sk_err = -error;
1da177e4
LT
326
327out_unlock:
1cf7c76e 328 sctp_bh_unlock_sock(sk);
1da177e4
LT
329 sctp_association_put(asoc);
330}
331
332static void sctp_generate_t1_cookie_event(unsigned long data)
333{
334 struct sctp_association *asoc = (struct sctp_association *) data;
335 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T1_COOKIE);
336}
337
338static void sctp_generate_t1_init_event(unsigned long data)
339{
340 struct sctp_association *asoc = (struct sctp_association *) data;
341 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T1_INIT);
342}
343
344static void sctp_generate_t2_shutdown_event(unsigned long data)
345{
346 struct sctp_association *asoc = (struct sctp_association *) data;
347 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T2_SHUTDOWN);
348}
349
350static void sctp_generate_t4_rto_event(unsigned long data)
351{
352 struct sctp_association *asoc = (struct sctp_association *) data;
353 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T4_RTO);
354}
355
356static void sctp_generate_t5_shutdown_guard_event(unsigned long data)
357{
d808ad9a
YH
358 struct sctp_association *asoc = (struct sctp_association *)data;
359 sctp_generate_timeout_event(asoc,
1da177e4
LT
360 SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD);
361
362} /* sctp_generate_t5_shutdown_guard_event() */
363
364static void sctp_generate_autoclose_event(unsigned long data)
365{
366 struct sctp_association *asoc = (struct sctp_association *) data;
367 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_AUTOCLOSE);
368}
369
370/* Generate a heart beat event. If the sock is busy, reschedule. Make
371 * sure that the transport is still valid.
372 */
373void sctp_generate_heartbeat_event(unsigned long data)
374{
375 int error = 0;
376 struct sctp_transport *transport = (struct sctp_transport *) data;
377 struct sctp_association *asoc = transport->asoc;
1cf7c76e
KH
378 struct sock *sk = asoc->base.sk;
379 struct net *net = sock_net(sk);
1da177e4 380
1cf7c76e
KH
381 sctp_bh_lock_sock(sk);
382 if (sock_owned_by_user(sk)) {
0dc47877 383 SCTP_DEBUG_PRINTK("%s:Sock is busy.\n", __func__);
1da177e4
LT
384
385 /* Try again later. */
386 if (!mod_timer(&transport->hb_timer, jiffies + (HZ/20)))
387 sctp_transport_hold(transport);
388 goto out_unlock;
389 }
390
391 /* Is this structure just waiting around for us to actually
392 * get destroyed?
393 */
394 if (transport->dead)
395 goto out_unlock;
396
55e26eb9 397 error = sctp_do_sm(net, SCTP_EVENT_T_TIMEOUT,
1da177e4
LT
398 SCTP_ST_TIMEOUT(SCTP_EVENT_TIMEOUT_HEARTBEAT),
399 asoc->state, asoc->ep, asoc,
400 transport, GFP_ATOMIC);
401
d808ad9a 402 if (error)
1cf7c76e 403 sk->sk_err = -error;
1da177e4
LT
404
405out_unlock:
1cf7c76e 406 sctp_bh_unlock_sock(sk);
1da177e4
LT
407 sctp_transport_put(transport);
408}
409
50b5d6ad
VY
410/* Handle the timeout of the ICMP protocol unreachable timer. Trigger
411 * the correct state machine transition that will close the association.
412 */
413void sctp_generate_proto_unreach_event(unsigned long data)
414{
415 struct sctp_transport *transport = (struct sctp_transport *) data;
416 struct sctp_association *asoc = transport->asoc;
1cf7c76e
KH
417 struct sock *sk = asoc->base.sk;
418 struct net *net = sock_net(sk);
50b5d6ad 419
1cf7c76e
KH
420 sctp_bh_lock_sock(sk);
421 if (sock_owned_by_user(sk)) {
50b5d6ad
VY
422 SCTP_DEBUG_PRINTK("%s:Sock is busy.\n", __func__);
423
424 /* Try again later. */
425 if (!mod_timer(&transport->proto_unreach_timer,
426 jiffies + (HZ/20)))
427 sctp_association_hold(asoc);
428 goto out_unlock;
429 }
430
431 /* Is this structure just waiting around for us to actually
432 * get destroyed?
433 */
434 if (asoc->base.dead)
435 goto out_unlock;
436
55e26eb9 437 sctp_do_sm(net, SCTP_EVENT_T_OTHER,
50b5d6ad
VY
438 SCTP_ST_OTHER(SCTP_EVENT_ICMP_PROTO_UNREACH),
439 asoc->state, asoc->ep, asoc, transport, GFP_ATOMIC);
440
441out_unlock:
1cf7c76e 442 sctp_bh_unlock_sock(sk);
50b5d6ad
VY
443 sctp_association_put(asoc);
444}
445
446
1da177e4
LT
447/* Inject a SACK Timeout event into the state machine. */
448static void sctp_generate_sack_event(unsigned long data)
449{
450 struct sctp_association *asoc = (struct sctp_association *) data;
451 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
452}
453
454sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
455 NULL,
456 sctp_generate_t1_cookie_event,
457 sctp_generate_t1_init_event,
458 sctp_generate_t2_shutdown_event,
459 NULL,
460 sctp_generate_t4_rto_event,
461 sctp_generate_t5_shutdown_guard_event,
1e7d3d90 462 NULL,
1da177e4
LT
463 sctp_generate_sack_event,
464 sctp_generate_autoclose_event,
465};
466
467
468/* RFC 2960 8.2 Path Failure Detection
469 *
470 * When its peer endpoint is multi-homed, an endpoint should keep a
471 * error counter for each of the destination transport addresses of the
472 * peer endpoint.
473 *
474 * Each time the T3-rtx timer expires on any address, or when a
475 * HEARTBEAT sent to an idle address is not acknowledged within a RTO,
476 * the error counter of that destination address will be incremented.
477 * When the value in the error counter exceeds the protocol parameter
478 * 'Path.Max.Retrans' of that destination address, the endpoint should
479 * mark the destination transport address as inactive, and a
480 * notification SHOULD be sent to the upper layer.
481 *
482 */
5aa93bcf
NH
483static void sctp_do_8_2_transport_strike(sctp_cmd_seq_t *commands,
484 struct sctp_association *asoc,
7e99013a
VY
485 struct sctp_transport *transport,
486 int is_hb)
1da177e4
LT
487{
488 /* The check for association's overall error counter exceeding the
489 * threshold is done in the state function.
490 */
b9f84786
VY
491 /* We are here due to a timer expiration. If the timer was
492 * not a HEARTBEAT, then normal error tracking is done.
493 * If the timer was a heartbeat, we only increment error counts
494 * when we already have an outstanding HEARTBEAT that has not
495 * been acknowledged.
25985edc 496 * Additionally, some tranport states inhibit error increments.
ad8fec17 497 */
b9f84786 498 if (!is_hb) {
ad8fec17 499 asoc->overall_error_count++;
b9f84786
VY
500 if (transport->state != SCTP_INACTIVE)
501 transport->error_count++;
502 } else if (transport->hb_sent) {
503 if (transport->state != SCTP_UNCONFIRMED)
504 asoc->overall_error_count++;
505 if (transport->state != SCTP_INACTIVE)
506 transport->error_count++;
507 }
1da177e4 508
5aa93bcf
NH
509 /* If the transport error count is greater than the pf_retrans
510 * threshold, and less than pathmaxrtx, then mark this transport
511 * as Partially Failed, ee SCTP Quick Failover Draft, secon 5.1,
512 * point 1
513 */
514 if ((transport->state != SCTP_PF) &&
515 (asoc->pf_retrans < transport->pathmaxrxt) &&
516 (transport->error_count > asoc->pf_retrans)) {
517
518 sctp_assoc_control_transport(asoc, transport,
519 SCTP_TRANSPORT_PF,
520 0);
521
522 /* Update the hb timer to resend a heartbeat every rto */
523 sctp_cmd_hb_timer_update(commands, transport);
524 }
525
3f7a87d2 526 if (transport->state != SCTP_INACTIVE &&
b9f84786 527 (transport->error_count > transport->pathmaxrxt)) {
3f7a87d2
FF
528 SCTP_DEBUG_PRINTK_IPADDR("transport_strike:association %p",
529 " transport IP: port:%d failed.\n",
530 asoc,
b3f5b3b6
AV
531 (&transport->ipaddr),
532 ntohs(transport->ipaddr.v4.sin_port));
1da177e4
LT
533 sctp_assoc_control_transport(asoc, transport,
534 SCTP_TRANSPORT_DOWN,
535 SCTP_FAILED_THRESHOLD);
536 }
537
538 /* E2) For the destination address for which the timer
539 * expires, set RTO <- RTO * 2 ("back off the timer"). The
540 * maximum value discussed in rule C7 above (RTO.max) may be
541 * used to provide an upper bound to this doubling operation.
faee47cd
VY
542 *
543 * Special Case: the first HB doesn't trigger exponential backoff.
3ad2f3fb 544 * The first unacknowledged HB triggers it. We do this with a flag
faee47cd 545 * that indicates that we have an outstanding HB.
1da177e4 546 */
7e99013a 547 if (!is_hb || transport->hb_sent) {
faee47cd 548 transport->rto = min((transport->rto * 2), transport->asoc->rto_max);
196d6759 549 sctp_max_rto(asoc, transport);
faee47cd 550 }
1da177e4
LT
551}
552
553/* Worker routine to handle INIT command failure. */
554static void sctp_cmd_init_failed(sctp_cmd_seq_t *commands,
555 struct sctp_association *asoc,
95c96174 556 unsigned int error)
1da177e4
LT
557{
558 struct sctp_ulpevent *event;
559
560 event = sctp_ulpevent_make_assoc_change(asoc,0, SCTP_CANT_STR_ASSOC,
a5a35e76 561 (__u16)error, 0, 0, NULL,
1da177e4
LT
562 GFP_ATOMIC);
563
564 if (event)
565 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
566 SCTP_ULPEVENT(event));
567
568 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
569 SCTP_STATE(SCTP_STATE_CLOSED));
570
571 /* SEND_FAILED sent later when cleaning up the association. */
572 asoc->outqueue.error = error;
573 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
574}
575
576/* Worker routine to handle SCTP_CMD_ASSOC_FAILED. */
577static void sctp_cmd_assoc_failed(sctp_cmd_seq_t *commands,
578 struct sctp_association *asoc,
579 sctp_event_t event_type,
580 sctp_subtype_t subtype,
581 struct sctp_chunk *chunk,
95c96174 582 unsigned int error)
1da177e4
LT
583{
584 struct sctp_ulpevent *event;
de4594a5 585 struct sctp_chunk *abort;
1da177e4
LT
586 /* Cancel any partial delivery in progress. */
587 sctp_ulpq_abort_pd(&asoc->ulpq, GFP_ATOMIC);
588
a5a35e76
VY
589 if (event_type == SCTP_EVENT_T_CHUNK && subtype.chunk == SCTP_CID_ABORT)
590 event = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_LOST,
591 (__u16)error, 0, 0, chunk,
592 GFP_ATOMIC);
593 else
594 event = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_LOST,
595 (__u16)error, 0, 0, NULL,
1da177e4
LT
596 GFP_ATOMIC);
597 if (event)
598 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
599 SCTP_ULPEVENT(event));
600
de4594a5
NH
601 if (asoc->overall_error_count >= asoc->max_retrans) {
602 abort = sctp_make_violation_max_retrans(asoc, chunk);
603 if (abort)
604 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
605 SCTP_CHUNK(abort));
606 }
607
1da177e4
LT
608 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
609 SCTP_STATE(SCTP_STATE_CLOSED));
610
1da177e4
LT
611 /* SEND_FAILED sent later when cleaning up the association. */
612 asoc->outqueue.error = error;
613 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
614}
615
616/* Process an init chunk (may be real INIT/INIT-ACK or an embedded INIT
617 * inside the cookie. In reality, this is only used for INIT-ACK processing
618 * since all other cases use "temporary" associations and can do all
619 * their work in statefuns directly.
620 */
621static int sctp_cmd_process_init(sctp_cmd_seq_t *commands,
622 struct sctp_association *asoc,
623 struct sctp_chunk *chunk,
3182cd84 624 sctp_init_chunk_t *peer_init,
dd0fc66f 625 gfp_t gfp)
1da177e4
LT
626{
627 int error;
628
629 /* We only process the init as a sideeffect in a single
630 * case. This is when we process the INIT-ACK. If we
631 * fail during INIT processing (due to malloc problems),
632 * just return the error and stop processing the stack.
633 */
de6becdc 634 if (!sctp_process_init(asoc, chunk, sctp_source(chunk), peer_init, gfp))
1da177e4
LT
635 error = -ENOMEM;
636 else
637 error = 0;
638
639 return error;
640}
641
642/* Helper function to break out starting up of heartbeat timers. */
643static void sctp_cmd_hb_timers_start(sctp_cmd_seq_t *cmds,
644 struct sctp_association *asoc)
645{
646 struct sctp_transport *t;
1da177e4
LT
647
648 /* Start a heartbeat timer for each transport on the association.
649 * hold a reference on the transport to make sure none of
650 * the needed data structures go away.
651 */
9dbc15f0 652 list_for_each_entry(t, &asoc->peer.transport_addr_list, transports) {
1da177e4
LT
653
654 if (!mod_timer(&t->hb_timer, sctp_transport_timeout(t)))
655 sctp_transport_hold(t);
656 }
657}
658
659static void sctp_cmd_hb_timers_stop(sctp_cmd_seq_t *cmds,
660 struct sctp_association *asoc)
661{
662 struct sctp_transport *t;
1da177e4
LT
663
664 /* Stop all heartbeat timers. */
665
9dbc15f0
RD
666 list_for_each_entry(t, &asoc->peer.transport_addr_list,
667 transports) {
1da177e4
LT
668 if (del_timer(&t->hb_timer))
669 sctp_transport_put(t);
670 }
671}
672
673/* Helper function to stop any pending T3-RTX timers */
674static void sctp_cmd_t3_rtx_timers_stop(sctp_cmd_seq_t *cmds,
d808ad9a 675 struct sctp_association *asoc)
1da177e4
LT
676{
677 struct sctp_transport *t;
1da177e4 678
9dbc15f0
RD
679 list_for_each_entry(t, &asoc->peer.transport_addr_list,
680 transports) {
25cc4ae9 681 if (del_timer(&t->T3_rtx_timer))
1da177e4 682 sctp_transport_put(t);
1da177e4
LT
683 }
684}
685
686
687/* Helper function to update the heartbeat timer. */
688static void sctp_cmd_hb_timer_update(sctp_cmd_seq_t *cmds,
1da177e4
LT
689 struct sctp_transport *t)
690{
691 /* Update the heartbeat timer. */
692 if (!mod_timer(&t->hb_timer, sctp_transport_timeout(t)))
693 sctp_transport_hold(t);
694}
695
696/* Helper function to handle the reception of an HEARTBEAT ACK. */
697static void sctp_cmd_transport_on(sctp_cmd_seq_t *cmds,
698 struct sctp_association *asoc,
699 struct sctp_transport *t,
700 struct sctp_chunk *chunk)
701{
702 sctp_sender_hb_info_t *hbinfo;
34d2d89f 703 int was_unconfirmed = 0;
1da177e4
LT
704
705 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of the
706 * HEARTBEAT should clear the error counter of the destination
707 * transport address to which the HEARTBEAT was sent.
1da177e4
LT
708 */
709 t->error_count = 0;
f8d96052
TG
710
711 /*
712 * Although RFC4960 specifies that the overall error count must
713 * be cleared when a HEARTBEAT ACK is received, we make an
714 * exception while in SHUTDOWN PENDING. If the peer keeps its
715 * window shut forever, we may never be able to transmit our
716 * outstanding data and rely on the retransmission limit be reached
717 * to shutdown the association.
718 */
719 if (t->asoc->state != SCTP_STATE_SHUTDOWN_PENDING)
720 t->asoc->overall_error_count = 0;
1da177e4 721
faee47cd
VY
722 /* Clear the hb_sent flag to signal that we had a good
723 * acknowledgement.
724 */
725 t->hb_sent = 0;
726
1da177e4
LT
727 /* Mark the destination transport address as active if it is not so
728 * marked.
729 */
34d2d89f
MH
730 if ((t->state == SCTP_INACTIVE) || (t->state == SCTP_UNCONFIRMED)) {
731 was_unconfirmed = 1;
1da177e4
LT
732 sctp_assoc_control_transport(asoc, t, SCTP_TRANSPORT_UP,
733 SCTP_HEARTBEAT_SUCCESS);
34d2d89f 734 }
1da177e4 735
5aa93bcf
NH
736 if (t->state == SCTP_PF)
737 sctp_assoc_control_transport(asoc, t, SCTP_TRANSPORT_UP,
738 SCTP_HEARTBEAT_SUCCESS);
739
1da177e4
LT
740 /* The receiver of the HEARTBEAT ACK should also perform an
741 * RTT measurement for that destination transport address
742 * using the time value carried in the HEARTBEAT ACK chunk.
e533ca16
VY
743 * If the transport's rto_pending variable has been cleared,
744 * it was most likely due to a retransmit. However, we want
745 * to re-enable it to properly update the rto.
1da177e4 746 */
e533ca16
VY
747 if (t->rto_pending == 0)
748 t->rto_pending = 1;
749
1da177e4
LT
750 hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data;
751 sctp_transport_update_rto(t, (jiffies - hbinfo->sent_at));
ad8fec17
SS
752
753 /* Update the heartbeat timer. */
754 if (!mod_timer(&t->hb_timer, sctp_transport_timeout(t)))
755 sctp_transport_hold(t);
34d2d89f
MH
756
757 if (was_unconfirmed && asoc->peer.transport_count == 1)
758 sctp_transport_immediate_rtx(t);
1da177e4
LT
759}
760
1da177e4
LT
761
762/* Helper function to process the process SACK command. */
763static int sctp_cmd_process_sack(sctp_cmd_seq_t *cmds,
764 struct sctp_association *asoc,
edfee033 765 struct sctp_chunk *chunk)
1da177e4 766{
2e3216cd 767 int err = 0;
1da177e4 768
edfee033 769 if (sctp_outq_sack(&asoc->outqueue, chunk)) {
55e26eb9
EB
770 struct net *net = sock_net(asoc->base.sk);
771
1da177e4 772 /* There are no more TSNs awaiting SACK. */
55e26eb9 773 err = sctp_do_sm(net, SCTP_EVENT_T_OTHER,
1da177e4
LT
774 SCTP_ST_OTHER(SCTP_EVENT_NO_PENDING_TSN),
775 asoc->state, asoc->ep, asoc, NULL,
776 GFP_ATOMIC);
1da177e4
LT
777 }
778
779 return err;
780}
781
782/* Helper function to set the timeout value for T2-SHUTDOWN timer and to set
783 * the transport for a shutdown chunk.
784 */
d808ad9a 785static void sctp_cmd_setup_t2(sctp_cmd_seq_t *cmds,
1da177e4
LT
786 struct sctp_association *asoc,
787 struct sctp_chunk *chunk)
788{
789 struct sctp_transport *t;
790
c17b02b3
VY
791 if (chunk->transport)
792 t = chunk->transport;
793 else {
794 t = sctp_assoc_choose_alter_transport(asoc,
9919b455 795 asoc->shutdown_last_sent_to);
c17b02b3
VY
796 chunk->transport = t;
797 }
1da177e4
LT
798 asoc->shutdown_last_sent_to = t;
799 asoc->timeouts[SCTP_EVENT_TIMEOUT_T2_SHUTDOWN] = t->rto;
1da177e4
LT
800}
801
802/* Helper function to change the state of an association. */
d808ad9a 803static void sctp_cmd_new_state(sctp_cmd_seq_t *cmds,
1da177e4
LT
804 struct sctp_association *asoc,
805 sctp_state_t state)
806{
807 struct sock *sk = asoc->base.sk;
808
809 asoc->state = state;
810
3f7a87d2
FF
811 SCTP_DEBUG_PRINTK("sctp_cmd_new_state: asoc %p[%s]\n",
812 asoc, sctp_state_tbl[state]);
813
1da177e4 814 if (sctp_style(sk, TCP)) {
3f7a87d2 815 /* Change the sk->sk_state of a TCP-style socket that has
af901ca1 816 * successfully completed a connect() call.
1da177e4
LT
817 */
818 if (sctp_state(asoc, ESTABLISHED) && sctp_sstate(sk, CLOSED))
819 sk->sk_state = SCTP_SS_ESTABLISHED;
820
821 /* Set the RCV_SHUTDOWN flag when a SHUTDOWN is received. */
822 if (sctp_state(asoc, SHUTDOWN_RECEIVED) &&
823 sctp_sstate(sk, ESTABLISHED))
824 sk->sk_shutdown |= RCV_SHUTDOWN;
825 }
826
3f7a87d2
FF
827 if (sctp_state(asoc, COOKIE_WAIT)) {
828 /* Reset init timeouts since they may have been
829 * increased due to timer expirations.
830 */
831 asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_INIT] =
1e7d3d90 832 asoc->rto_initial;
3f7a87d2 833 asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE] =
1e7d3d90 834 asoc->rto_initial;
3f7a87d2
FF
835 }
836
1da177e4
LT
837 if (sctp_state(asoc, ESTABLISHED) ||
838 sctp_state(asoc, CLOSED) ||
839 sctp_state(asoc, SHUTDOWN_RECEIVED)) {
840 /* Wake up any processes waiting in the asoc's wait queue in
841 * sctp_wait_for_connect() or sctp_wait_for_sndbuf().
d808ad9a 842 */
1da177e4
LT
843 if (waitqueue_active(&asoc->wait))
844 wake_up_interruptible(&asoc->wait);
845
846 /* Wake up any processes waiting in the sk's sleep queue of
847 * a TCP-style or UDP-style peeled-off socket in
848 * sctp_wait_for_accept() or sctp_wait_for_packet().
849 * For a UDP-style socket, the waiters are woken up by the
850 * notifications.
851 */
852 if (!sctp_style(sk, UDP))
853 sk->sk_state_change(sk);
854 }
855}
856
857/* Helper function to delete an association. */
858static void sctp_cmd_delete_tcb(sctp_cmd_seq_t *cmds,
859 struct sctp_association *asoc)
860{
861 struct sock *sk = asoc->base.sk;
862
863 /* If it is a non-temporary association belonging to a TCP-style
d808ad9a 864 * listening socket that is not closed, do not free it so that accept()
1da177e4 865 * can pick it up later.
d808ad9a 866 */
1da177e4
LT
867 if (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING) &&
868 (!asoc->temp) && (sk->sk_shutdown != SHUTDOWN_MASK))
869 return;
870
871 sctp_unhash_established(asoc);
872 sctp_association_free(asoc);
873}
874
875/*
876 * ADDIP Section 4.1 ASCONF Chunk Procedures
877 * A4) Start a T-4 RTO timer, using the RTO value of the selected
878 * destination address (we use active path instead of primary path just
d808ad9a 879 * because primary path may be inactive.
1da177e4
LT
880 */
881static void sctp_cmd_setup_t4(sctp_cmd_seq_t *cmds,
882 struct sctp_association *asoc,
883 struct sctp_chunk *chunk)
884{
885 struct sctp_transport *t;
886
9919b455 887 t = sctp_assoc_choose_alter_transport(asoc, chunk->transport);
1da177e4
LT
888 asoc->timeouts[SCTP_EVENT_TIMEOUT_T4_RTO] = t->rto;
889 chunk->transport = t;
890}
891
d808ad9a 892/* Process an incoming Operation Error Chunk. */
1da177e4
LT
893static void sctp_cmd_process_operr(sctp_cmd_seq_t *cmds,
894 struct sctp_association *asoc,
895 struct sctp_chunk *chunk)
896{
1da177e4 897 struct sctp_errhdr *err_hdr;
3df26787
WY
898 struct sctp_ulpevent *ev;
899
900 while (chunk->chunk_end > chunk->skb->data) {
901 err_hdr = (struct sctp_errhdr *)(chunk->skb->data);
902
903 ev = sctp_ulpevent_make_remote_error(asoc, chunk, 0,
904 GFP_ATOMIC);
905 if (!ev)
906 return;
907
908 sctp_ulpq_tail_event(&asoc->ulpq, ev);
909
910 switch (err_hdr->cause) {
911 case SCTP_ERROR_UNKNOWN_CHUNK:
912 {
913 sctp_chunkhdr_t *unk_chunk_hdr;
914
915 unk_chunk_hdr = (sctp_chunkhdr_t *)err_hdr->variable;
916 switch (unk_chunk_hdr->type) {
917 /* ADDIP 4.1 A9) If the peer responds to an ASCONF with
918 * an ERROR chunk reporting that it did not recognized
919 * the ASCONF chunk type, the sender of the ASCONF MUST
920 * NOT send any further ASCONF chunks and MUST stop its
921 * T-4 timer.
922 */
923 case SCTP_CID_ASCONF:
924 if (asoc->peer.asconf_capable == 0)
925 break;
926
927 asoc->peer.asconf_capable = 0;
928 sctp_add_cmd_sf(cmds, SCTP_CMD_TIMER_STOP,
1da177e4 929 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3df26787
WY
930 break;
931 default:
932 break;
933 }
1da177e4 934 break;
3df26787 935 }
1da177e4
LT
936 default:
937 break;
938 }
1da177e4
LT
939 }
940}
941
942/* Process variable FWDTSN chunk information. */
d808ad9a 943static void sctp_cmd_process_fwdtsn(struct sctp_ulpq *ulpq,
1da177e4
LT
944 struct sctp_chunk *chunk)
945{
946 struct sctp_fwdtsn_skip *skip;
947 /* Walk through all the skipped SSNs */
948 sctp_walk_fwdtsn(skip, chunk) {
949 sctp_ulpq_skip(ulpq, ntohs(skip->stream), ntohs(skip->ssn));
950 }
1da177e4
LT
951}
952
d808ad9a 953/* Helper function to remove the association non-primary peer
1da177e4 954 * transports.
d808ad9a 955 */
1da177e4
LT
956static void sctp_cmd_del_non_primary(struct sctp_association *asoc)
957{
958 struct sctp_transport *t;
959 struct list_head *pos;
960 struct list_head *temp;
961
962 list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
963 t = list_entry(pos, struct sctp_transport, transports);
5f242a13 964 if (!sctp_cmp_addr_exact(&t->ipaddr,
d808ad9a 965 &asoc->peer.primary_addr)) {
38a03145 966 sctp_assoc_del_peer(asoc, &t->ipaddr);
1da177e4
LT
967 }
968 }
1da177e4
LT
969}
970
8de8c873
SS
971/* Helper function to set sk_err on a 1-1 style socket. */
972static void sctp_cmd_set_sk_err(struct sctp_association *asoc, int error)
973{
974 struct sock *sk = asoc->base.sk;
975
976 if (!sctp_style(sk, UDP))
977 sk->sk_err = error;
978}
979
07d93967
VY
980/* Helper function to generate an association change event */
981static void sctp_cmd_assoc_change(sctp_cmd_seq_t *commands,
982 struct sctp_association *asoc,
983 u8 state)
984{
985 struct sctp_ulpevent *ev;
986
987 ev = sctp_ulpevent_make_assoc_change(asoc, 0, state, 0,
988 asoc->c.sinit_num_ostreams,
989 asoc->c.sinit_max_instreams,
990 NULL, GFP_ATOMIC);
991 if (ev)
992 sctp_ulpq_tail_event(&asoc->ulpq, ev);
993}
994
995/* Helper function to generate an adaptation indication event */
996static void sctp_cmd_adaptation_ind(sctp_cmd_seq_t *commands,
997 struct sctp_association *asoc)
998{
999 struct sctp_ulpevent *ev;
1000
1001 ev = sctp_ulpevent_make_adaptation_indication(asoc, GFP_ATOMIC);
1002
1003 if (ev)
1004 sctp_ulpq_tail_event(&asoc->ulpq, ev);
1005}
1006
96cd0d3d
VY
1007
1008static void sctp_cmd_t1_timer_update(struct sctp_association *asoc,
1009 sctp_event_timeout_t timer,
1010 char *name)
1011{
1012 struct sctp_transport *t;
1013
1014 t = asoc->init_last_sent_to;
1015 asoc->init_err_counter++;
1016
1017 if (t->init_sent_count > (asoc->init_cycle + 1)) {
1018 asoc->timeouts[timer] *= 2;
1019 if (asoc->timeouts[timer] > asoc->max_init_timeo) {
1020 asoc->timeouts[timer] = asoc->max_init_timeo;
1021 }
1022 asoc->init_cycle++;
1023 SCTP_DEBUG_PRINTK(
1024 "T1 %s Timeout adjustment"
1025 " init_err_counter: %d"
1026 " cycle: %d"
1027 " timeout: %ld\n",
1028 name,
1029 asoc->init_err_counter,
1030 asoc->init_cycle,
1031 asoc->timeouts[timer]);
1032 }
1033
1034}
1035
9c5c62be
VY
1036/* Send the whole message, chunk by chunk, to the outqueue.
1037 * This way the whole message is queued up and bundling if
1038 * encouraged for small fragments.
1039 */
1040static int sctp_cmd_send_msg(struct sctp_association *asoc,
1041 struct sctp_datamsg *msg)
1042{
1043 struct sctp_chunk *chunk;
1044 int error = 0;
1045
1046 list_for_each_entry(chunk, &msg->chunks, frag_list) {
1047 error = sctp_outq_tail(&asoc->outqueue, chunk);
1048 if (error)
1049 break;
1050 }
1051
1052 return error;
1053}
1054
1055
c0786693
VY
1056/* Sent the next ASCONF packet currently stored in the association.
1057 * This happens after the ASCONF_ACK was succeffully processed.
1058 */
1059static void sctp_cmd_send_asconf(struct sctp_association *asoc)
1060{
55e26eb9
EB
1061 struct net *net = sock_net(asoc->base.sk);
1062
c0786693
VY
1063 /* Send the next asconf chunk from the addip chunk
1064 * queue.
1065 */
1066 if (!list_empty(&asoc->addip_chunk_list)) {
1067 struct list_head *entry = asoc->addip_chunk_list.next;
1068 struct sctp_chunk *asconf = list_entry(entry,
1069 struct sctp_chunk, list);
1070 list_del_init(entry);
1071
1072 /* Hold the chunk until an ASCONF_ACK is received. */
1073 sctp_chunk_hold(asconf);
55e26eb9 1074 if (sctp_primitive_ASCONF(net, asoc, asconf))
c0786693
VY
1075 sctp_chunk_free(asconf);
1076 else
1077 asoc->addip_last_asconf = asconf;
1078 }
1079}
1080
9c5c62be 1081
1da177e4
LT
1082/* These three macros allow us to pull the debugging code out of the
1083 * main flow of sctp_do_sm() to keep attention focused on the real
1084 * functionality there.
1085 */
1086#define DEBUG_PRE \
1087 SCTP_DEBUG_PRINTK("sctp_do_sm prefn: " \
1088 "ep %p, %s, %s, asoc %p[%s], %s\n", \
1089 ep, sctp_evttype_tbl[event_type], \
1090 (*debug_fn)(subtype), asoc, \
1091 sctp_state_tbl[state], state_fn->name)
1092
1093#define DEBUG_POST \
1094 SCTP_DEBUG_PRINTK("sctp_do_sm postfn: " \
1095 "asoc %p, status: %s\n", \
1096 asoc, sctp_status_tbl[status])
1097
1098#define DEBUG_POST_SFX \
1099 SCTP_DEBUG_PRINTK("sctp_do_sm post sfx: error %d, asoc %p[%s]\n", \
1100 error, asoc, \
1101 sctp_state_tbl[(asoc && sctp_id2assoc(ep->base.sk, \
1102 sctp_assoc2id(asoc)))?asoc->state:SCTP_STATE_CLOSED])
1103
1104/*
1105 * This is the master state machine processing function.
1106 *
1107 * If you want to understand all of lksctp, this is a
1108 * good place to start.
1109 */
55e26eb9 1110int sctp_do_sm(struct net *net, sctp_event_t event_type, sctp_subtype_t subtype,
1da177e4
LT
1111 sctp_state_t state,
1112 struct sctp_endpoint *ep,
1113 struct sctp_association *asoc,
1114 void *event_arg,
dd0fc66f 1115 gfp_t gfp)
1da177e4
LT
1116{
1117 sctp_cmd_seq_t commands;
1118 const sctp_sm_table_entry_t *state_fn;
1119 sctp_disposition_t status;
1120 int error = 0;
1121 typedef const char *(printfn_t)(sctp_subtype_t);
1122
1123 static printfn_t *table[] = {
1124 NULL, sctp_cname, sctp_tname, sctp_oname, sctp_pname,
1125 };
1126 printfn_t *debug_fn __attribute__ ((unused)) = table[event_type];
1127
1128 /* Look up the state function, run it, and then process the
1129 * side effects. These three steps are the heart of lksctp.
1130 */
55e26eb9 1131 state_fn = sctp_sm_lookup_event(net, event_type, state, subtype);
1da177e4
LT
1132
1133 sctp_init_cmd_seq(&commands);
1134
1135 DEBUG_PRE;
24cb81a6 1136 status = (*state_fn->fn)(net, ep, asoc, subtype, event_arg, &commands);
1da177e4
LT
1137 DEBUG_POST;
1138
1139 error = sctp_side_effects(event_type, subtype, state,
d808ad9a 1140 ep, asoc, event_arg, status,
1da177e4
LT
1141 &commands, gfp);
1142 DEBUG_POST_SFX;
1143
1144 return error;
1145}
1146
1147#undef DEBUG_PRE
1148#undef DEBUG_POST
1149
1150/*****************************************************************
1151 * This the master state function side effect processing function.
1152 *****************************************************************/
1153static int sctp_side_effects(sctp_event_t event_type, sctp_subtype_t subtype,
1154 sctp_state_t state,
1155 struct sctp_endpoint *ep,
1156 struct sctp_association *asoc,
1157 void *event_arg,
1158 sctp_disposition_t status,
1159 sctp_cmd_seq_t *commands,
dd0fc66f 1160 gfp_t gfp)
1da177e4
LT
1161{
1162 int error;
1163
1164 /* FIXME - Most of the dispositions left today would be categorized
1165 * as "exceptional" dispositions. For those dispositions, it
1166 * may not be proper to run through any of the commands at all.
1167 * For example, the command interpreter might be run only with
1168 * disposition SCTP_DISPOSITION_CONSUME.
1169 */
1170 if (0 != (error = sctp_cmd_interpreter(event_type, subtype, state,
1171 ep, asoc,
1172 event_arg, status,
1173 commands, gfp)))
1174 goto bail;
1175
1176 switch (status) {
1177 case SCTP_DISPOSITION_DISCARD:
1178 SCTP_DEBUG_PRINTK("Ignored sctp protocol event - state %d, "
1179 "event_type %d, event_id %d\n",
1180 state, event_type, subtype.chunk);
1181 break;
1182
1183 case SCTP_DISPOSITION_NOMEM:
1184 /* We ran out of memory, so we need to discard this
1185 * packet.
1186 */
1187 /* BUG--we should now recover some memory, probably by
1188 * reneging...
1189 */
1190 error = -ENOMEM;
1191 break;
1192
d808ad9a 1193 case SCTP_DISPOSITION_DELETE_TCB:
1da177e4
LT
1194 /* This should now be a command. */
1195 break;
1196
1197 case SCTP_DISPOSITION_CONSUME:
1198 case SCTP_DISPOSITION_ABORT:
1199 /*
1200 * We should no longer have much work to do here as the
1201 * real work has been done as explicit commands above.
1202 */
1203 break;
1204
1205 case SCTP_DISPOSITION_VIOLATION:
e87cc472
JP
1206 net_err_ratelimited("protocol violation state %d chunkid %d\n",
1207 state, subtype.chunk);
1da177e4
LT
1208 break;
1209
1210 case SCTP_DISPOSITION_NOT_IMPL:
145ce502
JP
1211 pr_warn("unimplemented feature in state %d, event_type %d, event_id %d\n",
1212 state, event_type, subtype.chunk);
1da177e4
LT
1213 break;
1214
1215 case SCTP_DISPOSITION_BUG:
145ce502 1216 pr_err("bug in state %d, event_type %d, event_id %d\n",
1da177e4
LT
1217 state, event_type, subtype.chunk);
1218 BUG();
1219 break;
1220
1221 default:
145ce502 1222 pr_err("impossible disposition %d in state %d, event_type %d, event_id %d\n",
1da177e4
LT
1223 status, state, event_type, subtype.chunk);
1224 BUG();
1225 break;
3ff50b79 1226 }
1da177e4
LT
1227
1228bail:
1229 return error;
1230}
1231
1232/********************************************************************
1233 * 2nd Level Abstractions
1234 ********************************************************************/
1235
1236/* This is the side-effect interpreter. */
1237static int sctp_cmd_interpreter(sctp_event_t event_type,
1238 sctp_subtype_t subtype,
1239 sctp_state_t state,
1240 struct sctp_endpoint *ep,
1241 struct sctp_association *asoc,
1242 void *event_arg,
d808ad9a 1243 sctp_disposition_t status,
1da177e4 1244 sctp_cmd_seq_t *commands,
dd0fc66f 1245 gfp_t gfp)
1da177e4
LT
1246{
1247 int error = 0;
1248 int force;
1249 sctp_cmd_t *cmd;
1250 struct sctp_chunk *new_obj;
1251 struct sctp_chunk *chunk = NULL;
1252 struct sctp_packet *packet;
1da177e4
LT
1253 struct timer_list *timer;
1254 unsigned long timeout;
1255 struct sctp_transport *t;
1256 struct sctp_sackhdr sackh;
1257 int local_cork = 0;
1258
1259 if (SCTP_EVENT_T_TIMEOUT != event_type)
ea110733 1260 chunk = event_arg;
1da177e4
LT
1261
1262 /* Note: This whole file is a huge candidate for rework.
1263 * For example, each command could either have its own handler, so
1264 * the loop would look like:
1265 * while (cmds)
1266 * cmd->handle(x, y, z)
1267 * --jgrimm
1268 */
1269 while (NULL != (cmd = sctp_next_cmd(commands))) {
1270 switch (cmd->verb) {
1271 case SCTP_CMD_NOP:
1272 /* Do nothing. */
1273 break;
1274
1275 case SCTP_CMD_NEW_ASOC:
1276 /* Register a new association. */
1277 if (local_cork) {
d808ad9a 1278 sctp_outq_uncork(&asoc->outqueue);
1da177e4
LT
1279 local_cork = 0;
1280 }
b26ddd81 1281 asoc = cmd->obj.asoc;
1da177e4
LT
1282 /* Register with the endpoint. */
1283 sctp_endpoint_add_asoc(ep, asoc);
1284 sctp_hash_established(asoc);
1285 break;
1286
1287 case SCTP_CMD_UPDATE_ASSOC:
b26ddd81 1288 sctp_assoc_update(asoc, cmd->obj.asoc);
1da177e4
LT
1289 break;
1290
1291 case SCTP_CMD_PURGE_OUTQUEUE:
1292 sctp_outq_teardown(&asoc->outqueue);
1293 break;
1294
d808ad9a 1295 case SCTP_CMD_DELETE_TCB:
1da177e4
LT
1296 if (local_cork) {
1297 sctp_outq_uncork(&asoc->outqueue);
1298 local_cork = 0;
1299 }
1300 /* Delete the current association. */
1301 sctp_cmd_delete_tcb(commands, asoc);
1302 asoc = NULL;
1303 break;
1304
1305 case SCTP_CMD_NEW_STATE:
1306 /* Enter a new state. */
1307 sctp_cmd_new_state(commands, asoc, cmd->obj.state);
1308 break;
1309
1310 case SCTP_CMD_REPORT_TSN:
1311 /* Record the arrival of a TSN. */
8e1ee18c 1312 error = sctp_tsnmap_mark(&asoc->peer.tsn_map,
4244854d 1313 cmd->obj.u32, NULL);
1da177e4
LT
1314 break;
1315
1316 case SCTP_CMD_REPORT_FWDTSN:
1317 /* Move the Cumulattive TSN Ack ahead. */
1318 sctp_tsnmap_skip(&asoc->peer.tsn_map, cmd->obj.u32);
1319
ea2dfb37
VY
1320 /* purge the fragmentation queue */
1321 sctp_ulpq_reasm_flushtsn(&asoc->ulpq, cmd->obj.u32);
1322
1da177e4
LT
1323 /* Abort any in progress partial delivery. */
1324 sctp_ulpq_abort_pd(&asoc->ulpq, GFP_ATOMIC);
1325 break;
1326
1327 case SCTP_CMD_PROCESS_FWDTSN:
b26ddd81 1328 sctp_cmd_process_fwdtsn(&asoc->ulpq, cmd->obj.chunk);
d808ad9a 1329 break;
1da177e4
LT
1330
1331 case SCTP_CMD_GEN_SACK:
1332 /* Generate a Selective ACK.
1333 * The argument tells us whether to just count
1334 * the packet and MAYBE generate a SACK, or
1335 * force a SACK out.
1336 */
1337 force = cmd->obj.i32;
1338 error = sctp_gen_sack(asoc, force, commands);
1339 break;
1340
1341 case SCTP_CMD_PROCESS_SACK:
1342 /* Process an inbound SACK. */
1343 error = sctp_cmd_process_sack(commands, asoc,
b26ddd81 1344 cmd->obj.chunk);
1da177e4
LT
1345 break;
1346
1347 case SCTP_CMD_GEN_INIT_ACK:
1348 /* Generate an INIT ACK chunk. */
1349 new_obj = sctp_make_init_ack(asoc, chunk, GFP_ATOMIC,
1350 0);
1351 if (!new_obj)
1352 goto nomem;
1353
1354 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1355 SCTP_CHUNK(new_obj));
1356 break;
1357
1358 case SCTP_CMD_PEER_INIT:
1359 /* Process a unified INIT from the peer.
1360 * Note: Only used during INIT-ACK processing. If
1361 * there is an error just return to the outter
1362 * layer which will bail.
1363 */
1364 error = sctp_cmd_process_init(commands, asoc, chunk,
b26ddd81 1365 cmd->obj.init, gfp);
1da177e4
LT
1366 break;
1367
1368 case SCTP_CMD_GEN_COOKIE_ECHO:
1369 /* Generate a COOKIE ECHO chunk. */
1370 new_obj = sctp_make_cookie_echo(asoc, chunk);
1371 if (!new_obj) {
b26ddd81
NH
1372 if (cmd->obj.chunk)
1373 sctp_chunk_free(cmd->obj.chunk);
1da177e4
LT
1374 goto nomem;
1375 }
1376 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1377 SCTP_CHUNK(new_obj));
1378
1379 /* If there is an ERROR chunk to be sent along with
1380 * the COOKIE_ECHO, send it, too.
1381 */
b26ddd81 1382 if (cmd->obj.chunk)
1da177e4 1383 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
b26ddd81 1384 SCTP_CHUNK(cmd->obj.chunk));
1da177e4 1385
96cd0d3d
VY
1386 if (new_obj->transport) {
1387 new_obj->transport->init_sent_count++;
1388 asoc->init_last_sent_to = new_obj->transport;
1389 }
1390
1da177e4 1391 /* FIXME - Eventually come up with a cleaner way to
d808ad9a
YH
1392 * enabling COOKIE-ECHO + DATA bundling during
1393 * multihoming stale cookie scenarios, the following
1394 * command plays with asoc->peer.retran_path to
1395 * avoid the problem of sending the COOKIE-ECHO and
1396 * DATA in different paths, which could result
1397 * in the association being ABORTed if the DATA chunk
1da177e4
LT
1398 * is processed first by the server. Checking the
1399 * init error counter simply causes this command
1400 * to be executed only during failed attempts of
1401 * association establishment.
1402 */
3f7a87d2
FF
1403 if ((asoc->peer.retran_path !=
1404 asoc->peer.primary_path) &&
1405 (asoc->init_err_counter > 0)) {
1406 sctp_add_cmd_sf(commands,
d808ad9a 1407 SCTP_CMD_FORCE_PRIM_RETRAN,
1da177e4
LT
1408 SCTP_NULL());
1409 }
1410
1411 break;
1412
1413 case SCTP_CMD_GEN_SHUTDOWN:
1414 /* Generate SHUTDOWN when in SHUTDOWN_SENT state.
1415 * Reset error counts.
1416 */
1417 asoc->overall_error_count = 0;
1418
1419 /* Generate a SHUTDOWN chunk. */
1420 new_obj = sctp_make_shutdown(asoc, chunk);
1421 if (!new_obj)
1422 goto nomem;
1423 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1424 SCTP_CHUNK(new_obj));
1425 break;
1426
1427 case SCTP_CMD_CHUNK_ULP:
1428 /* Send a chunk to the sockets layer. */
1429 SCTP_DEBUG_PRINTK("sm_sideff: %s %p, %s %p.\n",
b26ddd81 1430 "chunk_up:", cmd->obj.chunk,
1da177e4 1431 "ulpq:", &asoc->ulpq);
b26ddd81 1432 sctp_ulpq_tail_data(&asoc->ulpq, cmd->obj.chunk,
1da177e4
LT
1433 GFP_ATOMIC);
1434 break;
1435
1436 case SCTP_CMD_EVENT_ULP:
1437 /* Send a notification to the sockets layer. */
1438 SCTP_DEBUG_PRINTK("sm_sideff: %s %p, %s %p.\n",
b26ddd81 1439 "event_up:",cmd->obj.ulpevent,
1da177e4 1440 "ulpq:",&asoc->ulpq);
b26ddd81 1441 sctp_ulpq_tail_event(&asoc->ulpq, cmd->obj.ulpevent);
1da177e4
LT
1442 break;
1443
1444 case SCTP_CMD_REPLY:
1445 /* If an caller has not already corked, do cork. */
1446 if (!asoc->outqueue.cork) {
1447 sctp_outq_cork(&asoc->outqueue);
1448 local_cork = 1;
1449 }
1450 /* Send a chunk to our peer. */
b26ddd81 1451 error = sctp_outq_tail(&asoc->outqueue, cmd->obj.chunk);
1da177e4
LT
1452 break;
1453
1454 case SCTP_CMD_SEND_PKT:
1455 /* Send a full packet to our peer. */
b26ddd81 1456 packet = cmd->obj.packet;
1da177e4
LT
1457 sctp_packet_transmit(packet);
1458 sctp_ootb_pkt_free(packet);
1459 break;
1460
b6157d8e
VY
1461 case SCTP_CMD_T1_RETRAN:
1462 /* Mark a transport for retransmission. */
1463 sctp_retransmit(&asoc->outqueue, cmd->obj.transport,
1464 SCTP_RTXR_T1_RTX);
1465 break;
1466
1da177e4
LT
1467 case SCTP_CMD_RETRAN:
1468 /* Mark a transport for retransmission. */
1469 sctp_retransmit(&asoc->outqueue, cmd->obj.transport,
1470 SCTP_RTXR_T3_RTX);
1471 break;
1472
1da177e4
LT
1473 case SCTP_CMD_ECN_CE:
1474 /* Do delayed CE processing. */
1475 sctp_do_ecn_ce_work(asoc, cmd->obj.u32);
1476 break;
1477
1478 case SCTP_CMD_ECN_ECNE:
1479 /* Do delayed ECNE processing. */
1480 new_obj = sctp_do_ecn_ecne_work(asoc, cmd->obj.u32,
1481 chunk);
1482 if (new_obj)
1483 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1484 SCTP_CHUNK(new_obj));
1485 break;
1486
1487 case SCTP_CMD_ECN_CWR:
1488 /* Do delayed CWR processing. */
1489 sctp_do_ecn_cwr_work(asoc, cmd->obj.u32);
1490 break;
1491
1492 case SCTP_CMD_SETUP_T2:
b26ddd81 1493 sctp_cmd_setup_t2(commands, asoc, cmd->obj.chunk);
1da177e4
LT
1494 break;
1495
f8d96052
TG
1496 case SCTP_CMD_TIMER_START_ONCE:
1497 timer = &asoc->timers[cmd->obj.to];
1498
1499 if (timer_pending(timer))
1500 break;
1501 /* fall through */
1502
1da177e4
LT
1503 case SCTP_CMD_TIMER_START:
1504 timer = &asoc->timers[cmd->obj.to];
1505 timeout = asoc->timeouts[cmd->obj.to];
09a62660 1506 BUG_ON(!timeout);
1da177e4
LT
1507
1508 timer->expires = jiffies + timeout;
1509 sctp_association_hold(asoc);
1510 add_timer(timer);
1511 break;
1512
1513 case SCTP_CMD_TIMER_RESTART:
1514 timer = &asoc->timers[cmd->obj.to];
1515 timeout = asoc->timeouts[cmd->obj.to];
1516 if (!mod_timer(timer, jiffies + timeout))
1517 sctp_association_hold(asoc);
1518 break;
1519
1520 case SCTP_CMD_TIMER_STOP:
1521 timer = &asoc->timers[cmd->obj.to];
25cc4ae9 1522 if (del_timer(timer))
1da177e4
LT
1523 sctp_association_put(asoc);
1524 break;
1525
3f7a87d2 1526 case SCTP_CMD_INIT_CHOOSE_TRANSPORT:
b26ddd81 1527 chunk = cmd->obj.chunk;
9919b455
WY
1528 t = sctp_assoc_choose_alter_transport(asoc,
1529 asoc->init_last_sent_to);
3f7a87d2
FF
1530 asoc->init_last_sent_to = t;
1531 chunk->transport = t;
1532 t->init_sent_count++;
e0e9db17
VY
1533 /* Set the new transport as primary */
1534 sctp_assoc_set_primary(asoc, t);
3f7a87d2
FF
1535 break;
1536
1da177e4
LT
1537 case SCTP_CMD_INIT_RESTART:
1538 /* Do the needed accounting and updates
1539 * associated with restarting an initialization
3f7a87d2
FF
1540 * timer. Only multiply the timeout by two if
1541 * all transports have been tried at the current
1542 * timeout.
1543 */
96cd0d3d
VY
1544 sctp_cmd_t1_timer_update(asoc,
1545 SCTP_EVENT_TIMEOUT_T1_INIT,
1546 "INIT");
3f7a87d2
FF
1547
1548 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
1549 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
1550 break;
1551
1552 case SCTP_CMD_COOKIEECHO_RESTART:
1553 /* Do the needed accounting and updates
1554 * associated with restarting an initialization
1555 * timer. Only multiply the timeout by two if
1556 * all transports have been tried at the current
1557 * timeout.
1da177e4 1558 */
96cd0d3d
VY
1559 sctp_cmd_t1_timer_update(asoc,
1560 SCTP_EVENT_TIMEOUT_T1_COOKIE,
1561 "COOKIE");
1da177e4
LT
1562
1563 /* If we've sent any data bundled with
1564 * COOKIE-ECHO we need to resend.
1565 */
9dbc15f0
RD
1566 list_for_each_entry(t, &asoc->peer.transport_addr_list,
1567 transports) {
b6157d8e
VY
1568 sctp_retransmit_mark(&asoc->outqueue, t,
1569 SCTP_RTXR_T1_RTX);
1da177e4
LT
1570 }
1571
1572 sctp_add_cmd_sf(commands,
1573 SCTP_CMD_TIMER_RESTART,
3f7a87d2 1574 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
1da177e4
LT
1575 break;
1576
1577 case SCTP_CMD_INIT_FAILED:
dc251b2b 1578 sctp_cmd_init_failed(commands, asoc, cmd->obj.err);
1da177e4
LT
1579 break;
1580
1581 case SCTP_CMD_ASSOC_FAILED:
1582 sctp_cmd_assoc_failed(commands, asoc, event_type,
5be291fe 1583 subtype, chunk, cmd->obj.err);
1da177e4
LT
1584 break;
1585
3f7a87d2
FF
1586 case SCTP_CMD_INIT_COUNTER_INC:
1587 asoc->init_err_counter++;
1da177e4
LT
1588 break;
1589
3f7a87d2
FF
1590 case SCTP_CMD_INIT_COUNTER_RESET:
1591 asoc->init_err_counter = 0;
1592 asoc->init_cycle = 0;
96cd0d3d
VY
1593 list_for_each_entry(t, &asoc->peer.transport_addr_list,
1594 transports) {
1595 t->init_sent_count = 0;
1596 }
1da177e4
LT
1597 break;
1598
1599 case SCTP_CMD_REPORT_DUP:
1600 sctp_tsnmap_mark_dup(&asoc->peer.tsn_map,
1601 cmd->obj.u32);
1602 break;
1603
1604 case SCTP_CMD_REPORT_BAD_TAG:
1605 SCTP_DEBUG_PRINTK("vtag mismatch!\n");
1606 break;
1607
1608 case SCTP_CMD_STRIKE:
1609 /* Mark one strike against a transport. */
5aa93bcf
NH
1610 sctp_do_8_2_transport_strike(commands, asoc,
1611 cmd->obj.transport, 0);
7e99013a
VY
1612 break;
1613
1614 case SCTP_CMD_TRANSPORT_IDLE:
1615 t = cmd->obj.transport;
1616 sctp_transport_lower_cwnd(t, SCTP_LOWER_CWND_INACTIVE);
1da177e4
LT
1617 break;
1618
7e99013a 1619 case SCTP_CMD_TRANSPORT_HB_SENT:
1da177e4 1620 t = cmd->obj.transport;
5aa93bcf
NH
1621 sctp_do_8_2_transport_strike(commands, asoc,
1622 t, 1);
7e99013a 1623 t->hb_sent = 1;
1da177e4
LT
1624 break;
1625
1626 case SCTP_CMD_TRANSPORT_ON:
1627 t = cmd->obj.transport;
1628 sctp_cmd_transport_on(commands, asoc, t, chunk);
1629 break;
1630
1631 case SCTP_CMD_HB_TIMERS_START:
1632 sctp_cmd_hb_timers_start(commands, asoc);
1633 break;
1634
1635 case SCTP_CMD_HB_TIMER_UPDATE:
1636 t = cmd->obj.transport;
765ff02e 1637 sctp_cmd_hb_timer_update(commands, t);
1da177e4
LT
1638 break;
1639
1640 case SCTP_CMD_HB_TIMERS_STOP:
1641 sctp_cmd_hb_timers_stop(commands, asoc);
1642 break;
1643
1644 case SCTP_CMD_REPORT_ERROR:
1645 error = cmd->obj.error;
1646 break;
1647
1648 case SCTP_CMD_PROCESS_CTSN:
1649 /* Dummy up a SACK for processing. */
2178eda8 1650 sackh.cum_tsn_ack = cmd->obj.be32;
d4d6fb57
VY
1651 sackh.a_rwnd = asoc->peer.rwnd +
1652 asoc->outqueue.outstanding_bytes;
1da177e4
LT
1653 sackh.num_gap_ack_blocks = 0;
1654 sackh.num_dup_tsns = 0;
f6e80abe 1655 chunk->subh.sack_hdr = &sackh;
1da177e4 1656 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK,
f6e80abe 1657 SCTP_CHUNK(chunk));
1da177e4
LT
1658 break;
1659
1660 case SCTP_CMD_DISCARD_PACKET:
2e3216cd
VY
1661 /* We need to discard the whole packet.
1662 * Uncork the queue since there might be
1663 * responses pending
1664 */
1da177e4 1665 chunk->pdiscard = 1;
2e3216cd
VY
1666 if (asoc) {
1667 sctp_outq_uncork(&asoc->outqueue);
1668 local_cork = 0;
1669 }
1da177e4
LT
1670 break;
1671
1672 case SCTP_CMD_RTO_PENDING:
1673 t = cmd->obj.transport;
1674 t->rto_pending = 1;
1675 break;
1676
1677 case SCTP_CMD_PART_DELIVER:
b26ddd81 1678 sctp_ulpq_partial_delivery(&asoc->ulpq, GFP_ATOMIC);
1da177e4
LT
1679 break;
1680
1681 case SCTP_CMD_RENEGE:
b26ddd81 1682 sctp_ulpq_renege(&asoc->ulpq, cmd->obj.chunk,
1da177e4
LT
1683 GFP_ATOMIC);
1684 break;
1685
1686 case SCTP_CMD_SETUP_T4:
b26ddd81 1687 sctp_cmd_setup_t4(commands, asoc, cmd->obj.chunk);
1da177e4
LT
1688 break;
1689
1690 case SCTP_CMD_PROCESS_OPERR:
1691 sctp_cmd_process_operr(commands, asoc, chunk);
1692 break;
1693 case SCTP_CMD_CLEAR_INIT_TAG:
1694 asoc->peer.i.init_tag = 0;
1695 break;
1696 case SCTP_CMD_DEL_NON_PRIMARY:
1697 sctp_cmd_del_non_primary(asoc);
1698 break;
1699 case SCTP_CMD_T3_RTX_TIMERS_STOP:
1700 sctp_cmd_t3_rtx_timers_stop(commands, asoc);
1701 break;
1702 case SCTP_CMD_FORCE_PRIM_RETRAN:
1703 t = asoc->peer.retran_path;
1704 asoc->peer.retran_path = asoc->peer.primary_path;
1705 error = sctp_outq_uncork(&asoc->outqueue);
1706 local_cork = 0;
1707 asoc->peer.retran_path = t;
1708 break;
8de8c873
SS
1709 case SCTP_CMD_SET_SK_ERR:
1710 sctp_cmd_set_sk_err(asoc, cmd->obj.error);
1711 break;
07d93967
VY
1712 case SCTP_CMD_ASSOC_CHANGE:
1713 sctp_cmd_assoc_change(commands, asoc,
1714 cmd->obj.u8);
1715 break;
1716 case SCTP_CMD_ADAPTATION_IND:
1717 sctp_cmd_adaptation_ind(commands, asoc);
1718 break;
1719
730fc3d0
VY
1720 case SCTP_CMD_ASSOC_SHKEY:
1721 error = sctp_auth_asoc_init_active_key(asoc,
1722 GFP_ATOMIC);
1723 break;
f4ad85ca
GJ
1724 case SCTP_CMD_UPDATE_INITTAG:
1725 asoc->peer.i.init_tag = cmd->obj.u32;
1726 break;
9c5c62be
VY
1727 case SCTP_CMD_SEND_MSG:
1728 if (!asoc->outqueue.cork) {
1729 sctp_outq_cork(&asoc->outqueue);
1730 local_cork = 1;
1731 }
1732 error = sctp_cmd_send_msg(asoc, cmd->obj.msg);
1733 break;
c0786693
VY
1734 case SCTP_CMD_SEND_NEXT_ASCONF:
1735 sctp_cmd_send_asconf(asoc);
1736 break;
a000c01e
WY
1737 case SCTP_CMD_PURGE_ASCONF_QUEUE:
1738 sctp_asconf_queue_teardown(asoc);
1739 break;
d5ccd496
MM
1740
1741 case SCTP_CMD_SET_ASOC:
1742 asoc = cmd->obj.asoc;
1743 break;
1744
1da177e4 1745 default:
b26ddd81
NH
1746 pr_warn("Impossible command: %u\n",
1747 cmd->verb);
1da177e4 1748 break;
3ff50b79
SH
1749 }
1750
1da177e4
LT
1751 if (error)
1752 break;
1753 }
1754
1755out:
2e3216cd
VY
1756 /* If this is in response to a received chunk, wait until
1757 * we are done with the packet to open the queue so that we don't
1758 * send multiple packets in response to a single request.
1759 */
1760 if (asoc && SCTP_EVENT_T_CHUNK == event_type && chunk) {
1761 if (chunk->end_of_packet || chunk->singleton)
d4d6fb57 1762 error = sctp_outq_uncork(&asoc->outqueue);
2e3216cd 1763 } else if (local_cork)
d4d6fb57 1764 error = sctp_outq_uncork(&asoc->outqueue);
1da177e4
LT
1765 return error;
1766nomem:
1767 error = -ENOMEM;
1768 goto out;
1769}
1770