sm_sideeffect.c 51 KB

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