sm_sideeffect.c 49 KB

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