sm_sideeffect.c 49 KB

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