sm_sideeffect.c 49 KB

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