sm_sideeffect.c 49 KB

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