sm_sideeffect.c 49 KB

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