ar-ack.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314
  1. /* Management of Tx window, Tx resend, ACKs and out-of-sequence reception
  2. *
  3. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/circ_buf.h>
  13. #include <linux/net.h>
  14. #include <linux/skbuff.h>
  15. #include <linux/slab.h>
  16. #include <linux/udp.h>
  17. #include <net/sock.h>
  18. #include <net/af_rxrpc.h>
  19. #include "ar-internal.h"
  20. static unsigned int rxrpc_ack_defer = 1;
  21. static const char *rxrpc_acks(u8 reason)
  22. {
  23. static const char *const str[] = {
  24. "---", "REQ", "DUP", "OOS", "WIN", "MEM", "PNG", "PNR", "DLY",
  25. "IDL", "-?-"
  26. };
  27. if (reason >= ARRAY_SIZE(str))
  28. reason = ARRAY_SIZE(str) - 1;
  29. return str[reason];
  30. }
  31. static const s8 rxrpc_ack_priority[] = {
  32. [0] = 0,
  33. [RXRPC_ACK_DELAY] = 1,
  34. [RXRPC_ACK_REQUESTED] = 2,
  35. [RXRPC_ACK_IDLE] = 3,
  36. [RXRPC_ACK_PING_RESPONSE] = 4,
  37. [RXRPC_ACK_DUPLICATE] = 5,
  38. [RXRPC_ACK_OUT_OF_SEQUENCE] = 6,
  39. [RXRPC_ACK_EXCEEDS_WINDOW] = 7,
  40. [RXRPC_ACK_NOSPACE] = 8,
  41. };
  42. /*
  43. * propose an ACK be sent
  44. */
  45. void __rxrpc_propose_ACK(struct rxrpc_call *call, u8 ack_reason,
  46. __be32 serial, bool immediate)
  47. {
  48. unsigned long expiry;
  49. s8 prior = rxrpc_ack_priority[ack_reason];
  50. ASSERTCMP(prior, >, 0);
  51. _enter("{%d},%s,%%%x,%u",
  52. call->debug_id, rxrpc_acks(ack_reason), ntohl(serial),
  53. immediate);
  54. if (prior < rxrpc_ack_priority[call->ackr_reason]) {
  55. if (immediate)
  56. goto cancel_timer;
  57. return;
  58. }
  59. /* update DELAY, IDLE, REQUESTED and PING_RESPONSE ACK serial
  60. * numbers */
  61. if (prior == rxrpc_ack_priority[call->ackr_reason]) {
  62. if (prior <= 4)
  63. call->ackr_serial = serial;
  64. if (immediate)
  65. goto cancel_timer;
  66. return;
  67. }
  68. call->ackr_reason = ack_reason;
  69. call->ackr_serial = serial;
  70. switch (ack_reason) {
  71. case RXRPC_ACK_DELAY:
  72. _debug("run delay timer");
  73. call->ack_timer.expires = jiffies + rxrpc_ack_timeout * HZ;
  74. add_timer(&call->ack_timer);
  75. return;
  76. case RXRPC_ACK_IDLE:
  77. if (!immediate) {
  78. _debug("run defer timer");
  79. expiry = 1;
  80. goto run_timer;
  81. }
  82. goto cancel_timer;
  83. case RXRPC_ACK_REQUESTED:
  84. if (!rxrpc_ack_defer)
  85. goto cancel_timer;
  86. if (!immediate || serial == cpu_to_be32(1)) {
  87. _debug("run defer timer");
  88. expiry = rxrpc_ack_defer;
  89. goto run_timer;
  90. }
  91. default:
  92. _debug("immediate ACK");
  93. goto cancel_timer;
  94. }
  95. run_timer:
  96. expiry += jiffies;
  97. if (!timer_pending(&call->ack_timer) ||
  98. time_after(call->ack_timer.expires, expiry))
  99. mod_timer(&call->ack_timer, expiry);
  100. return;
  101. cancel_timer:
  102. _debug("cancel timer %%%u", ntohl(serial));
  103. try_to_del_timer_sync(&call->ack_timer);
  104. read_lock_bh(&call->state_lock);
  105. if (call->state <= RXRPC_CALL_COMPLETE &&
  106. !test_and_set_bit(RXRPC_CALL_ACK, &call->events))
  107. rxrpc_queue_call(call);
  108. read_unlock_bh(&call->state_lock);
  109. }
  110. /*
  111. * propose an ACK be sent, locking the call structure
  112. */
  113. void rxrpc_propose_ACK(struct rxrpc_call *call, u8 ack_reason,
  114. __be32 serial, bool immediate)
  115. {
  116. s8 prior = rxrpc_ack_priority[ack_reason];
  117. if (prior > rxrpc_ack_priority[call->ackr_reason]) {
  118. spin_lock_bh(&call->lock);
  119. __rxrpc_propose_ACK(call, ack_reason, serial, immediate);
  120. spin_unlock_bh(&call->lock);
  121. }
  122. }
  123. /*
  124. * set the resend timer
  125. */
  126. static void rxrpc_set_resend(struct rxrpc_call *call, u8 resend,
  127. unsigned long resend_at)
  128. {
  129. read_lock_bh(&call->state_lock);
  130. if (call->state >= RXRPC_CALL_COMPLETE)
  131. resend = 0;
  132. if (resend & 1) {
  133. _debug("SET RESEND");
  134. set_bit(RXRPC_CALL_RESEND, &call->events);
  135. }
  136. if (resend & 2) {
  137. _debug("MODIFY RESEND TIMER");
  138. set_bit(RXRPC_CALL_RUN_RTIMER, &call->flags);
  139. mod_timer(&call->resend_timer, resend_at);
  140. } else {
  141. _debug("KILL RESEND TIMER");
  142. del_timer_sync(&call->resend_timer);
  143. clear_bit(RXRPC_CALL_RESEND_TIMER, &call->events);
  144. clear_bit(RXRPC_CALL_RUN_RTIMER, &call->flags);
  145. }
  146. read_unlock_bh(&call->state_lock);
  147. }
  148. /*
  149. * resend packets
  150. */
  151. static void rxrpc_resend(struct rxrpc_call *call)
  152. {
  153. struct rxrpc_skb_priv *sp;
  154. struct rxrpc_header *hdr;
  155. struct sk_buff *txb;
  156. unsigned long *p_txb, resend_at;
  157. int loop, stop;
  158. u8 resend;
  159. _enter("{%d,%d,%d,%d},",
  160. call->acks_hard, call->acks_unacked,
  161. atomic_read(&call->sequence),
  162. CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
  163. stop = 0;
  164. resend = 0;
  165. resend_at = 0;
  166. for (loop = call->acks_tail;
  167. loop != call->acks_head || stop;
  168. loop = (loop + 1) & (call->acks_winsz - 1)
  169. ) {
  170. p_txb = call->acks_window + loop;
  171. smp_read_barrier_depends();
  172. if (*p_txb & 1)
  173. continue;
  174. txb = (struct sk_buff *) *p_txb;
  175. sp = rxrpc_skb(txb);
  176. if (sp->need_resend) {
  177. sp->need_resend = false;
  178. /* each Tx packet has a new serial number */
  179. sp->hdr.serial =
  180. htonl(atomic_inc_return(&call->conn->serial));
  181. hdr = (struct rxrpc_header *) txb->head;
  182. hdr->serial = sp->hdr.serial;
  183. _proto("Tx DATA %%%u { #%d }",
  184. ntohl(sp->hdr.serial), ntohl(sp->hdr.seq));
  185. if (rxrpc_send_packet(call->conn->trans, txb) < 0) {
  186. stop = 0;
  187. sp->resend_at = jiffies + 3;
  188. } else {
  189. sp->resend_at =
  190. jiffies + rxrpc_resend_timeout * HZ;
  191. }
  192. }
  193. if (time_after_eq(jiffies + 1, sp->resend_at)) {
  194. sp->need_resend = true;
  195. resend |= 1;
  196. } else if (resend & 2) {
  197. if (time_before(sp->resend_at, resend_at))
  198. resend_at = sp->resend_at;
  199. } else {
  200. resend_at = sp->resend_at;
  201. resend |= 2;
  202. }
  203. }
  204. rxrpc_set_resend(call, resend, resend_at);
  205. _leave("");
  206. }
  207. /*
  208. * handle resend timer expiry
  209. */
  210. static void rxrpc_resend_timer(struct rxrpc_call *call)
  211. {
  212. struct rxrpc_skb_priv *sp;
  213. struct sk_buff *txb;
  214. unsigned long *p_txb, resend_at;
  215. int loop;
  216. u8 resend;
  217. _enter("%d,%d,%d",
  218. call->acks_tail, call->acks_unacked, call->acks_head);
  219. if (call->state >= RXRPC_CALL_COMPLETE)
  220. return;
  221. resend = 0;
  222. resend_at = 0;
  223. for (loop = call->acks_unacked;
  224. loop != call->acks_head;
  225. loop = (loop + 1) & (call->acks_winsz - 1)
  226. ) {
  227. p_txb = call->acks_window + loop;
  228. smp_read_barrier_depends();
  229. txb = (struct sk_buff *) (*p_txb & ~1);
  230. sp = rxrpc_skb(txb);
  231. ASSERT(!(*p_txb & 1));
  232. if (sp->need_resend) {
  233. ;
  234. } else if (time_after_eq(jiffies + 1, sp->resend_at)) {
  235. sp->need_resend = true;
  236. resend |= 1;
  237. } else if (resend & 2) {
  238. if (time_before(sp->resend_at, resend_at))
  239. resend_at = sp->resend_at;
  240. } else {
  241. resend_at = sp->resend_at;
  242. resend |= 2;
  243. }
  244. }
  245. rxrpc_set_resend(call, resend, resend_at);
  246. _leave("");
  247. }
  248. /*
  249. * process soft ACKs of our transmitted packets
  250. * - these indicate packets the peer has or has not received, but hasn't yet
  251. * given to the consumer, and so can still be discarded and re-requested
  252. */
  253. static int rxrpc_process_soft_ACKs(struct rxrpc_call *call,
  254. struct rxrpc_ackpacket *ack,
  255. struct sk_buff *skb)
  256. {
  257. struct rxrpc_skb_priv *sp;
  258. struct sk_buff *txb;
  259. unsigned long *p_txb, resend_at;
  260. int loop;
  261. u8 sacks[RXRPC_MAXACKS], resend;
  262. _enter("{%d,%d},{%d},",
  263. call->acks_hard,
  264. CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz),
  265. ack->nAcks);
  266. if (skb_copy_bits(skb, 0, sacks, ack->nAcks) < 0)
  267. goto protocol_error;
  268. resend = 0;
  269. resend_at = 0;
  270. for (loop = 0; loop < ack->nAcks; loop++) {
  271. p_txb = call->acks_window;
  272. p_txb += (call->acks_tail + loop) & (call->acks_winsz - 1);
  273. smp_read_barrier_depends();
  274. txb = (struct sk_buff *) (*p_txb & ~1);
  275. sp = rxrpc_skb(txb);
  276. switch (sacks[loop]) {
  277. case RXRPC_ACK_TYPE_ACK:
  278. sp->need_resend = false;
  279. *p_txb |= 1;
  280. break;
  281. case RXRPC_ACK_TYPE_NACK:
  282. sp->need_resend = true;
  283. *p_txb &= ~1;
  284. resend = 1;
  285. break;
  286. default:
  287. _debug("Unsupported ACK type %d", sacks[loop]);
  288. goto protocol_error;
  289. }
  290. }
  291. smp_mb();
  292. call->acks_unacked = (call->acks_tail + loop) & (call->acks_winsz - 1);
  293. /* anything not explicitly ACK'd is implicitly NACK'd, but may just not
  294. * have been received or processed yet by the far end */
  295. for (loop = call->acks_unacked;
  296. loop != call->acks_head;
  297. loop = (loop + 1) & (call->acks_winsz - 1)
  298. ) {
  299. p_txb = call->acks_window + loop;
  300. smp_read_barrier_depends();
  301. txb = (struct sk_buff *) (*p_txb & ~1);
  302. sp = rxrpc_skb(txb);
  303. if (*p_txb & 1) {
  304. /* packet must have been discarded */
  305. sp->need_resend = true;
  306. *p_txb &= ~1;
  307. resend |= 1;
  308. } else if (sp->need_resend) {
  309. ;
  310. } else if (time_after_eq(jiffies + 1, sp->resend_at)) {
  311. sp->need_resend = true;
  312. resend |= 1;
  313. } else if (resend & 2) {
  314. if (time_before(sp->resend_at, resend_at))
  315. resend_at = sp->resend_at;
  316. } else {
  317. resend_at = sp->resend_at;
  318. resend |= 2;
  319. }
  320. }
  321. rxrpc_set_resend(call, resend, resend_at);
  322. _leave(" = 0");
  323. return 0;
  324. protocol_error:
  325. _leave(" = -EPROTO");
  326. return -EPROTO;
  327. }
  328. /*
  329. * discard hard-ACK'd packets from the Tx window
  330. */
  331. static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
  332. {
  333. unsigned long _skb;
  334. int tail = call->acks_tail, old_tail;
  335. int win = CIRC_CNT(call->acks_head, tail, call->acks_winsz);
  336. _enter("{%u,%u},%u", call->acks_hard, win, hard);
  337. ASSERTCMP(hard - call->acks_hard, <=, win);
  338. while (call->acks_hard < hard) {
  339. smp_read_barrier_depends();
  340. _skb = call->acks_window[tail] & ~1;
  341. rxrpc_free_skb((struct sk_buff *) _skb);
  342. old_tail = tail;
  343. tail = (tail + 1) & (call->acks_winsz - 1);
  344. call->acks_tail = tail;
  345. if (call->acks_unacked == old_tail)
  346. call->acks_unacked = tail;
  347. call->acks_hard++;
  348. }
  349. wake_up(&call->tx_waitq);
  350. }
  351. /*
  352. * clear the Tx window in the event of a failure
  353. */
  354. static void rxrpc_clear_tx_window(struct rxrpc_call *call)
  355. {
  356. rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
  357. }
  358. /*
  359. * drain the out of sequence received packet queue into the packet Rx queue
  360. */
  361. static int rxrpc_drain_rx_oos_queue(struct rxrpc_call *call)
  362. {
  363. struct rxrpc_skb_priv *sp;
  364. struct sk_buff *skb;
  365. bool terminal;
  366. int ret;
  367. _enter("{%d,%d}", call->rx_data_post, call->rx_first_oos);
  368. spin_lock_bh(&call->lock);
  369. ret = -ECONNRESET;
  370. if (test_bit(RXRPC_CALL_RELEASED, &call->flags))
  371. goto socket_unavailable;
  372. skb = skb_dequeue(&call->rx_oos_queue);
  373. if (skb) {
  374. sp = rxrpc_skb(skb);
  375. _debug("drain OOS packet %d [%d]",
  376. ntohl(sp->hdr.seq), call->rx_first_oos);
  377. if (ntohl(sp->hdr.seq) != call->rx_first_oos) {
  378. skb_queue_head(&call->rx_oos_queue, skb);
  379. call->rx_first_oos = ntohl(rxrpc_skb(skb)->hdr.seq);
  380. _debug("requeue %p {%u}", skb, call->rx_first_oos);
  381. } else {
  382. skb->mark = RXRPC_SKB_MARK_DATA;
  383. terminal = ((sp->hdr.flags & RXRPC_LAST_PACKET) &&
  384. !(sp->hdr.flags & RXRPC_CLIENT_INITIATED));
  385. ret = rxrpc_queue_rcv_skb(call, skb, true, terminal);
  386. BUG_ON(ret < 0);
  387. _debug("drain #%u", call->rx_data_post);
  388. call->rx_data_post++;
  389. /* find out what the next packet is */
  390. skb = skb_peek(&call->rx_oos_queue);
  391. if (skb)
  392. call->rx_first_oos =
  393. ntohl(rxrpc_skb(skb)->hdr.seq);
  394. else
  395. call->rx_first_oos = 0;
  396. _debug("peek %p {%u}", skb, call->rx_first_oos);
  397. }
  398. }
  399. ret = 0;
  400. socket_unavailable:
  401. spin_unlock_bh(&call->lock);
  402. _leave(" = %d", ret);
  403. return ret;
  404. }
  405. /*
  406. * insert an out of sequence packet into the buffer
  407. */
  408. static void rxrpc_insert_oos_packet(struct rxrpc_call *call,
  409. struct sk_buff *skb)
  410. {
  411. struct rxrpc_skb_priv *sp, *psp;
  412. struct sk_buff *p;
  413. u32 seq;
  414. sp = rxrpc_skb(skb);
  415. seq = ntohl(sp->hdr.seq);
  416. _enter(",,{%u}", seq);
  417. skb->destructor = rxrpc_packet_destructor;
  418. ASSERTCMP(sp->call, ==, NULL);
  419. sp->call = call;
  420. rxrpc_get_call(call);
  421. /* insert into the buffer in sequence order */
  422. spin_lock_bh(&call->lock);
  423. skb_queue_walk(&call->rx_oos_queue, p) {
  424. psp = rxrpc_skb(p);
  425. if (ntohl(psp->hdr.seq) > seq) {
  426. _debug("insert oos #%u before #%u",
  427. seq, ntohl(psp->hdr.seq));
  428. skb_insert(p, skb, &call->rx_oos_queue);
  429. goto inserted;
  430. }
  431. }
  432. _debug("append oos #%u", seq);
  433. skb_queue_tail(&call->rx_oos_queue, skb);
  434. inserted:
  435. /* we might now have a new front to the queue */
  436. if (call->rx_first_oos == 0 || seq < call->rx_first_oos)
  437. call->rx_first_oos = seq;
  438. read_lock(&call->state_lock);
  439. if (call->state < RXRPC_CALL_COMPLETE &&
  440. call->rx_data_post == call->rx_first_oos) {
  441. _debug("drain rx oos now");
  442. set_bit(RXRPC_CALL_DRAIN_RX_OOS, &call->events);
  443. }
  444. read_unlock(&call->state_lock);
  445. spin_unlock_bh(&call->lock);
  446. _leave(" [stored #%u]", call->rx_first_oos);
  447. }
  448. /*
  449. * clear the Tx window on final ACK reception
  450. */
  451. static void rxrpc_zap_tx_window(struct rxrpc_call *call)
  452. {
  453. struct rxrpc_skb_priv *sp;
  454. struct sk_buff *skb;
  455. unsigned long _skb, *acks_window;
  456. u8 winsz = call->acks_winsz;
  457. int tail;
  458. acks_window = call->acks_window;
  459. call->acks_window = NULL;
  460. while (CIRC_CNT(call->acks_head, call->acks_tail, winsz) > 0) {
  461. tail = call->acks_tail;
  462. smp_read_barrier_depends();
  463. _skb = acks_window[tail] & ~1;
  464. smp_mb();
  465. call->acks_tail = (call->acks_tail + 1) & (winsz - 1);
  466. skb = (struct sk_buff *) _skb;
  467. sp = rxrpc_skb(skb);
  468. _debug("+++ clear Tx %u", ntohl(sp->hdr.seq));
  469. rxrpc_free_skb(skb);
  470. }
  471. kfree(acks_window);
  472. }
  473. /*
  474. * process the extra information that may be appended to an ACK packet
  475. */
  476. static void rxrpc_extract_ackinfo(struct rxrpc_call *call, struct sk_buff *skb,
  477. unsigned int latest, int nAcks)
  478. {
  479. struct rxrpc_ackinfo ackinfo;
  480. struct rxrpc_peer *peer;
  481. unsigned int mtu;
  482. if (skb_copy_bits(skb, nAcks + 3, &ackinfo, sizeof(ackinfo)) < 0) {
  483. _leave(" [no ackinfo]");
  484. return;
  485. }
  486. _proto("Rx ACK %%%u Info { rx=%u max=%u rwin=%u jm=%u }",
  487. latest,
  488. ntohl(ackinfo.rxMTU), ntohl(ackinfo.maxMTU),
  489. ntohl(ackinfo.rwind), ntohl(ackinfo.jumbo_max));
  490. mtu = min(ntohl(ackinfo.rxMTU), ntohl(ackinfo.maxMTU));
  491. peer = call->conn->trans->peer;
  492. if (mtu < peer->maxdata) {
  493. spin_lock_bh(&peer->lock);
  494. peer->maxdata = mtu;
  495. peer->mtu = mtu + peer->hdrsize;
  496. spin_unlock_bh(&peer->lock);
  497. _net("Net MTU %u (maxdata %u)", peer->mtu, peer->maxdata);
  498. }
  499. }
  500. /*
  501. * process packets in the reception queue
  502. */
  503. static int rxrpc_process_rx_queue(struct rxrpc_call *call,
  504. u32 *_abort_code)
  505. {
  506. struct rxrpc_ackpacket ack;
  507. struct rxrpc_skb_priv *sp;
  508. struct sk_buff *skb;
  509. bool post_ACK;
  510. int latest;
  511. u32 hard, tx;
  512. _enter("");
  513. process_further:
  514. skb = skb_dequeue(&call->rx_queue);
  515. if (!skb)
  516. return -EAGAIN;
  517. _net("deferred skb %p", skb);
  518. sp = rxrpc_skb(skb);
  519. _debug("process %s [st %d]", rxrpc_pkts[sp->hdr.type], call->state);
  520. post_ACK = false;
  521. switch (sp->hdr.type) {
  522. /* data packets that wind up here have been received out of
  523. * order, need security processing or are jumbo packets */
  524. case RXRPC_PACKET_TYPE_DATA:
  525. _proto("OOSQ DATA %%%u { #%u }",
  526. ntohl(sp->hdr.serial), ntohl(sp->hdr.seq));
  527. /* secured packets must be verified and possibly decrypted */
  528. if (rxrpc_verify_packet(call, skb, _abort_code) < 0)
  529. goto protocol_error;
  530. rxrpc_insert_oos_packet(call, skb);
  531. goto process_further;
  532. /* partial ACK to process */
  533. case RXRPC_PACKET_TYPE_ACK:
  534. if (skb_copy_bits(skb, 0, &ack, sizeof(ack)) < 0) {
  535. _debug("extraction failure");
  536. goto protocol_error;
  537. }
  538. if (!skb_pull(skb, sizeof(ack)))
  539. BUG();
  540. latest = ntohl(sp->hdr.serial);
  541. hard = ntohl(ack.firstPacket);
  542. tx = atomic_read(&call->sequence);
  543. _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
  544. latest,
  545. ntohs(ack.maxSkew),
  546. hard,
  547. ntohl(ack.previousPacket),
  548. ntohl(ack.serial),
  549. rxrpc_acks(ack.reason),
  550. ack.nAcks);
  551. rxrpc_extract_ackinfo(call, skb, latest, ack.nAcks);
  552. if (ack.reason == RXRPC_ACK_PING) {
  553. _proto("Rx ACK %%%u PING Request", latest);
  554. rxrpc_propose_ACK(call, RXRPC_ACK_PING_RESPONSE,
  555. sp->hdr.serial, true);
  556. }
  557. /* discard any out-of-order or duplicate ACKs */
  558. if (latest - call->acks_latest <= 0) {
  559. _debug("discard ACK %d <= %d",
  560. latest, call->acks_latest);
  561. goto discard;
  562. }
  563. call->acks_latest = latest;
  564. if (call->state != RXRPC_CALL_CLIENT_SEND_REQUEST &&
  565. call->state != RXRPC_CALL_CLIENT_AWAIT_REPLY &&
  566. call->state != RXRPC_CALL_SERVER_SEND_REPLY &&
  567. call->state != RXRPC_CALL_SERVER_AWAIT_ACK)
  568. goto discard;
  569. _debug("Tx=%d H=%u S=%d", tx, call->acks_hard, call->state);
  570. if (hard > 0) {
  571. if (hard - 1 > tx) {
  572. _debug("hard-ACK'd packet %d not transmitted"
  573. " (%d top)",
  574. hard - 1, tx);
  575. goto protocol_error;
  576. }
  577. if ((call->state == RXRPC_CALL_CLIENT_AWAIT_REPLY ||
  578. call->state == RXRPC_CALL_SERVER_AWAIT_ACK) &&
  579. hard > tx)
  580. goto all_acked;
  581. smp_rmb();
  582. rxrpc_rotate_tx_window(call, hard - 1);
  583. }
  584. if (ack.nAcks > 0) {
  585. if (hard - 1 + ack.nAcks > tx) {
  586. _debug("soft-ACK'd packet %d+%d not"
  587. " transmitted (%d top)",
  588. hard - 1, ack.nAcks, tx);
  589. goto protocol_error;
  590. }
  591. if (rxrpc_process_soft_ACKs(call, &ack, skb) < 0)
  592. goto protocol_error;
  593. }
  594. goto discard;
  595. /* complete ACK to process */
  596. case RXRPC_PACKET_TYPE_ACKALL:
  597. goto all_acked;
  598. /* abort and busy are handled elsewhere */
  599. case RXRPC_PACKET_TYPE_BUSY:
  600. case RXRPC_PACKET_TYPE_ABORT:
  601. BUG();
  602. /* connection level events - also handled elsewhere */
  603. case RXRPC_PACKET_TYPE_CHALLENGE:
  604. case RXRPC_PACKET_TYPE_RESPONSE:
  605. case RXRPC_PACKET_TYPE_DEBUG:
  606. BUG();
  607. }
  608. /* if we've had a hard ACK that covers all the packets we've sent, then
  609. * that ends that phase of the operation */
  610. all_acked:
  611. write_lock_bh(&call->state_lock);
  612. _debug("ack all %d", call->state);
  613. switch (call->state) {
  614. case RXRPC_CALL_CLIENT_AWAIT_REPLY:
  615. call->state = RXRPC_CALL_CLIENT_RECV_REPLY;
  616. break;
  617. case RXRPC_CALL_SERVER_AWAIT_ACK:
  618. _debug("srv complete");
  619. call->state = RXRPC_CALL_COMPLETE;
  620. post_ACK = true;
  621. break;
  622. case RXRPC_CALL_CLIENT_SEND_REQUEST:
  623. case RXRPC_CALL_SERVER_RECV_REQUEST:
  624. goto protocol_error_unlock; /* can't occur yet */
  625. default:
  626. write_unlock_bh(&call->state_lock);
  627. goto discard; /* assume packet left over from earlier phase */
  628. }
  629. write_unlock_bh(&call->state_lock);
  630. /* if all the packets we sent are hard-ACK'd, then we can discard
  631. * whatever we've got left */
  632. _debug("clear Tx %d",
  633. CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
  634. del_timer_sync(&call->resend_timer);
  635. clear_bit(RXRPC_CALL_RUN_RTIMER, &call->flags);
  636. clear_bit(RXRPC_CALL_RESEND_TIMER, &call->events);
  637. if (call->acks_window)
  638. rxrpc_zap_tx_window(call);
  639. if (post_ACK) {
  640. /* post the final ACK message for userspace to pick up */
  641. _debug("post ACK");
  642. skb->mark = RXRPC_SKB_MARK_FINAL_ACK;
  643. sp->call = call;
  644. rxrpc_get_call(call);
  645. spin_lock_bh(&call->lock);
  646. if (rxrpc_queue_rcv_skb(call, skb, true, true) < 0)
  647. BUG();
  648. spin_unlock_bh(&call->lock);
  649. goto process_further;
  650. }
  651. discard:
  652. rxrpc_free_skb(skb);
  653. goto process_further;
  654. protocol_error_unlock:
  655. write_unlock_bh(&call->state_lock);
  656. protocol_error:
  657. rxrpc_free_skb(skb);
  658. _leave(" = -EPROTO");
  659. return -EPROTO;
  660. }
  661. /*
  662. * post a message to the socket Rx queue for recvmsg() to pick up
  663. */
  664. static int rxrpc_post_message(struct rxrpc_call *call, u32 mark, u32 error,
  665. bool fatal)
  666. {
  667. struct rxrpc_skb_priv *sp;
  668. struct sk_buff *skb;
  669. int ret;
  670. _enter("{%d,%lx},%u,%u,%d",
  671. call->debug_id, call->flags, mark, error, fatal);
  672. /* remove timers and things for fatal messages */
  673. if (fatal) {
  674. del_timer_sync(&call->resend_timer);
  675. del_timer_sync(&call->ack_timer);
  676. clear_bit(RXRPC_CALL_RUN_RTIMER, &call->flags);
  677. }
  678. if (mark != RXRPC_SKB_MARK_NEW_CALL &&
  679. !test_bit(RXRPC_CALL_HAS_USERID, &call->flags)) {
  680. _leave("[no userid]");
  681. return 0;
  682. }
  683. if (!test_bit(RXRPC_CALL_TERMINAL_MSG, &call->flags)) {
  684. skb = alloc_skb(0, GFP_NOFS);
  685. if (!skb)
  686. return -ENOMEM;
  687. rxrpc_new_skb(skb);
  688. skb->mark = mark;
  689. sp = rxrpc_skb(skb);
  690. memset(sp, 0, sizeof(*sp));
  691. sp->error = error;
  692. sp->call = call;
  693. rxrpc_get_call(call);
  694. spin_lock_bh(&call->lock);
  695. ret = rxrpc_queue_rcv_skb(call, skb, true, fatal);
  696. spin_unlock_bh(&call->lock);
  697. BUG_ON(ret < 0);
  698. }
  699. return 0;
  700. }
  701. /*
  702. * handle background processing of incoming call packets and ACK / abort
  703. * generation
  704. */
  705. void rxrpc_process_call(struct work_struct *work)
  706. {
  707. struct rxrpc_call *call =
  708. container_of(work, struct rxrpc_call, processor);
  709. struct rxrpc_ackpacket ack;
  710. struct rxrpc_ackinfo ackinfo;
  711. struct rxrpc_header hdr;
  712. struct msghdr msg;
  713. struct kvec iov[5];
  714. unsigned long bits;
  715. __be32 data, pad;
  716. size_t len;
  717. int genbit, loop, nbit, ioc, ret, mtu;
  718. u32 abort_code = RX_PROTOCOL_ERROR;
  719. u8 *acks = NULL;
  720. //printk("\n--------------------\n");
  721. _enter("{%d,%s,%lx} [%lu]",
  722. call->debug_id, rxrpc_call_states[call->state], call->events,
  723. (jiffies - call->creation_jif) / (HZ / 10));
  724. if (test_and_set_bit(RXRPC_CALL_PROC_BUSY, &call->flags)) {
  725. _debug("XXXXXXXXXXXXX RUNNING ON MULTIPLE CPUS XXXXXXXXXXXXX");
  726. return;
  727. }
  728. /* there's a good chance we're going to have to send a message, so set
  729. * one up in advance */
  730. msg.msg_name = &call->conn->trans->peer->srx.transport.sin;
  731. msg.msg_namelen = sizeof(call->conn->trans->peer->srx.transport.sin);
  732. msg.msg_control = NULL;
  733. msg.msg_controllen = 0;
  734. msg.msg_flags = 0;
  735. hdr.epoch = call->conn->epoch;
  736. hdr.cid = call->cid;
  737. hdr.callNumber = call->call_id;
  738. hdr.seq = 0;
  739. hdr.type = RXRPC_PACKET_TYPE_ACK;
  740. hdr.flags = call->conn->out_clientflag;
  741. hdr.userStatus = 0;
  742. hdr.securityIndex = call->conn->security_ix;
  743. hdr._rsvd = 0;
  744. hdr.serviceId = call->conn->service_id;
  745. memset(iov, 0, sizeof(iov));
  746. iov[0].iov_base = &hdr;
  747. iov[0].iov_len = sizeof(hdr);
  748. /* deal with events of a final nature */
  749. if (test_bit(RXRPC_CALL_RELEASE, &call->events)) {
  750. rxrpc_release_call(call);
  751. clear_bit(RXRPC_CALL_RELEASE, &call->events);
  752. }
  753. if (test_bit(RXRPC_CALL_RCVD_ERROR, &call->events)) {
  754. int error;
  755. clear_bit(RXRPC_CALL_CONN_ABORT, &call->events);
  756. clear_bit(RXRPC_CALL_REJECT_BUSY, &call->events);
  757. clear_bit(RXRPC_CALL_ABORT, &call->events);
  758. error = call->conn->trans->peer->net_error;
  759. _debug("post net error %d", error);
  760. if (rxrpc_post_message(call, RXRPC_SKB_MARK_NET_ERROR,
  761. error, true) < 0)
  762. goto no_mem;
  763. clear_bit(RXRPC_CALL_RCVD_ERROR, &call->events);
  764. goto kill_ACKs;
  765. }
  766. if (test_bit(RXRPC_CALL_CONN_ABORT, &call->events)) {
  767. ASSERTCMP(call->state, >, RXRPC_CALL_COMPLETE);
  768. clear_bit(RXRPC_CALL_REJECT_BUSY, &call->events);
  769. clear_bit(RXRPC_CALL_ABORT, &call->events);
  770. _debug("post conn abort");
  771. if (rxrpc_post_message(call, RXRPC_SKB_MARK_LOCAL_ERROR,
  772. call->conn->error, true) < 0)
  773. goto no_mem;
  774. clear_bit(RXRPC_CALL_CONN_ABORT, &call->events);
  775. goto kill_ACKs;
  776. }
  777. if (test_bit(RXRPC_CALL_REJECT_BUSY, &call->events)) {
  778. hdr.type = RXRPC_PACKET_TYPE_BUSY;
  779. genbit = RXRPC_CALL_REJECT_BUSY;
  780. goto send_message;
  781. }
  782. if (test_bit(RXRPC_CALL_ABORT, &call->events)) {
  783. ASSERTCMP(call->state, >, RXRPC_CALL_COMPLETE);
  784. if (rxrpc_post_message(call, RXRPC_SKB_MARK_LOCAL_ERROR,
  785. ECONNABORTED, true) < 0)
  786. goto no_mem;
  787. hdr.type = RXRPC_PACKET_TYPE_ABORT;
  788. data = htonl(call->abort_code);
  789. iov[1].iov_base = &data;
  790. iov[1].iov_len = sizeof(data);
  791. genbit = RXRPC_CALL_ABORT;
  792. goto send_message;
  793. }
  794. if (test_bit(RXRPC_CALL_ACK_FINAL, &call->events)) {
  795. genbit = RXRPC_CALL_ACK_FINAL;
  796. ack.bufferSpace = htons(8);
  797. ack.maxSkew = 0;
  798. ack.serial = 0;
  799. ack.reason = RXRPC_ACK_IDLE;
  800. ack.nAcks = 0;
  801. call->ackr_reason = 0;
  802. spin_lock_bh(&call->lock);
  803. ack.serial = call->ackr_serial;
  804. ack.previousPacket = call->ackr_prev_seq;
  805. ack.firstPacket = htonl(call->rx_data_eaten + 1);
  806. spin_unlock_bh(&call->lock);
  807. pad = 0;
  808. iov[1].iov_base = &ack;
  809. iov[1].iov_len = sizeof(ack);
  810. iov[2].iov_base = &pad;
  811. iov[2].iov_len = 3;
  812. iov[3].iov_base = &ackinfo;
  813. iov[3].iov_len = sizeof(ackinfo);
  814. goto send_ACK;
  815. }
  816. if (call->events & ((1 << RXRPC_CALL_RCVD_BUSY) |
  817. (1 << RXRPC_CALL_RCVD_ABORT))
  818. ) {
  819. u32 mark;
  820. if (test_bit(RXRPC_CALL_RCVD_ABORT, &call->events))
  821. mark = RXRPC_SKB_MARK_REMOTE_ABORT;
  822. else
  823. mark = RXRPC_SKB_MARK_BUSY;
  824. _debug("post abort/busy");
  825. rxrpc_clear_tx_window(call);
  826. if (rxrpc_post_message(call, mark, ECONNABORTED, true) < 0)
  827. goto no_mem;
  828. clear_bit(RXRPC_CALL_RCVD_BUSY, &call->events);
  829. clear_bit(RXRPC_CALL_RCVD_ABORT, &call->events);
  830. goto kill_ACKs;
  831. }
  832. if (test_and_clear_bit(RXRPC_CALL_RCVD_ACKALL, &call->events)) {
  833. _debug("do implicit ackall");
  834. rxrpc_clear_tx_window(call);
  835. }
  836. if (test_bit(RXRPC_CALL_LIFE_TIMER, &call->events)) {
  837. write_lock_bh(&call->state_lock);
  838. if (call->state <= RXRPC_CALL_COMPLETE) {
  839. call->state = RXRPC_CALL_LOCALLY_ABORTED;
  840. call->abort_code = RX_CALL_TIMEOUT;
  841. set_bit(RXRPC_CALL_ABORT, &call->events);
  842. }
  843. write_unlock_bh(&call->state_lock);
  844. _debug("post timeout");
  845. if (rxrpc_post_message(call, RXRPC_SKB_MARK_LOCAL_ERROR,
  846. ETIME, true) < 0)
  847. goto no_mem;
  848. clear_bit(RXRPC_CALL_LIFE_TIMER, &call->events);
  849. goto kill_ACKs;
  850. }
  851. /* deal with assorted inbound messages */
  852. if (!skb_queue_empty(&call->rx_queue)) {
  853. switch (rxrpc_process_rx_queue(call, &abort_code)) {
  854. case 0:
  855. case -EAGAIN:
  856. break;
  857. case -ENOMEM:
  858. goto no_mem;
  859. case -EKEYEXPIRED:
  860. case -EKEYREJECTED:
  861. case -EPROTO:
  862. rxrpc_abort_call(call, abort_code);
  863. goto kill_ACKs;
  864. }
  865. }
  866. /* handle resending */
  867. if (test_and_clear_bit(RXRPC_CALL_RESEND_TIMER, &call->events))
  868. rxrpc_resend_timer(call);
  869. if (test_and_clear_bit(RXRPC_CALL_RESEND, &call->events))
  870. rxrpc_resend(call);
  871. /* consider sending an ordinary ACK */
  872. if (test_bit(RXRPC_CALL_ACK, &call->events)) {
  873. _debug("send ACK: window: %d - %d { %lx }",
  874. call->rx_data_eaten, call->ackr_win_top,
  875. call->ackr_window[0]);
  876. if (call->state > RXRPC_CALL_SERVER_ACK_REQUEST &&
  877. call->ackr_reason != RXRPC_ACK_PING_RESPONSE) {
  878. /* ACK by sending reply DATA packet in this state */
  879. clear_bit(RXRPC_CALL_ACK, &call->events);
  880. goto maybe_reschedule;
  881. }
  882. genbit = RXRPC_CALL_ACK;
  883. acks = kzalloc(call->ackr_win_top - call->rx_data_eaten,
  884. GFP_NOFS);
  885. if (!acks)
  886. goto no_mem;
  887. //hdr.flags = RXRPC_SLOW_START_OK;
  888. ack.bufferSpace = htons(8);
  889. ack.maxSkew = 0;
  890. ack.serial = 0;
  891. ack.reason = 0;
  892. spin_lock_bh(&call->lock);
  893. ack.reason = call->ackr_reason;
  894. ack.serial = call->ackr_serial;
  895. ack.previousPacket = call->ackr_prev_seq;
  896. ack.firstPacket = htonl(call->rx_data_eaten + 1);
  897. ack.nAcks = 0;
  898. for (loop = 0; loop < RXRPC_ACKR_WINDOW_ASZ; loop++) {
  899. nbit = loop * BITS_PER_LONG;
  900. for (bits = call->ackr_window[loop]; bits; bits >>= 1
  901. ) {
  902. _debug("- l=%d n=%d b=%lx", loop, nbit, bits);
  903. if (bits & 1) {
  904. acks[nbit] = RXRPC_ACK_TYPE_ACK;
  905. ack.nAcks = nbit + 1;
  906. }
  907. nbit++;
  908. }
  909. }
  910. call->ackr_reason = 0;
  911. spin_unlock_bh(&call->lock);
  912. pad = 0;
  913. iov[1].iov_base = &ack;
  914. iov[1].iov_len = sizeof(ack);
  915. iov[2].iov_base = acks;
  916. iov[2].iov_len = ack.nAcks;
  917. iov[3].iov_base = &pad;
  918. iov[3].iov_len = 3;
  919. iov[4].iov_base = &ackinfo;
  920. iov[4].iov_len = sizeof(ackinfo);
  921. switch (ack.reason) {
  922. case RXRPC_ACK_REQUESTED:
  923. case RXRPC_ACK_DUPLICATE:
  924. case RXRPC_ACK_OUT_OF_SEQUENCE:
  925. case RXRPC_ACK_EXCEEDS_WINDOW:
  926. case RXRPC_ACK_NOSPACE:
  927. case RXRPC_ACK_PING:
  928. case RXRPC_ACK_PING_RESPONSE:
  929. goto send_ACK_with_skew;
  930. case RXRPC_ACK_DELAY:
  931. case RXRPC_ACK_IDLE:
  932. goto send_ACK;
  933. }
  934. }
  935. /* handle completion of security negotiations on an incoming
  936. * connection */
  937. if (test_and_clear_bit(RXRPC_CALL_SECURED, &call->events)) {
  938. _debug("secured");
  939. spin_lock_bh(&call->lock);
  940. if (call->state == RXRPC_CALL_SERVER_SECURING) {
  941. _debug("securing");
  942. write_lock(&call->conn->lock);
  943. if (!test_bit(RXRPC_CALL_RELEASED, &call->flags) &&
  944. !test_bit(RXRPC_CALL_RELEASE, &call->events)) {
  945. _debug("not released");
  946. call->state = RXRPC_CALL_SERVER_ACCEPTING;
  947. list_move_tail(&call->accept_link,
  948. &call->socket->acceptq);
  949. }
  950. write_unlock(&call->conn->lock);
  951. read_lock(&call->state_lock);
  952. if (call->state < RXRPC_CALL_COMPLETE)
  953. set_bit(RXRPC_CALL_POST_ACCEPT, &call->events);
  954. read_unlock(&call->state_lock);
  955. }
  956. spin_unlock_bh(&call->lock);
  957. if (!test_bit(RXRPC_CALL_POST_ACCEPT, &call->events))
  958. goto maybe_reschedule;
  959. }
  960. /* post a notification of an acceptable connection to the app */
  961. if (test_bit(RXRPC_CALL_POST_ACCEPT, &call->events)) {
  962. _debug("post accept");
  963. if (rxrpc_post_message(call, RXRPC_SKB_MARK_NEW_CALL,
  964. 0, false) < 0)
  965. goto no_mem;
  966. clear_bit(RXRPC_CALL_POST_ACCEPT, &call->events);
  967. goto maybe_reschedule;
  968. }
  969. /* handle incoming call acceptance */
  970. if (test_and_clear_bit(RXRPC_CALL_ACCEPTED, &call->events)) {
  971. _debug("accepted");
  972. ASSERTCMP(call->rx_data_post, ==, 0);
  973. call->rx_data_post = 1;
  974. read_lock_bh(&call->state_lock);
  975. if (call->state < RXRPC_CALL_COMPLETE)
  976. set_bit(RXRPC_CALL_DRAIN_RX_OOS, &call->events);
  977. read_unlock_bh(&call->state_lock);
  978. }
  979. /* drain the out of sequence received packet queue into the packet Rx
  980. * queue */
  981. if (test_and_clear_bit(RXRPC_CALL_DRAIN_RX_OOS, &call->events)) {
  982. while (call->rx_data_post == call->rx_first_oos)
  983. if (rxrpc_drain_rx_oos_queue(call) < 0)
  984. break;
  985. goto maybe_reschedule;
  986. }
  987. /* other events may have been raised since we started checking */
  988. goto maybe_reschedule;
  989. send_ACK_with_skew:
  990. ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
  991. ntohl(ack.serial));
  992. send_ACK:
  993. mtu = call->conn->trans->peer->if_mtu;
  994. mtu -= call->conn->trans->peer->hdrsize;
  995. ackinfo.maxMTU = htonl(mtu);
  996. ackinfo.rwind = htonl(32);
  997. /* permit the peer to send us jumbo packets if it wants to */
  998. ackinfo.rxMTU = htonl(5692);
  999. ackinfo.jumbo_max = htonl(4);
  1000. hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
  1001. _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
  1002. ntohl(hdr.serial),
  1003. ntohs(ack.maxSkew),
  1004. ntohl(ack.firstPacket),
  1005. ntohl(ack.previousPacket),
  1006. ntohl(ack.serial),
  1007. rxrpc_acks(ack.reason),
  1008. ack.nAcks);
  1009. del_timer_sync(&call->ack_timer);
  1010. if (ack.nAcks > 0)
  1011. set_bit(RXRPC_CALL_TX_SOFT_ACK, &call->flags);
  1012. goto send_message_2;
  1013. send_message:
  1014. _debug("send message");
  1015. hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
  1016. _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
  1017. send_message_2:
  1018. len = iov[0].iov_len;
  1019. ioc = 1;
  1020. if (iov[4].iov_len) {
  1021. ioc = 5;
  1022. len += iov[4].iov_len;
  1023. len += iov[3].iov_len;
  1024. len += iov[2].iov_len;
  1025. len += iov[1].iov_len;
  1026. } else if (iov[3].iov_len) {
  1027. ioc = 4;
  1028. len += iov[3].iov_len;
  1029. len += iov[2].iov_len;
  1030. len += iov[1].iov_len;
  1031. } else if (iov[2].iov_len) {
  1032. ioc = 3;
  1033. len += iov[2].iov_len;
  1034. len += iov[1].iov_len;
  1035. } else if (iov[1].iov_len) {
  1036. ioc = 2;
  1037. len += iov[1].iov_len;
  1038. }
  1039. ret = kernel_sendmsg(call->conn->trans->local->socket,
  1040. &msg, iov, ioc, len);
  1041. if (ret < 0) {
  1042. _debug("sendmsg failed: %d", ret);
  1043. read_lock_bh(&call->state_lock);
  1044. if (call->state < RXRPC_CALL_DEAD)
  1045. rxrpc_queue_call(call);
  1046. read_unlock_bh(&call->state_lock);
  1047. goto error;
  1048. }
  1049. switch (genbit) {
  1050. case RXRPC_CALL_ABORT:
  1051. clear_bit(genbit, &call->events);
  1052. clear_bit(RXRPC_CALL_RCVD_ABORT, &call->events);
  1053. goto kill_ACKs;
  1054. case RXRPC_CALL_ACK_FINAL:
  1055. write_lock_bh(&call->state_lock);
  1056. if (call->state == RXRPC_CALL_CLIENT_FINAL_ACK)
  1057. call->state = RXRPC_CALL_COMPLETE;
  1058. write_unlock_bh(&call->state_lock);
  1059. goto kill_ACKs;
  1060. default:
  1061. clear_bit(genbit, &call->events);
  1062. switch (call->state) {
  1063. case RXRPC_CALL_CLIENT_AWAIT_REPLY:
  1064. case RXRPC_CALL_CLIENT_RECV_REPLY:
  1065. case RXRPC_CALL_SERVER_RECV_REQUEST:
  1066. case RXRPC_CALL_SERVER_ACK_REQUEST:
  1067. _debug("start ACK timer");
  1068. rxrpc_propose_ACK(call, RXRPC_ACK_DELAY,
  1069. call->ackr_serial, false);
  1070. default:
  1071. break;
  1072. }
  1073. goto maybe_reschedule;
  1074. }
  1075. kill_ACKs:
  1076. del_timer_sync(&call->ack_timer);
  1077. if (test_and_clear_bit(RXRPC_CALL_ACK_FINAL, &call->events))
  1078. rxrpc_put_call(call);
  1079. clear_bit(RXRPC_CALL_ACK, &call->events);
  1080. maybe_reschedule:
  1081. if (call->events || !skb_queue_empty(&call->rx_queue)) {
  1082. read_lock_bh(&call->state_lock);
  1083. if (call->state < RXRPC_CALL_DEAD)
  1084. rxrpc_queue_call(call);
  1085. read_unlock_bh(&call->state_lock);
  1086. }
  1087. /* don't leave aborted connections on the accept queue */
  1088. if (call->state >= RXRPC_CALL_COMPLETE &&
  1089. !list_empty(&call->accept_link)) {
  1090. _debug("X unlinking once-pending call %p { e=%lx f=%lx c=%x }",
  1091. call, call->events, call->flags,
  1092. ntohl(call->conn->cid));
  1093. read_lock_bh(&call->state_lock);
  1094. if (!test_bit(RXRPC_CALL_RELEASED, &call->flags) &&
  1095. !test_and_set_bit(RXRPC_CALL_RELEASE, &call->events))
  1096. rxrpc_queue_call(call);
  1097. read_unlock_bh(&call->state_lock);
  1098. }
  1099. error:
  1100. clear_bit(RXRPC_CALL_PROC_BUSY, &call->flags);
  1101. kfree(acks);
  1102. /* because we don't want two CPUs both processing the work item for one
  1103. * call at the same time, we use a flag to note when it's busy; however
  1104. * this means there's a race between clearing the flag and setting the
  1105. * work pending bit and the work item being processed again */
  1106. if (call->events && !work_pending(&call->processor)) {
  1107. _debug("jumpstart %x", ntohl(call->conn->cid));
  1108. rxrpc_queue_call(call);
  1109. }
  1110. _leave("");
  1111. return;
  1112. no_mem:
  1113. _debug("out of memory");
  1114. goto maybe_reschedule;
  1115. }