sm_sideeffect.c 49 KB

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