input.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  1. /* RxRPC packet reception
  2. *
  3. * Copyright (C) 2007, 2016 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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  12. #include <linux/module.h>
  13. #include <linux/net.h>
  14. #include <linux/skbuff.h>
  15. #include <linux/errqueue.h>
  16. #include <linux/udp.h>
  17. #include <linux/in.h>
  18. #include <linux/in6.h>
  19. #include <linux/icmp.h>
  20. #include <linux/gfp.h>
  21. #include <net/sock.h>
  22. #include <net/af_rxrpc.h>
  23. #include <net/ip.h>
  24. #include <net/udp.h>
  25. #include <net/net_namespace.h>
  26. #include "ar-internal.h"
  27. static void rxrpc_proto_abort(const char *why,
  28. struct rxrpc_call *call, rxrpc_seq_t seq)
  29. {
  30. if (rxrpc_abort_call(why, call, seq, RX_PROTOCOL_ERROR, EBADMSG)) {
  31. set_bit(RXRPC_CALL_EV_ABORT, &call->events);
  32. rxrpc_queue_call(call);
  33. }
  34. }
  35. /*
  36. * Do TCP-style congestion management [RFC 5681].
  37. */
  38. static void rxrpc_congestion_management(struct rxrpc_call *call,
  39. struct sk_buff *skb,
  40. struct rxrpc_ack_summary *summary,
  41. rxrpc_serial_t acked_serial)
  42. {
  43. enum rxrpc_congest_change change = rxrpc_cong_no_change;
  44. unsigned int cumulative_acks = call->cong_cumul_acks;
  45. unsigned int cwnd = call->cong_cwnd;
  46. bool resend = false;
  47. summary->flight_size =
  48. (call->tx_top - call->tx_hard_ack) - summary->nr_acks;
  49. if (test_and_clear_bit(RXRPC_CALL_RETRANS_TIMEOUT, &call->flags)) {
  50. summary->retrans_timeo = true;
  51. call->cong_ssthresh = max_t(unsigned int,
  52. summary->flight_size / 2, 2);
  53. cwnd = 1;
  54. if (cwnd >= call->cong_ssthresh &&
  55. call->cong_mode == RXRPC_CALL_SLOW_START) {
  56. call->cong_mode = RXRPC_CALL_CONGEST_AVOIDANCE;
  57. call->cong_tstamp = skb->tstamp;
  58. cumulative_acks = 0;
  59. }
  60. }
  61. cumulative_acks += summary->nr_new_acks;
  62. cumulative_acks += summary->nr_rot_new_acks;
  63. if (cumulative_acks > 255)
  64. cumulative_acks = 255;
  65. summary->mode = call->cong_mode;
  66. summary->cwnd = call->cong_cwnd;
  67. summary->ssthresh = call->cong_ssthresh;
  68. summary->cumulative_acks = cumulative_acks;
  69. summary->dup_acks = call->cong_dup_acks;
  70. switch (call->cong_mode) {
  71. case RXRPC_CALL_SLOW_START:
  72. if (summary->nr_nacks > 0)
  73. goto packet_loss_detected;
  74. if (summary->cumulative_acks > 0)
  75. cwnd += 1;
  76. if (cwnd >= call->cong_ssthresh) {
  77. call->cong_mode = RXRPC_CALL_CONGEST_AVOIDANCE;
  78. call->cong_tstamp = skb->tstamp;
  79. }
  80. goto out;
  81. case RXRPC_CALL_CONGEST_AVOIDANCE:
  82. if (summary->nr_nacks > 0)
  83. goto packet_loss_detected;
  84. /* We analyse the number of packets that get ACK'd per RTT
  85. * period and increase the window if we managed to fill it.
  86. */
  87. if (call->peer->rtt_usage == 0)
  88. goto out;
  89. if (ktime_before(skb->tstamp,
  90. ktime_add_ns(call->cong_tstamp,
  91. call->peer->rtt)))
  92. goto out_no_clear_ca;
  93. change = rxrpc_cong_rtt_window_end;
  94. call->cong_tstamp = skb->tstamp;
  95. if (cumulative_acks >= cwnd)
  96. cwnd++;
  97. goto out;
  98. case RXRPC_CALL_PACKET_LOSS:
  99. if (summary->nr_nacks == 0)
  100. goto resume_normality;
  101. if (summary->new_low_nack) {
  102. change = rxrpc_cong_new_low_nack;
  103. call->cong_dup_acks = 1;
  104. if (call->cong_extra > 1)
  105. call->cong_extra = 1;
  106. goto send_extra_data;
  107. }
  108. call->cong_dup_acks++;
  109. if (call->cong_dup_acks < 3)
  110. goto send_extra_data;
  111. change = rxrpc_cong_begin_retransmission;
  112. call->cong_mode = RXRPC_CALL_FAST_RETRANSMIT;
  113. call->cong_ssthresh = max_t(unsigned int,
  114. summary->flight_size / 2, 2);
  115. cwnd = call->cong_ssthresh + 3;
  116. call->cong_extra = 0;
  117. call->cong_dup_acks = 0;
  118. resend = true;
  119. goto out;
  120. case RXRPC_CALL_FAST_RETRANSMIT:
  121. if (!summary->new_low_nack) {
  122. if (summary->nr_new_acks == 0)
  123. cwnd += 1;
  124. call->cong_dup_acks++;
  125. if (call->cong_dup_acks == 2) {
  126. change = rxrpc_cong_retransmit_again;
  127. call->cong_dup_acks = 0;
  128. resend = true;
  129. }
  130. } else {
  131. change = rxrpc_cong_progress;
  132. cwnd = call->cong_ssthresh;
  133. if (summary->nr_nacks == 0)
  134. goto resume_normality;
  135. }
  136. goto out;
  137. default:
  138. BUG();
  139. goto out;
  140. }
  141. resume_normality:
  142. change = rxrpc_cong_cleared_nacks;
  143. call->cong_dup_acks = 0;
  144. call->cong_extra = 0;
  145. call->cong_tstamp = skb->tstamp;
  146. if (cwnd < call->cong_ssthresh)
  147. call->cong_mode = RXRPC_CALL_SLOW_START;
  148. else
  149. call->cong_mode = RXRPC_CALL_CONGEST_AVOIDANCE;
  150. out:
  151. cumulative_acks = 0;
  152. out_no_clear_ca:
  153. if (cwnd >= RXRPC_RXTX_BUFF_SIZE - 1)
  154. cwnd = RXRPC_RXTX_BUFF_SIZE - 1;
  155. call->cong_cwnd = cwnd;
  156. call->cong_cumul_acks = cumulative_acks;
  157. trace_rxrpc_congest(call, summary, acked_serial, change);
  158. if (resend && !test_and_set_bit(RXRPC_CALL_EV_RESEND, &call->events))
  159. rxrpc_queue_call(call);
  160. return;
  161. packet_loss_detected:
  162. change = rxrpc_cong_saw_nack;
  163. call->cong_mode = RXRPC_CALL_PACKET_LOSS;
  164. call->cong_dup_acks = 0;
  165. goto send_extra_data;
  166. send_extra_data:
  167. /* Send some previously unsent DATA if we have some to advance the ACK
  168. * state.
  169. */
  170. if (call->rxtx_annotations[call->tx_top & RXRPC_RXTX_BUFF_MASK] &
  171. RXRPC_TX_ANNO_LAST ||
  172. summary->nr_acks != call->tx_top - call->tx_hard_ack) {
  173. call->cong_extra++;
  174. wake_up(&call->waitq);
  175. }
  176. goto out_no_clear_ca;
  177. }
  178. /*
  179. * Ping the other end to fill our RTT cache and to retrieve the rwind
  180. * and MTU parameters.
  181. */
  182. static void rxrpc_send_ping(struct rxrpc_call *call, struct sk_buff *skb,
  183. int skew)
  184. {
  185. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  186. ktime_t now = skb->tstamp;
  187. if (call->peer->rtt_usage < 3 ||
  188. ktime_before(ktime_add_ms(call->peer->rtt_last_req, 1000), now))
  189. rxrpc_propose_ACK(call, RXRPC_ACK_PING, skew, sp->hdr.serial,
  190. true, true,
  191. rxrpc_propose_ack_ping_for_params);
  192. }
  193. /*
  194. * Apply a hard ACK by advancing the Tx window.
  195. */
  196. static bool rxrpc_rotate_tx_window(struct rxrpc_call *call, rxrpc_seq_t to,
  197. struct rxrpc_ack_summary *summary)
  198. {
  199. struct sk_buff *skb, *list = NULL;
  200. bool rot_last = false;
  201. int ix;
  202. u8 annotation;
  203. if (call->acks_lowest_nak == call->tx_hard_ack) {
  204. call->acks_lowest_nak = to;
  205. } else if (before_eq(call->acks_lowest_nak, to)) {
  206. summary->new_low_nack = true;
  207. call->acks_lowest_nak = to;
  208. }
  209. spin_lock(&call->lock);
  210. while (before(call->tx_hard_ack, to)) {
  211. call->tx_hard_ack++;
  212. ix = call->tx_hard_ack & RXRPC_RXTX_BUFF_MASK;
  213. skb = call->rxtx_buffer[ix];
  214. annotation = call->rxtx_annotations[ix];
  215. rxrpc_see_skb(skb, rxrpc_skb_tx_rotated);
  216. call->rxtx_buffer[ix] = NULL;
  217. call->rxtx_annotations[ix] = 0;
  218. skb->next = list;
  219. list = skb;
  220. if (annotation & RXRPC_TX_ANNO_LAST) {
  221. set_bit(RXRPC_CALL_TX_LAST, &call->flags);
  222. rot_last = true;
  223. }
  224. if ((annotation & RXRPC_TX_ANNO_MASK) != RXRPC_TX_ANNO_ACK)
  225. summary->nr_rot_new_acks++;
  226. }
  227. spin_unlock(&call->lock);
  228. trace_rxrpc_transmit(call, (rot_last ?
  229. rxrpc_transmit_rotate_last :
  230. rxrpc_transmit_rotate));
  231. wake_up(&call->waitq);
  232. while (list) {
  233. skb = list;
  234. list = skb->next;
  235. skb->next = NULL;
  236. rxrpc_free_skb(skb, rxrpc_skb_tx_freed);
  237. }
  238. return rot_last;
  239. }
  240. /*
  241. * End the transmission phase of a call.
  242. *
  243. * This occurs when we get an ACKALL packet, the first DATA packet of a reply,
  244. * or a final ACK packet.
  245. */
  246. static bool rxrpc_end_tx_phase(struct rxrpc_call *call, bool reply_begun,
  247. const char *abort_why)
  248. {
  249. ASSERT(test_bit(RXRPC_CALL_TX_LAST, &call->flags));
  250. write_lock(&call->state_lock);
  251. switch (call->state) {
  252. case RXRPC_CALL_CLIENT_SEND_REQUEST:
  253. case RXRPC_CALL_CLIENT_AWAIT_REPLY:
  254. if (reply_begun)
  255. call->state = RXRPC_CALL_CLIENT_RECV_REPLY;
  256. else
  257. call->state = RXRPC_CALL_CLIENT_AWAIT_REPLY;
  258. break;
  259. case RXRPC_CALL_SERVER_AWAIT_ACK:
  260. __rxrpc_call_completed(call);
  261. rxrpc_notify_socket(call);
  262. break;
  263. default:
  264. goto bad_state;
  265. }
  266. write_unlock(&call->state_lock);
  267. if (call->state == RXRPC_CALL_CLIENT_AWAIT_REPLY) {
  268. rxrpc_propose_ACK(call, RXRPC_ACK_IDLE, 0, 0, false, true,
  269. rxrpc_propose_ack_client_tx_end);
  270. trace_rxrpc_transmit(call, rxrpc_transmit_await_reply);
  271. } else {
  272. trace_rxrpc_transmit(call, rxrpc_transmit_end);
  273. }
  274. _leave(" = ok");
  275. return true;
  276. bad_state:
  277. write_unlock(&call->state_lock);
  278. kdebug("end_tx %s", rxrpc_call_states[call->state]);
  279. rxrpc_proto_abort(abort_why, call, call->tx_top);
  280. return false;
  281. }
  282. /*
  283. * Begin the reply reception phase of a call.
  284. */
  285. static bool rxrpc_receiving_reply(struct rxrpc_call *call)
  286. {
  287. struct rxrpc_ack_summary summary = { 0 };
  288. rxrpc_seq_t top = READ_ONCE(call->tx_top);
  289. if (call->ackr_reason) {
  290. spin_lock_bh(&call->lock);
  291. call->ackr_reason = 0;
  292. call->resend_at = call->expire_at;
  293. call->ack_at = call->expire_at;
  294. spin_unlock_bh(&call->lock);
  295. rxrpc_set_timer(call, rxrpc_timer_init_for_reply,
  296. ktime_get_real());
  297. }
  298. if (!test_bit(RXRPC_CALL_TX_LAST, &call->flags)) {
  299. if (!rxrpc_rotate_tx_window(call, top, &summary)) {
  300. rxrpc_proto_abort("TXL", call, top);
  301. return false;
  302. }
  303. }
  304. if (!rxrpc_end_tx_phase(call, true, "ETD"))
  305. return false;
  306. call->tx_phase = false;
  307. return true;
  308. }
  309. /*
  310. * Scan a jumbo packet to validate its structure and to work out how many
  311. * subpackets it contains.
  312. *
  313. * A jumbo packet is a collection of consecutive packets glued together with
  314. * little headers between that indicate how to change the initial header for
  315. * each subpacket.
  316. *
  317. * RXRPC_JUMBO_PACKET must be set on all but the last subpacket - and all but
  318. * the last are RXRPC_JUMBO_DATALEN in size. The last subpacket may be of any
  319. * size.
  320. */
  321. static bool rxrpc_validate_jumbo(struct sk_buff *skb)
  322. {
  323. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  324. unsigned int offset = sizeof(struct rxrpc_wire_header);
  325. unsigned int len = skb->len;
  326. int nr_jumbo = 1;
  327. u8 flags = sp->hdr.flags;
  328. do {
  329. nr_jumbo++;
  330. if (len - offset < RXRPC_JUMBO_SUBPKTLEN)
  331. goto protocol_error;
  332. if (flags & RXRPC_LAST_PACKET)
  333. goto protocol_error;
  334. offset += RXRPC_JUMBO_DATALEN;
  335. if (skb_copy_bits(skb, offset, &flags, 1) < 0)
  336. goto protocol_error;
  337. offset += sizeof(struct rxrpc_jumbo_header);
  338. } while (flags & RXRPC_JUMBO_PACKET);
  339. sp->nr_jumbo = nr_jumbo;
  340. return true;
  341. protocol_error:
  342. return false;
  343. }
  344. /*
  345. * Handle reception of a duplicate packet.
  346. *
  347. * We have to take care to avoid an attack here whereby we're given a series of
  348. * jumbograms, each with a sequence number one before the preceding one and
  349. * filled up to maximum UDP size. If they never send us the first packet in
  350. * the sequence, they can cause us to have to hold on to around 2MiB of kernel
  351. * space until the call times out.
  352. *
  353. * We limit the space usage by only accepting three duplicate jumbo packets per
  354. * call. After that, we tell the other side we're no longer accepting jumbos
  355. * (that information is encoded in the ACK packet).
  356. */
  357. static void rxrpc_input_dup_data(struct rxrpc_call *call, rxrpc_seq_t seq,
  358. u8 annotation, bool *_jumbo_bad)
  359. {
  360. /* Discard normal packets that are duplicates. */
  361. if (annotation == 0)
  362. return;
  363. /* Skip jumbo subpackets that are duplicates. When we've had three or
  364. * more partially duplicate jumbo packets, we refuse to take any more
  365. * jumbos for this call.
  366. */
  367. if (!*_jumbo_bad) {
  368. call->nr_jumbo_bad++;
  369. *_jumbo_bad = true;
  370. }
  371. }
  372. /*
  373. * Process a DATA packet, adding the packet to the Rx ring.
  374. */
  375. static void rxrpc_input_data(struct rxrpc_call *call, struct sk_buff *skb,
  376. u16 skew)
  377. {
  378. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  379. unsigned int offset = sizeof(struct rxrpc_wire_header);
  380. unsigned int ix;
  381. rxrpc_serial_t serial = sp->hdr.serial, ack_serial = 0;
  382. rxrpc_seq_t seq = sp->hdr.seq, hard_ack;
  383. bool immediate_ack = false, jumbo_bad = false, queued;
  384. u16 len;
  385. u8 ack = 0, flags, annotation = 0;
  386. _enter("{%u,%u},{%u,%u}",
  387. call->rx_hard_ack, call->rx_top, skb->len, seq);
  388. _proto("Rx DATA %%%u { #%u f=%02x }",
  389. sp->hdr.serial, seq, sp->hdr.flags);
  390. if (call->state >= RXRPC_CALL_COMPLETE)
  391. return;
  392. /* Received data implicitly ACKs all of the request packets we sent
  393. * when we're acting as a client.
  394. */
  395. if ((call->state == RXRPC_CALL_CLIENT_SEND_REQUEST ||
  396. call->state == RXRPC_CALL_CLIENT_AWAIT_REPLY) &&
  397. !rxrpc_receiving_reply(call))
  398. return;
  399. call->ackr_prev_seq = seq;
  400. hard_ack = READ_ONCE(call->rx_hard_ack);
  401. if (after(seq, hard_ack + call->rx_winsize)) {
  402. ack = RXRPC_ACK_EXCEEDS_WINDOW;
  403. ack_serial = serial;
  404. goto ack;
  405. }
  406. flags = sp->hdr.flags;
  407. if (flags & RXRPC_JUMBO_PACKET) {
  408. if (call->nr_jumbo_bad > 3) {
  409. ack = RXRPC_ACK_NOSPACE;
  410. ack_serial = serial;
  411. goto ack;
  412. }
  413. annotation = 1;
  414. }
  415. next_subpacket:
  416. queued = false;
  417. ix = seq & RXRPC_RXTX_BUFF_MASK;
  418. len = skb->len;
  419. if (flags & RXRPC_JUMBO_PACKET)
  420. len = RXRPC_JUMBO_DATALEN;
  421. if (flags & RXRPC_LAST_PACKET) {
  422. if (test_bit(RXRPC_CALL_RX_LAST, &call->flags) &&
  423. seq != call->rx_top)
  424. return rxrpc_proto_abort("LSN", call, seq);
  425. } else {
  426. if (test_bit(RXRPC_CALL_RX_LAST, &call->flags) &&
  427. after_eq(seq, call->rx_top))
  428. return rxrpc_proto_abort("LSA", call, seq);
  429. }
  430. if (before_eq(seq, hard_ack)) {
  431. ack = RXRPC_ACK_DUPLICATE;
  432. ack_serial = serial;
  433. goto skip;
  434. }
  435. if (flags & RXRPC_REQUEST_ACK && !ack) {
  436. ack = RXRPC_ACK_REQUESTED;
  437. ack_serial = serial;
  438. }
  439. if (call->rxtx_buffer[ix]) {
  440. rxrpc_input_dup_data(call, seq, annotation, &jumbo_bad);
  441. if (ack != RXRPC_ACK_DUPLICATE) {
  442. ack = RXRPC_ACK_DUPLICATE;
  443. ack_serial = serial;
  444. }
  445. immediate_ack = true;
  446. goto skip;
  447. }
  448. /* Queue the packet. We use a couple of memory barriers here as need
  449. * to make sure that rx_top is perceived to be set after the buffer
  450. * pointer and that the buffer pointer is set after the annotation and
  451. * the skb data.
  452. *
  453. * Barriers against rxrpc_recvmsg_data() and rxrpc_rotate_rx_window()
  454. * and also rxrpc_fill_out_ack().
  455. */
  456. rxrpc_get_skb(skb, rxrpc_skb_rx_got);
  457. call->rxtx_annotations[ix] = annotation;
  458. smp_wmb();
  459. call->rxtx_buffer[ix] = skb;
  460. if (after(seq, call->rx_top)) {
  461. smp_store_release(&call->rx_top, seq);
  462. } else if (before(seq, call->rx_top)) {
  463. /* Send an immediate ACK if we fill in a hole */
  464. if (!ack) {
  465. ack = RXRPC_ACK_DELAY;
  466. ack_serial = serial;
  467. }
  468. immediate_ack = true;
  469. }
  470. if (flags & RXRPC_LAST_PACKET) {
  471. set_bit(RXRPC_CALL_RX_LAST, &call->flags);
  472. trace_rxrpc_receive(call, rxrpc_receive_queue_last, serial, seq);
  473. } else {
  474. trace_rxrpc_receive(call, rxrpc_receive_queue, serial, seq);
  475. }
  476. queued = true;
  477. if (after_eq(seq, call->rx_expect_next)) {
  478. if (after(seq, call->rx_expect_next)) {
  479. _net("OOS %u > %u", seq, call->rx_expect_next);
  480. ack = RXRPC_ACK_OUT_OF_SEQUENCE;
  481. ack_serial = serial;
  482. }
  483. call->rx_expect_next = seq + 1;
  484. }
  485. skip:
  486. offset += len;
  487. if (flags & RXRPC_JUMBO_PACKET) {
  488. if (skb_copy_bits(skb, offset, &flags, 1) < 0)
  489. return rxrpc_proto_abort("XJF", call, seq);
  490. offset += sizeof(struct rxrpc_jumbo_header);
  491. seq++;
  492. serial++;
  493. annotation++;
  494. if (flags & RXRPC_JUMBO_PACKET)
  495. annotation |= RXRPC_RX_ANNO_JLAST;
  496. if (after(seq, hard_ack + call->rx_winsize)) {
  497. ack = RXRPC_ACK_EXCEEDS_WINDOW;
  498. ack_serial = serial;
  499. if (!jumbo_bad) {
  500. call->nr_jumbo_bad++;
  501. jumbo_bad = true;
  502. }
  503. goto ack;
  504. }
  505. _proto("Rx DATA Jumbo %%%u", serial);
  506. goto next_subpacket;
  507. }
  508. if (queued && flags & RXRPC_LAST_PACKET && !ack) {
  509. ack = RXRPC_ACK_DELAY;
  510. ack_serial = serial;
  511. }
  512. ack:
  513. if (ack)
  514. rxrpc_propose_ACK(call, ack, skew, ack_serial,
  515. immediate_ack, true,
  516. rxrpc_propose_ack_input_data);
  517. if (sp->hdr.seq == READ_ONCE(call->rx_hard_ack) + 1)
  518. rxrpc_notify_socket(call);
  519. _leave(" [queued]");
  520. }
  521. /*
  522. * Process a requested ACK.
  523. */
  524. static void rxrpc_input_requested_ack(struct rxrpc_call *call,
  525. ktime_t resp_time,
  526. rxrpc_serial_t orig_serial,
  527. rxrpc_serial_t ack_serial)
  528. {
  529. struct rxrpc_skb_priv *sp;
  530. struct sk_buff *skb;
  531. ktime_t sent_at;
  532. int ix;
  533. for (ix = 0; ix < RXRPC_RXTX_BUFF_SIZE; ix++) {
  534. skb = call->rxtx_buffer[ix];
  535. if (!skb)
  536. continue;
  537. sp = rxrpc_skb(skb);
  538. if (sp->hdr.serial != orig_serial)
  539. continue;
  540. smp_rmb();
  541. sent_at = skb->tstamp;
  542. goto found;
  543. }
  544. return;
  545. found:
  546. rxrpc_peer_add_rtt(call, rxrpc_rtt_rx_requested_ack,
  547. orig_serial, ack_serial, sent_at, resp_time);
  548. }
  549. /*
  550. * Process a ping response.
  551. */
  552. static void rxrpc_input_ping_response(struct rxrpc_call *call,
  553. ktime_t resp_time,
  554. rxrpc_serial_t orig_serial,
  555. rxrpc_serial_t ack_serial)
  556. {
  557. rxrpc_serial_t ping_serial;
  558. ktime_t ping_time;
  559. ping_time = call->ping_time;
  560. smp_rmb();
  561. ping_serial = call->ping_serial;
  562. if (!test_bit(RXRPC_CALL_PINGING, &call->flags) ||
  563. before(orig_serial, ping_serial))
  564. return;
  565. clear_bit(RXRPC_CALL_PINGING, &call->flags);
  566. if (after(orig_serial, ping_serial))
  567. return;
  568. rxrpc_peer_add_rtt(call, rxrpc_rtt_rx_ping_response,
  569. orig_serial, ack_serial, ping_time, resp_time);
  570. }
  571. /*
  572. * Process the extra information that may be appended to an ACK packet
  573. */
  574. static void rxrpc_input_ackinfo(struct rxrpc_call *call, struct sk_buff *skb,
  575. struct rxrpc_ackinfo *ackinfo)
  576. {
  577. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  578. struct rxrpc_peer *peer;
  579. unsigned int mtu;
  580. bool wake = false;
  581. u32 rwind = ntohl(ackinfo->rwind);
  582. _proto("Rx ACK %%%u Info { rx=%u max=%u rwin=%u jm=%u }",
  583. sp->hdr.serial,
  584. ntohl(ackinfo->rxMTU), ntohl(ackinfo->maxMTU),
  585. rwind, ntohl(ackinfo->jumbo_max));
  586. if (call->tx_winsize != rwind) {
  587. if (rwind > RXRPC_RXTX_BUFF_SIZE - 1)
  588. rwind = RXRPC_RXTX_BUFF_SIZE - 1;
  589. if (rwind > call->tx_winsize)
  590. wake = true;
  591. call->tx_winsize = rwind;
  592. }
  593. if (call->cong_ssthresh > rwind)
  594. call->cong_ssthresh = rwind;
  595. mtu = min(ntohl(ackinfo->rxMTU), ntohl(ackinfo->maxMTU));
  596. peer = call->peer;
  597. if (mtu < peer->maxdata) {
  598. spin_lock_bh(&peer->lock);
  599. peer->maxdata = mtu;
  600. peer->mtu = mtu + peer->hdrsize;
  601. spin_unlock_bh(&peer->lock);
  602. _net("Net MTU %u (maxdata %u)", peer->mtu, peer->maxdata);
  603. }
  604. if (wake)
  605. wake_up(&call->waitq);
  606. }
  607. /*
  608. * Process individual soft ACKs.
  609. *
  610. * Each ACK in the array corresponds to one packet and can be either an ACK or
  611. * a NAK. If we get find an explicitly NAK'd packet we resend immediately;
  612. * packets that lie beyond the end of the ACK list are scheduled for resend by
  613. * the timer on the basis that the peer might just not have processed them at
  614. * the time the ACK was sent.
  615. */
  616. static void rxrpc_input_soft_acks(struct rxrpc_call *call, u8 *acks,
  617. rxrpc_seq_t seq, int nr_acks,
  618. struct rxrpc_ack_summary *summary)
  619. {
  620. int ix;
  621. u8 annotation, anno_type;
  622. for (; nr_acks > 0; nr_acks--, seq++) {
  623. ix = seq & RXRPC_RXTX_BUFF_MASK;
  624. annotation = call->rxtx_annotations[ix];
  625. anno_type = annotation & RXRPC_TX_ANNO_MASK;
  626. annotation &= ~RXRPC_TX_ANNO_MASK;
  627. switch (*acks++) {
  628. case RXRPC_ACK_TYPE_ACK:
  629. summary->nr_acks++;
  630. if (anno_type == RXRPC_TX_ANNO_ACK)
  631. continue;
  632. summary->nr_new_acks++;
  633. call->rxtx_annotations[ix] =
  634. RXRPC_TX_ANNO_ACK | annotation;
  635. break;
  636. case RXRPC_ACK_TYPE_NACK:
  637. if (!summary->nr_nacks &&
  638. call->acks_lowest_nak != seq) {
  639. call->acks_lowest_nak = seq;
  640. summary->new_low_nack = true;
  641. }
  642. summary->nr_nacks++;
  643. if (anno_type == RXRPC_TX_ANNO_NAK)
  644. continue;
  645. summary->nr_new_nacks++;
  646. if (anno_type == RXRPC_TX_ANNO_RETRANS)
  647. continue;
  648. call->rxtx_annotations[ix] =
  649. RXRPC_TX_ANNO_NAK | annotation;
  650. break;
  651. default:
  652. return rxrpc_proto_abort("SFT", call, 0);
  653. }
  654. }
  655. }
  656. /*
  657. * Process an ACK packet.
  658. *
  659. * ack.firstPacket is the sequence number of the first soft-ACK'd/NAK'd packet
  660. * in the ACK array. Anything before that is hard-ACK'd and may be discarded.
  661. *
  662. * A hard-ACK means that a packet has been processed and may be discarded; a
  663. * soft-ACK means that the packet may be discarded and retransmission
  664. * requested. A phase is complete when all packets are hard-ACK'd.
  665. */
  666. static void rxrpc_input_ack(struct rxrpc_call *call, struct sk_buff *skb,
  667. u16 skew)
  668. {
  669. struct rxrpc_ack_summary summary = { 0 };
  670. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  671. union {
  672. struct rxrpc_ackpacket ack;
  673. struct rxrpc_ackinfo info;
  674. u8 acks[RXRPC_MAXACKS];
  675. } buf;
  676. rxrpc_serial_t acked_serial;
  677. rxrpc_seq_t first_soft_ack, hard_ack;
  678. int nr_acks, offset, ioffset;
  679. _enter("");
  680. offset = sizeof(struct rxrpc_wire_header);
  681. if (skb_copy_bits(skb, offset, &buf.ack, sizeof(buf.ack)) < 0) {
  682. _debug("extraction failure");
  683. return rxrpc_proto_abort("XAK", call, 0);
  684. }
  685. offset += sizeof(buf.ack);
  686. acked_serial = ntohl(buf.ack.serial);
  687. first_soft_ack = ntohl(buf.ack.firstPacket);
  688. hard_ack = first_soft_ack - 1;
  689. nr_acks = buf.ack.nAcks;
  690. summary.ack_reason = (buf.ack.reason < RXRPC_ACK__INVALID ?
  691. buf.ack.reason : RXRPC_ACK__INVALID);
  692. trace_rxrpc_rx_ack(call, first_soft_ack, summary.ack_reason, nr_acks);
  693. _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
  694. sp->hdr.serial,
  695. ntohs(buf.ack.maxSkew),
  696. first_soft_ack,
  697. ntohl(buf.ack.previousPacket),
  698. acked_serial,
  699. rxrpc_ack_names[summary.ack_reason],
  700. buf.ack.nAcks);
  701. if (buf.ack.reason == RXRPC_ACK_PING_RESPONSE)
  702. rxrpc_input_ping_response(call, skb->tstamp, acked_serial,
  703. sp->hdr.serial);
  704. if (buf.ack.reason == RXRPC_ACK_REQUESTED)
  705. rxrpc_input_requested_ack(call, skb->tstamp, acked_serial,
  706. sp->hdr.serial);
  707. if (buf.ack.reason == RXRPC_ACK_PING) {
  708. _proto("Rx ACK %%%u PING Request", sp->hdr.serial);
  709. rxrpc_propose_ACK(call, RXRPC_ACK_PING_RESPONSE,
  710. skew, sp->hdr.serial, true, true,
  711. rxrpc_propose_ack_respond_to_ping);
  712. } else if (sp->hdr.flags & RXRPC_REQUEST_ACK) {
  713. rxrpc_propose_ACK(call, RXRPC_ACK_REQUESTED,
  714. skew, sp->hdr.serial, true, true,
  715. rxrpc_propose_ack_respond_to_ack);
  716. }
  717. /* Discard any out-of-order or duplicate ACKs. */
  718. if (before_eq(sp->hdr.serial, call->acks_latest)) {
  719. _debug("discard ACK %d <= %d",
  720. sp->hdr.serial, call->acks_latest);
  721. return;
  722. }
  723. call->acks_latest_ts = skb->tstamp;
  724. call->acks_latest = sp->hdr.serial;
  725. /* Parse rwind and mtu sizes if provided. */
  726. ioffset = offset + nr_acks + 3;
  727. if (skb->len >= ioffset + sizeof(buf.info)) {
  728. if (skb_copy_bits(skb, ioffset, &buf.info, sizeof(buf.info)) < 0)
  729. return rxrpc_proto_abort("XAI", call, 0);
  730. rxrpc_input_ackinfo(call, skb, &buf.info);
  731. }
  732. if (first_soft_ack == 0)
  733. return rxrpc_proto_abort("AK0", call, 0);
  734. /* Ignore ACKs unless we are or have just been transmitting. */
  735. switch (call->state) {
  736. case RXRPC_CALL_CLIENT_SEND_REQUEST:
  737. case RXRPC_CALL_CLIENT_AWAIT_REPLY:
  738. case RXRPC_CALL_SERVER_SEND_REPLY:
  739. case RXRPC_CALL_SERVER_AWAIT_ACK:
  740. break;
  741. default:
  742. return;
  743. }
  744. if (before(hard_ack, call->tx_hard_ack) ||
  745. after(hard_ack, call->tx_top))
  746. return rxrpc_proto_abort("AKW", call, 0);
  747. if (nr_acks > call->tx_top - hard_ack)
  748. return rxrpc_proto_abort("AKN", call, 0);
  749. if (after(hard_ack, call->tx_hard_ack)) {
  750. if (rxrpc_rotate_tx_window(call, hard_ack, &summary)) {
  751. rxrpc_end_tx_phase(call, false, "ETA");
  752. return;
  753. }
  754. }
  755. if (nr_acks > 0) {
  756. if (skb_copy_bits(skb, offset, buf.acks, nr_acks) < 0)
  757. return rxrpc_proto_abort("XSA", call, 0);
  758. rxrpc_input_soft_acks(call, buf.acks, first_soft_ack, nr_acks,
  759. &summary);
  760. }
  761. if (call->rxtx_annotations[call->tx_top & RXRPC_RXTX_BUFF_MASK] &
  762. RXRPC_TX_ANNO_LAST &&
  763. summary.nr_acks == call->tx_top - hard_ack &&
  764. rxrpc_is_client_call(call))
  765. rxrpc_propose_ACK(call, RXRPC_ACK_PING, skew, sp->hdr.serial,
  766. false, true,
  767. rxrpc_propose_ack_ping_for_lost_reply);
  768. return rxrpc_congestion_management(call, skb, &summary, acked_serial);
  769. }
  770. /*
  771. * Process an ACKALL packet.
  772. */
  773. static void rxrpc_input_ackall(struct rxrpc_call *call, struct sk_buff *skb)
  774. {
  775. struct rxrpc_ack_summary summary = { 0 };
  776. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  777. _proto("Rx ACKALL %%%u", sp->hdr.serial);
  778. if (rxrpc_rotate_tx_window(call, call->tx_top, &summary))
  779. rxrpc_end_tx_phase(call, false, "ETL");
  780. }
  781. /*
  782. * Process an ABORT packet.
  783. */
  784. static void rxrpc_input_abort(struct rxrpc_call *call, struct sk_buff *skb)
  785. {
  786. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  787. __be32 wtmp;
  788. u32 abort_code = RX_CALL_DEAD;
  789. _enter("");
  790. if (skb->len >= 4 &&
  791. skb_copy_bits(skb, sizeof(struct rxrpc_wire_header),
  792. &wtmp, sizeof(wtmp)) >= 0)
  793. abort_code = ntohl(wtmp);
  794. _proto("Rx ABORT %%%u { %x }", sp->hdr.serial, abort_code);
  795. if (rxrpc_set_call_completion(call, RXRPC_CALL_REMOTELY_ABORTED,
  796. abort_code, ECONNABORTED))
  797. rxrpc_notify_socket(call);
  798. }
  799. /*
  800. * Process an incoming call packet.
  801. */
  802. static void rxrpc_input_call_packet(struct rxrpc_call *call,
  803. struct sk_buff *skb, u16 skew)
  804. {
  805. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  806. _enter("%p,%p", call, skb);
  807. switch (sp->hdr.type) {
  808. case RXRPC_PACKET_TYPE_DATA:
  809. rxrpc_input_data(call, skb, skew);
  810. break;
  811. case RXRPC_PACKET_TYPE_ACK:
  812. rxrpc_input_ack(call, skb, skew);
  813. break;
  814. case RXRPC_PACKET_TYPE_BUSY:
  815. _proto("Rx BUSY %%%u", sp->hdr.serial);
  816. /* Just ignore BUSY packets from the server; the retry and
  817. * lifespan timers will take care of business. BUSY packets
  818. * from the client don't make sense.
  819. */
  820. break;
  821. case RXRPC_PACKET_TYPE_ABORT:
  822. rxrpc_input_abort(call, skb);
  823. break;
  824. case RXRPC_PACKET_TYPE_ACKALL:
  825. rxrpc_input_ackall(call, skb);
  826. break;
  827. default:
  828. _proto("Rx %s %%%u", rxrpc_pkts[sp->hdr.type], sp->hdr.serial);
  829. break;
  830. }
  831. _leave("");
  832. }
  833. /*
  834. * Handle a new call on a channel implicitly completing the preceding call on
  835. * that channel.
  836. *
  837. * TODO: If callNumber > call_id + 1, renegotiate security.
  838. */
  839. static void rxrpc_input_implicit_end_call(struct rxrpc_connection *conn,
  840. struct rxrpc_call *call)
  841. {
  842. switch (call->state) {
  843. case RXRPC_CALL_SERVER_AWAIT_ACK:
  844. rxrpc_call_completed(call);
  845. break;
  846. case RXRPC_CALL_COMPLETE:
  847. break;
  848. default:
  849. if (rxrpc_abort_call("IMP", call, 0, RX_CALL_DEAD, ESHUTDOWN)) {
  850. set_bit(RXRPC_CALL_EV_ABORT, &call->events);
  851. rxrpc_queue_call(call);
  852. }
  853. break;
  854. }
  855. __rxrpc_disconnect_call(conn, call);
  856. rxrpc_notify_socket(call);
  857. }
  858. /*
  859. * post connection-level events to the connection
  860. * - this includes challenges, responses, some aborts and call terminal packet
  861. * retransmission.
  862. */
  863. static void rxrpc_post_packet_to_conn(struct rxrpc_connection *conn,
  864. struct sk_buff *skb)
  865. {
  866. _enter("%p,%p", conn, skb);
  867. skb_queue_tail(&conn->rx_queue, skb);
  868. rxrpc_queue_conn(conn);
  869. }
  870. /*
  871. * post endpoint-level events to the local endpoint
  872. * - this includes debug and version messages
  873. */
  874. static void rxrpc_post_packet_to_local(struct rxrpc_local *local,
  875. struct sk_buff *skb)
  876. {
  877. _enter("%p,%p", local, skb);
  878. skb_queue_tail(&local->event_queue, skb);
  879. rxrpc_queue_local(local);
  880. }
  881. /*
  882. * put a packet up for transport-level abort
  883. */
  884. static void rxrpc_reject_packet(struct rxrpc_local *local, struct sk_buff *skb)
  885. {
  886. CHECK_SLAB_OKAY(&local->usage);
  887. skb_queue_tail(&local->reject_queue, skb);
  888. rxrpc_queue_local(local);
  889. }
  890. /*
  891. * Extract the wire header from a packet and translate the byte order.
  892. */
  893. static noinline
  894. int rxrpc_extract_header(struct rxrpc_skb_priv *sp, struct sk_buff *skb)
  895. {
  896. struct rxrpc_wire_header whdr;
  897. /* dig out the RxRPC connection details */
  898. if (skb_copy_bits(skb, 0, &whdr, sizeof(whdr)) < 0)
  899. return -EBADMSG;
  900. memset(sp, 0, sizeof(*sp));
  901. sp->hdr.epoch = ntohl(whdr.epoch);
  902. sp->hdr.cid = ntohl(whdr.cid);
  903. sp->hdr.callNumber = ntohl(whdr.callNumber);
  904. sp->hdr.seq = ntohl(whdr.seq);
  905. sp->hdr.serial = ntohl(whdr.serial);
  906. sp->hdr.flags = whdr.flags;
  907. sp->hdr.type = whdr.type;
  908. sp->hdr.userStatus = whdr.userStatus;
  909. sp->hdr.securityIndex = whdr.securityIndex;
  910. sp->hdr._rsvd = ntohs(whdr._rsvd);
  911. sp->hdr.serviceId = ntohs(whdr.serviceId);
  912. return 0;
  913. }
  914. /*
  915. * handle data received on the local endpoint
  916. * - may be called in interrupt context
  917. *
  918. * The socket is locked by the caller and this prevents the socket from being
  919. * shut down and the local endpoint from going away, thus sk_user_data will not
  920. * be cleared until this function returns.
  921. */
  922. void rxrpc_data_ready(struct sock *udp_sk)
  923. {
  924. struct rxrpc_connection *conn;
  925. struct rxrpc_channel *chan;
  926. struct rxrpc_call *call;
  927. struct rxrpc_skb_priv *sp;
  928. struct rxrpc_local *local = udp_sk->sk_user_data;
  929. struct sk_buff *skb;
  930. unsigned int channel;
  931. int ret, skew;
  932. _enter("%p", udp_sk);
  933. ASSERT(!irqs_disabled());
  934. skb = skb_recv_datagram(udp_sk, 0, 1, &ret);
  935. if (!skb) {
  936. if (ret == -EAGAIN)
  937. return;
  938. _debug("UDP socket error %d", ret);
  939. return;
  940. }
  941. rxrpc_new_skb(skb, rxrpc_skb_rx_received);
  942. _net("recv skb %p", skb);
  943. /* we'll probably need to checksum it (didn't call sock_recvmsg) */
  944. if (skb_checksum_complete(skb)) {
  945. rxrpc_free_skb(skb, rxrpc_skb_rx_freed);
  946. __UDP_INC_STATS(&init_net, UDP_MIB_INERRORS, 0);
  947. _leave(" [CSUM failed]");
  948. return;
  949. }
  950. __UDP_INC_STATS(&init_net, UDP_MIB_INDATAGRAMS, 0);
  951. /* The socket buffer we have is owned by UDP, with UDP's data all over
  952. * it, but we really want our own data there.
  953. */
  954. skb_orphan(skb);
  955. sp = rxrpc_skb(skb);
  956. /* dig out the RxRPC connection details */
  957. if (rxrpc_extract_header(sp, skb) < 0)
  958. goto bad_message;
  959. if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) {
  960. static int lose;
  961. if ((lose++ & 7) == 7) {
  962. trace_rxrpc_rx_lose(sp);
  963. rxrpc_lose_skb(skb, rxrpc_skb_rx_lost);
  964. return;
  965. }
  966. }
  967. trace_rxrpc_rx_packet(sp);
  968. _net("Rx RxRPC %s ep=%x call=%x:%x",
  969. sp->hdr.flags & RXRPC_CLIENT_INITIATED ? "ToServer" : "ToClient",
  970. sp->hdr.epoch, sp->hdr.cid, sp->hdr.callNumber);
  971. if (sp->hdr.type >= RXRPC_N_PACKET_TYPES ||
  972. !((RXRPC_SUPPORTED_PACKET_TYPES >> sp->hdr.type) & 1)) {
  973. _proto("Rx Bad Packet Type %u", sp->hdr.type);
  974. goto bad_message;
  975. }
  976. switch (sp->hdr.type) {
  977. case RXRPC_PACKET_TYPE_VERSION:
  978. rxrpc_post_packet_to_local(local, skb);
  979. goto out;
  980. case RXRPC_PACKET_TYPE_BUSY:
  981. if (sp->hdr.flags & RXRPC_CLIENT_INITIATED)
  982. goto discard;
  983. case RXRPC_PACKET_TYPE_DATA:
  984. if (sp->hdr.callNumber == 0)
  985. goto bad_message;
  986. if (sp->hdr.flags & RXRPC_JUMBO_PACKET &&
  987. !rxrpc_validate_jumbo(skb))
  988. goto bad_message;
  989. break;
  990. }
  991. rcu_read_lock();
  992. conn = rxrpc_find_connection_rcu(local, skb);
  993. if (conn) {
  994. if (sp->hdr.securityIndex != conn->security_ix)
  995. goto wrong_security;
  996. if (sp->hdr.callNumber == 0) {
  997. /* Connection-level packet */
  998. _debug("CONN %p {%d}", conn, conn->debug_id);
  999. rxrpc_post_packet_to_conn(conn, skb);
  1000. goto out_unlock;
  1001. }
  1002. /* Note the serial number skew here */
  1003. skew = (int)sp->hdr.serial - (int)conn->hi_serial;
  1004. if (skew >= 0) {
  1005. if (skew > 0)
  1006. conn->hi_serial = sp->hdr.serial;
  1007. } else {
  1008. skew = -skew;
  1009. skew = min(skew, 65535);
  1010. }
  1011. /* Call-bound packets are routed by connection channel. */
  1012. channel = sp->hdr.cid & RXRPC_CHANNELMASK;
  1013. chan = &conn->channels[channel];
  1014. /* Ignore really old calls */
  1015. if (sp->hdr.callNumber < chan->last_call)
  1016. goto discard_unlock;
  1017. if (sp->hdr.callNumber == chan->last_call) {
  1018. if (chan->call ||
  1019. sp->hdr.type == RXRPC_PACKET_TYPE_ABORT)
  1020. goto discard_unlock;
  1021. /* For the previous service call, if completed
  1022. * successfully, we discard all further packets.
  1023. */
  1024. if (rxrpc_conn_is_service(conn) &&
  1025. chan->last_type == RXRPC_PACKET_TYPE_ACK)
  1026. goto discard_unlock;
  1027. /* But otherwise we need to retransmit the final packet
  1028. * from data cached in the connection record.
  1029. */
  1030. rxrpc_post_packet_to_conn(conn, skb);
  1031. goto out_unlock;
  1032. }
  1033. call = rcu_dereference(chan->call);
  1034. if (sp->hdr.callNumber > chan->call_id) {
  1035. if (!(sp->hdr.flags & RXRPC_CLIENT_INITIATED)) {
  1036. rcu_read_unlock();
  1037. goto reject_packet;
  1038. }
  1039. if (call)
  1040. rxrpc_input_implicit_end_call(conn, call);
  1041. call = NULL;
  1042. }
  1043. } else {
  1044. skew = 0;
  1045. call = NULL;
  1046. }
  1047. if (!call || atomic_read(&call->usage) == 0) {
  1048. if (!(sp->hdr.type & RXRPC_CLIENT_INITIATED) ||
  1049. sp->hdr.callNumber == 0 ||
  1050. sp->hdr.type != RXRPC_PACKET_TYPE_DATA)
  1051. goto bad_message_unlock;
  1052. if (sp->hdr.seq != 1)
  1053. goto discard_unlock;
  1054. call = rxrpc_new_incoming_call(local, conn, skb);
  1055. if (!call) {
  1056. rcu_read_unlock();
  1057. goto reject_packet;
  1058. }
  1059. rxrpc_send_ping(call, skb, skew);
  1060. }
  1061. rxrpc_input_call_packet(call, skb, skew);
  1062. goto discard_unlock;
  1063. discard_unlock:
  1064. rcu_read_unlock();
  1065. discard:
  1066. rxrpc_free_skb(skb, rxrpc_skb_rx_freed);
  1067. out:
  1068. trace_rxrpc_rx_done(0, 0);
  1069. return;
  1070. out_unlock:
  1071. rcu_read_unlock();
  1072. goto out;
  1073. wrong_security:
  1074. rcu_read_unlock();
  1075. trace_rxrpc_abort("SEC", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq,
  1076. RXKADINCONSISTENCY, EBADMSG);
  1077. skb->priority = RXKADINCONSISTENCY;
  1078. goto post_abort;
  1079. bad_message_unlock:
  1080. rcu_read_unlock();
  1081. bad_message:
  1082. trace_rxrpc_abort("BAD", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq,
  1083. RX_PROTOCOL_ERROR, EBADMSG);
  1084. skb->priority = RX_PROTOCOL_ERROR;
  1085. post_abort:
  1086. skb->mark = RXRPC_SKB_MARK_LOCAL_ABORT;
  1087. reject_packet:
  1088. trace_rxrpc_rx_done(skb->mark, skb->priority);
  1089. rxrpc_reject_packet(local, skb);
  1090. _leave(" [badmsg]");
  1091. }