input.c 32 KB

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