sm_sideeffect.c 50 KB

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