blob: 349698d87ad1894b5ed57bc6c259a112580e3b5d [file] [log] [blame]
David Howells17926a72007-04-26 15:48:28 -07001/* RxRPC packet reception
2 *
David Howells248f2192016-09-08 11:10:12 +01003 * Copyright (C) 2007, 2016 Red Hat, Inc. All Rights Reserved.
David Howells17926a72007-04-26 15:48:28 -07004 * 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
Joe Perches9b6d5392016-06-02 12:08:52 -070012#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
David Howells17926a72007-04-26 15:48:28 -070014#include <linux/module.h>
15#include <linux/net.h>
16#include <linux/skbuff.h>
17#include <linux/errqueue.h>
18#include <linux/udp.h>
19#include <linux/in.h>
20#include <linux/in6.h>
21#include <linux/icmp.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/gfp.h>
David Howells17926a72007-04-26 15:48:28 -070023#include <net/sock.h>
24#include <net/af_rxrpc.h>
25#include <net/ip.h>
Herbert Xu1781f7f2007-12-11 11:30:32 -080026#include <net/udp.h>
Pavel Emelyanov02833282008-07-05 21:18:48 -070027#include <net/net_namespace.h>
David Howells17926a72007-04-26 15:48:28 -070028#include "ar-internal.h"
29
David Howells248f2192016-09-08 11:10:12 +010030static void rxrpc_proto_abort(const char *why,
31 struct rxrpc_call *call, rxrpc_seq_t seq)
David Howells17926a72007-04-26 15:48:28 -070032{
David Howells248f2192016-09-08 11:10:12 +010033 if (rxrpc_abort_call(why, call, seq, RX_PROTOCOL_ERROR, EBADMSG)) {
34 set_bit(RXRPC_CALL_EV_ABORT, &call->events);
35 rxrpc_queue_call(call);
David Howells17926a72007-04-26 15:48:28 -070036 }
David Howells17926a72007-04-26 15:48:28 -070037}
38
39/*
David Howells8e831342016-09-22 00:29:31 +010040 * Ping the other end to fill our RTT cache and to retrieve the rwind
41 * and MTU parameters.
42 */
43static void rxrpc_send_ping(struct rxrpc_call *call, struct sk_buff *skb,
44 int skew)
45{
46 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
David Howellsfc943f62016-09-22 00:29:32 +010047 ktime_t now = skb->tstamp;
David Howells8e831342016-09-22 00:29:31 +010048
David Howellsfc943f62016-09-22 00:29:32 +010049 if (call->peer->rtt_usage < 3 ||
50 ktime_before(ktime_add_ms(call->peer->rtt_last_req, 1000), now))
51 rxrpc_propose_ACK(call, RXRPC_ACK_PING, skew, sp->hdr.serial,
David Howells9c7ad432016-09-23 13:50:40 +010052 true, true,
53 rxrpc_propose_ack_ping_for_params);
David Howells8e831342016-09-22 00:29:31 +010054}
55
56/*
David Howells248f2192016-09-08 11:10:12 +010057 * Apply a hard ACK by advancing the Tx window.
David Howells17926a72007-04-26 15:48:28 -070058 */
David Howells248f2192016-09-08 11:10:12 +010059static void rxrpc_rotate_tx_window(struct rxrpc_call *call, rxrpc_seq_t to)
David Howells17926a72007-04-26 15:48:28 -070060{
David Howells248f2192016-09-08 11:10:12 +010061 struct sk_buff *skb, *list = NULL;
62 int ix;
David Howells70790db2016-09-23 12:39:22 +010063 u8 annotation;
David Howells17926a72007-04-26 15:48:28 -070064
65 spin_lock(&call->lock);
66
David Howells248f2192016-09-08 11:10:12 +010067 while (before(call->tx_hard_ack, to)) {
68 call->tx_hard_ack++;
69 ix = call->tx_hard_ack & RXRPC_RXTX_BUFF_MASK;
70 skb = call->rxtx_buffer[ix];
David Howells70790db2016-09-23 12:39:22 +010071 annotation = call->rxtx_annotations[ix];
David Howells71f3ca42016-09-17 10:49:14 +010072 rxrpc_see_skb(skb, rxrpc_skb_tx_rotated);
David Howells248f2192016-09-08 11:10:12 +010073 call->rxtx_buffer[ix] = NULL;
74 call->rxtx_annotations[ix] = 0;
75 skb->next = list;
76 list = skb;
David Howells70790db2016-09-23 12:39:22 +010077
78 if (annotation & RXRPC_TX_ANNO_LAST)
79 set_bit(RXRPC_CALL_TX_LAST, &call->flags);
David Howells17926a72007-04-26 15:48:28 -070080 }
81
82 spin_unlock(&call->lock);
David Howells17926a72007-04-26 15:48:28 -070083
David Howells70790db2016-09-23 12:39:22 +010084 trace_rxrpc_transmit(call, (test_bit(RXRPC_CALL_TX_LAST, &call->flags) ?
85 rxrpc_transmit_rotate_last :
86 rxrpc_transmit_rotate));
David Howellsbc4abfc2016-09-13 22:36:21 +010087 wake_up(&call->waitq);
88
David Howells248f2192016-09-08 11:10:12 +010089 while (list) {
90 skb = list;
91 list = skb->next;
92 skb->next = NULL;
David Howells71f3ca42016-09-17 10:49:14 +010093 rxrpc_free_skb(skb, rxrpc_skb_tx_freed);
David Howells248f2192016-09-08 11:10:12 +010094 }
David Howells17926a72007-04-26 15:48:28 -070095}
96
97/*
David Howells248f2192016-09-08 11:10:12 +010098 * End the transmission phase of a call.
99 *
100 * This occurs when we get an ACKALL packet, the first DATA packet of a reply,
101 * or a final ACK packet.
David Howells17926a72007-04-26 15:48:28 -0700102 */
David Howells70790db2016-09-23 12:39:22 +0100103static bool rxrpc_end_tx_phase(struct rxrpc_call *call, bool reply_begun,
104 const char *abort_why)
David Howells17926a72007-04-26 15:48:28 -0700105{
David Howells17926a72007-04-26 15:48:28 -0700106
David Howells70790db2016-09-23 12:39:22 +0100107 ASSERT(test_bit(RXRPC_CALL_TX_LAST, &call->flags));
David Howells248f2192016-09-08 11:10:12 +0100108
109 write_lock(&call->state_lock);
110
111 switch (call->state) {
David Howells70790db2016-09-23 12:39:22 +0100112 case RXRPC_CALL_CLIENT_SEND_REQUEST:
David Howells17926a72007-04-26 15:48:28 -0700113 case RXRPC_CALL_CLIENT_AWAIT_REPLY:
David Howells70790db2016-09-23 12:39:22 +0100114 if (reply_begun)
115 call->state = RXRPC_CALL_CLIENT_RECV_REPLY;
116 else
117 call->state = RXRPC_CALL_CLIENT_AWAIT_REPLY;
David Howells17926a72007-04-26 15:48:28 -0700118 break;
David Howells70790db2016-09-23 12:39:22 +0100119
David Howells248f2192016-09-08 11:10:12 +0100120 case RXRPC_CALL_SERVER_AWAIT_ACK:
121 __rxrpc_call_completed(call);
122 rxrpc_notify_socket(call);
David Howells17926a72007-04-26 15:48:28 -0700123 break;
David Howells70790db2016-09-23 12:39:22 +0100124
125 default:
126 goto bad_state;
David Howells17926a72007-04-26 15:48:28 -0700127 }
David Howells248f2192016-09-08 11:10:12 +0100128
129 write_unlock(&call->state_lock);
David Howells70790db2016-09-23 12:39:22 +0100130 if (call->state == RXRPC_CALL_CLIENT_AWAIT_REPLY) {
131 trace_rxrpc_transmit(call, rxrpc_transmit_await_reply);
132 } else {
133 trace_rxrpc_transmit(call, rxrpc_transmit_end);
134 }
David Howells248f2192016-09-08 11:10:12 +0100135 _leave(" = ok");
136 return true;
David Howells70790db2016-09-23 12:39:22 +0100137
138bad_state:
139 write_unlock(&call->state_lock);
140 kdebug("end_tx %s", rxrpc_call_states[call->state]);
141 rxrpc_proto_abort(abort_why, call, call->tx_top);
142 return false;
143}
144
145/*
146 * Begin the reply reception phase of a call.
147 */
148static bool rxrpc_receiving_reply(struct rxrpc_call *call)
149{
150 rxrpc_seq_t top = READ_ONCE(call->tx_top);
151
152 if (!test_bit(RXRPC_CALL_TX_LAST, &call->flags))
153 rxrpc_rotate_tx_window(call, top);
154 if (!test_bit(RXRPC_CALL_TX_LAST, &call->flags)) {
155 rxrpc_proto_abort("TXL", call, top);
156 return false;
157 }
158 if (!rxrpc_end_tx_phase(call, true, "ETD"))
159 return false;
160 call->tx_phase = false;
161 return true;
David Howells248f2192016-09-08 11:10:12 +0100162}
163
164/*
165 * Scan a jumbo packet to validate its structure and to work out how many
166 * subpackets it contains.
167 *
168 * A jumbo packet is a collection of consecutive packets glued together with
169 * little headers between that indicate how to change the initial header for
170 * each subpacket.
171 *
172 * RXRPC_JUMBO_PACKET must be set on all but the last subpacket - and all but
173 * the last are RXRPC_JUMBO_DATALEN in size. The last subpacket may be of any
174 * size.
175 */
176static bool rxrpc_validate_jumbo(struct sk_buff *skb)
177{
178 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
179 unsigned int offset = sp->offset;
David Howells89a80ed2016-09-13 22:36:22 +0100180 unsigned int len = skb->len;
David Howells248f2192016-09-08 11:10:12 +0100181 int nr_jumbo = 1;
182 u8 flags = sp->hdr.flags;
183
184 do {
185 nr_jumbo++;
186 if (len - offset < RXRPC_JUMBO_SUBPKTLEN)
187 goto protocol_error;
188 if (flags & RXRPC_LAST_PACKET)
189 goto protocol_error;
190 offset += RXRPC_JUMBO_DATALEN;
191 if (skb_copy_bits(skb, offset, &flags, 1) < 0)
192 goto protocol_error;
193 offset += sizeof(struct rxrpc_jumbo_header);
194 } while (flags & RXRPC_JUMBO_PACKET);
195
196 sp->nr_jumbo = nr_jumbo;
197 return true;
198
199protocol_error:
200 return false;
201}
202
203/*
204 * Handle reception of a duplicate packet.
205 *
206 * We have to take care to avoid an attack here whereby we're given a series of
207 * jumbograms, each with a sequence number one before the preceding one and
208 * filled up to maximum UDP size. If they never send us the first packet in
209 * the sequence, they can cause us to have to hold on to around 2MiB of kernel
210 * space until the call times out.
211 *
212 * We limit the space usage by only accepting three duplicate jumbo packets per
213 * call. After that, we tell the other side we're no longer accepting jumbos
214 * (that information is encoded in the ACK packet).
215 */
216static void rxrpc_input_dup_data(struct rxrpc_call *call, rxrpc_seq_t seq,
David Howells75e42122016-09-13 22:36:22 +0100217 u8 annotation, bool *_jumbo_bad)
David Howells248f2192016-09-08 11:10:12 +0100218{
219 /* Discard normal packets that are duplicates. */
220 if (annotation == 0)
221 return;
222
223 /* Skip jumbo subpackets that are duplicates. When we've had three or
224 * more partially duplicate jumbo packets, we refuse to take any more
225 * jumbos for this call.
226 */
David Howells75e42122016-09-13 22:36:22 +0100227 if (!*_jumbo_bad) {
228 call->nr_jumbo_bad++;
229 *_jumbo_bad = true;
David Howells248f2192016-09-08 11:10:12 +0100230 }
David Howells17926a72007-04-26 15:48:28 -0700231}
232
233/*
David Howells248f2192016-09-08 11:10:12 +0100234 * Process a DATA packet, adding the packet to the Rx ring.
David Howells17926a72007-04-26 15:48:28 -0700235 */
David Howells248f2192016-09-08 11:10:12 +0100236static void rxrpc_input_data(struct rxrpc_call *call, struct sk_buff *skb,
237 u16 skew)
238{
239 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
240 unsigned int offset = sp->offset;
241 unsigned int ix;
242 rxrpc_serial_t serial = sp->hdr.serial, ack_serial = 0;
243 rxrpc_seq_t seq = sp->hdr.seq, hard_ack;
David Howells75e42122016-09-13 22:36:22 +0100244 bool immediate_ack = false, jumbo_bad = false, queued;
David Howells248f2192016-09-08 11:10:12 +0100245 u16 len;
246 u8 ack = 0, flags, annotation = 0;
247
248 _enter("{%u,%u},{%u,%u}",
David Howells89a80ed2016-09-13 22:36:22 +0100249 call->rx_hard_ack, call->rx_top, skb->len, seq);
David Howells248f2192016-09-08 11:10:12 +0100250
251 _proto("Rx DATA %%%u { #%u f=%02x }",
252 sp->hdr.serial, seq, sp->hdr.flags);
253
254 if (call->state >= RXRPC_CALL_COMPLETE)
255 return;
256
257 /* Received data implicitly ACKs all of the request packets we sent
258 * when we're acting as a client.
259 */
David Howells70790db2016-09-23 12:39:22 +0100260 if ((call->state == RXRPC_CALL_CLIENT_SEND_REQUEST ||
261 call->state == RXRPC_CALL_CLIENT_AWAIT_REPLY) &&
262 !rxrpc_receiving_reply(call))
David Howells248f2192016-09-08 11:10:12 +0100263 return;
264
265 call->ackr_prev_seq = seq;
266
267 hard_ack = READ_ONCE(call->rx_hard_ack);
268 if (after(seq, hard_ack + call->rx_winsize)) {
269 ack = RXRPC_ACK_EXCEEDS_WINDOW;
270 ack_serial = serial;
271 goto ack;
272 }
273
274 flags = sp->hdr.flags;
275 if (flags & RXRPC_JUMBO_PACKET) {
David Howells75e42122016-09-13 22:36:22 +0100276 if (call->nr_jumbo_bad > 3) {
David Howells248f2192016-09-08 11:10:12 +0100277 ack = RXRPC_ACK_NOSPACE;
278 ack_serial = serial;
279 goto ack;
280 }
281 annotation = 1;
282 }
283
284next_subpacket:
285 queued = false;
286 ix = seq & RXRPC_RXTX_BUFF_MASK;
David Howells89a80ed2016-09-13 22:36:22 +0100287 len = skb->len;
David Howells248f2192016-09-08 11:10:12 +0100288 if (flags & RXRPC_JUMBO_PACKET)
289 len = RXRPC_JUMBO_DATALEN;
290
291 if (flags & RXRPC_LAST_PACKET) {
David Howells816c9fc2016-09-17 10:49:11 +0100292 if (test_bit(RXRPC_CALL_RX_LAST, &call->flags) &&
David Howells248f2192016-09-08 11:10:12 +0100293 seq != call->rx_top)
294 return rxrpc_proto_abort("LSN", call, seq);
295 } else {
296 if (test_bit(RXRPC_CALL_RX_LAST, &call->flags) &&
297 after_eq(seq, call->rx_top))
298 return rxrpc_proto_abort("LSA", call, seq);
299 }
300
301 if (before_eq(seq, hard_ack)) {
302 ack = RXRPC_ACK_DUPLICATE;
303 ack_serial = serial;
304 goto skip;
305 }
306
307 if (flags & RXRPC_REQUEST_ACK && !ack) {
308 ack = RXRPC_ACK_REQUESTED;
309 ack_serial = serial;
310 }
311
312 if (call->rxtx_buffer[ix]) {
David Howells75e42122016-09-13 22:36:22 +0100313 rxrpc_input_dup_data(call, seq, annotation, &jumbo_bad);
David Howells248f2192016-09-08 11:10:12 +0100314 if (ack != RXRPC_ACK_DUPLICATE) {
315 ack = RXRPC_ACK_DUPLICATE;
316 ack_serial = serial;
317 }
318 immediate_ack = true;
319 goto skip;
320 }
321
322 /* Queue the packet. We use a couple of memory barriers here as need
323 * to make sure that rx_top is perceived to be set after the buffer
324 * pointer and that the buffer pointer is set after the annotation and
325 * the skb data.
326 *
327 * Barriers against rxrpc_recvmsg_data() and rxrpc_rotate_rx_window()
328 * and also rxrpc_fill_out_ack().
329 */
David Howells71f3ca42016-09-17 10:49:14 +0100330 rxrpc_get_skb(skb, rxrpc_skb_rx_got);
David Howells248f2192016-09-08 11:10:12 +0100331 call->rxtx_annotations[ix] = annotation;
332 smp_wmb();
333 call->rxtx_buffer[ix] = skb;
334 if (after(seq, call->rx_top))
335 smp_store_release(&call->rx_top, seq);
David Howells58dc63c2016-09-17 10:49:13 +0100336 if (flags & RXRPC_LAST_PACKET) {
David Howells816c9fc2016-09-17 10:49:11 +0100337 set_bit(RXRPC_CALL_RX_LAST, &call->flags);
David Howells58dc63c2016-09-17 10:49:13 +0100338 trace_rxrpc_receive(call, rxrpc_receive_queue_last, serial, seq);
339 } else {
340 trace_rxrpc_receive(call, rxrpc_receive_queue, serial, seq);
341 }
David Howells248f2192016-09-08 11:10:12 +0100342 queued = true;
343
344 if (after_eq(seq, call->rx_expect_next)) {
345 if (after(seq, call->rx_expect_next)) {
346 _net("OOS %u > %u", seq, call->rx_expect_next);
347 ack = RXRPC_ACK_OUT_OF_SEQUENCE;
348 ack_serial = serial;
349 }
350 call->rx_expect_next = seq + 1;
351 }
352
353skip:
354 offset += len;
355 if (flags & RXRPC_JUMBO_PACKET) {
356 if (skb_copy_bits(skb, offset, &flags, 1) < 0)
357 return rxrpc_proto_abort("XJF", call, seq);
358 offset += sizeof(struct rxrpc_jumbo_header);
359 seq++;
360 serial++;
361 annotation++;
362 if (flags & RXRPC_JUMBO_PACKET)
363 annotation |= RXRPC_RX_ANNO_JLAST;
David Howells75e42122016-09-13 22:36:22 +0100364 if (after(seq, hard_ack + call->rx_winsize)) {
365 ack = RXRPC_ACK_EXCEEDS_WINDOW;
366 ack_serial = serial;
367 if (!jumbo_bad) {
368 call->nr_jumbo_bad++;
369 jumbo_bad = true;
370 }
371 goto ack;
372 }
David Howells248f2192016-09-08 11:10:12 +0100373
374 _proto("Rx DATA Jumbo %%%u", serial);
375 goto next_subpacket;
376 }
377
378 if (queued && flags & RXRPC_LAST_PACKET && !ack) {
379 ack = RXRPC_ACK_DELAY;
380 ack_serial = serial;
381 }
382
383ack:
384 if (ack)
385 rxrpc_propose_ACK(call, ack, skew, ack_serial,
David Howells9c7ad432016-09-23 13:50:40 +0100386 immediate_ack, true,
387 rxrpc_propose_ack_input_data);
David Howells248f2192016-09-08 11:10:12 +0100388
389 if (sp->hdr.seq == READ_ONCE(call->rx_hard_ack) + 1)
390 rxrpc_notify_socket(call);
391 _leave(" [queued]");
392}
393
394/*
David Howells50235c42016-09-22 00:29:31 +0100395 * Process a requested ACK.
396 */
397static void rxrpc_input_requested_ack(struct rxrpc_call *call,
398 ktime_t resp_time,
399 rxrpc_serial_t orig_serial,
400 rxrpc_serial_t ack_serial)
401{
402 struct rxrpc_skb_priv *sp;
403 struct sk_buff *skb;
404 ktime_t sent_at;
405 int ix;
406
407 for (ix = 0; ix < RXRPC_RXTX_BUFF_SIZE; ix++) {
408 skb = call->rxtx_buffer[ix];
409 if (!skb)
410 continue;
411
412 sp = rxrpc_skb(skb);
413 if (sp->hdr.serial != orig_serial)
414 continue;
415 smp_rmb();
416 sent_at = skb->tstamp;
417 goto found;
418 }
419 return;
420
421found:
422 rxrpc_peer_add_rtt(call, rxrpc_rtt_rx_requested_ack,
423 orig_serial, ack_serial, sent_at, resp_time);
424}
425
426/*
David Howells8e831342016-09-22 00:29:31 +0100427 * Process a ping response.
428 */
429static void rxrpc_input_ping_response(struct rxrpc_call *call,
430 ktime_t resp_time,
431 rxrpc_serial_t orig_serial,
432 rxrpc_serial_t ack_serial)
433{
434 rxrpc_serial_t ping_serial;
435 ktime_t ping_time;
436
437 ping_time = call->ackr_ping_time;
438 smp_rmb();
439 ping_serial = call->ackr_ping;
440
441 if (!test_bit(RXRPC_CALL_PINGING, &call->flags) ||
442 before(orig_serial, ping_serial))
443 return;
444 clear_bit(RXRPC_CALL_PINGING, &call->flags);
445 if (after(orig_serial, ping_serial))
446 return;
447
448 rxrpc_peer_add_rtt(call, rxrpc_rtt_rx_ping_response,
449 orig_serial, ack_serial, ping_time, resp_time);
450}
451
452/*
David Howells248f2192016-09-08 11:10:12 +0100453 * Process the extra information that may be appended to an ACK packet
454 */
455static void rxrpc_input_ackinfo(struct rxrpc_call *call, struct sk_buff *skb,
456 struct rxrpc_ackinfo *ackinfo)
457{
458 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
459 struct rxrpc_peer *peer;
460 unsigned int mtu;
David Howells01fd0742016-09-13 10:23:01 +0100461 u32 rwind = ntohl(ackinfo->rwind);
David Howells248f2192016-09-08 11:10:12 +0100462
463 _proto("Rx ACK %%%u Info { rx=%u max=%u rwin=%u jm=%u }",
464 sp->hdr.serial,
465 ntohl(ackinfo->rxMTU), ntohl(ackinfo->maxMTU),
David Howells01fd0742016-09-13 10:23:01 +0100466 rwind, ntohl(ackinfo->jumbo_max));
David Howells248f2192016-09-08 11:10:12 +0100467
David Howells01fd0742016-09-13 10:23:01 +0100468 if (rwind > RXRPC_RXTX_BUFF_SIZE - 1)
469 rwind = RXRPC_RXTX_BUFF_SIZE - 1;
470 call->tx_winsize = rwind;
David Howells248f2192016-09-08 11:10:12 +0100471
472 mtu = min(ntohl(ackinfo->rxMTU), ntohl(ackinfo->maxMTU));
473
474 peer = call->peer;
475 if (mtu < peer->maxdata) {
476 spin_lock_bh(&peer->lock);
477 peer->maxdata = mtu;
478 peer->mtu = mtu + peer->hdrsize;
479 spin_unlock_bh(&peer->lock);
480 _net("Net MTU %u (maxdata %u)", peer->mtu, peer->maxdata);
481 }
482}
483
484/*
485 * Process individual soft ACKs.
486 *
487 * Each ACK in the array corresponds to one packet and can be either an ACK or
488 * a NAK. If we get find an explicitly NAK'd packet we resend immediately;
489 * packets that lie beyond the end of the ACK list are scheduled for resend by
490 * the timer on the basis that the peer might just not have processed them at
491 * the time the ACK was sent.
492 */
493static void rxrpc_input_soft_acks(struct rxrpc_call *call, u8 *acks,
494 rxrpc_seq_t seq, int nr_acks)
495{
496 bool resend = false;
497 int ix;
David Howellsf07373e2016-09-22 00:29:32 +0100498 u8 annotation, anno_type;
David Howells248f2192016-09-08 11:10:12 +0100499
500 for (; nr_acks > 0; nr_acks--, seq++) {
501 ix = seq & RXRPC_RXTX_BUFF_MASK;
David Howellsf07373e2016-09-22 00:29:32 +0100502 annotation = call->rxtx_annotations[ix];
503 anno_type = annotation & RXRPC_TX_ANNO_MASK;
504 annotation &= ~RXRPC_TX_ANNO_MASK;
David Howellsd01dc4c2016-09-17 10:49:12 +0100505 switch (*acks++) {
David Howells248f2192016-09-08 11:10:12 +0100506 case RXRPC_ACK_TYPE_ACK:
David Howellsf07373e2016-09-22 00:29:32 +0100507 if (anno_type == RXRPC_TX_ANNO_ACK)
508 continue;
509 call->rxtx_annotations[ix] =
510 RXRPC_TX_ANNO_ACK | annotation;
David Howells248f2192016-09-08 11:10:12 +0100511 break;
512 case RXRPC_ACK_TYPE_NACK:
David Howellsf07373e2016-09-22 00:29:32 +0100513 if (anno_type == RXRPC_TX_ANNO_NAK)
David Howells248f2192016-09-08 11:10:12 +0100514 continue;
David Howellsbe8aa332016-09-23 12:39:23 +0100515 if (anno_type == RXRPC_TX_ANNO_RETRANS)
516 continue;
David Howellsf07373e2016-09-22 00:29:32 +0100517 call->rxtx_annotations[ix] =
518 RXRPC_TX_ANNO_NAK | annotation;
David Howells248f2192016-09-08 11:10:12 +0100519 resend = true;
520 break;
521 default:
522 return rxrpc_proto_abort("SFT", call, 0);
523 }
524 }
525
526 if (resend &&
527 !test_and_set_bit(RXRPC_CALL_EV_RESEND, &call->events))
528 rxrpc_queue_call(call);
529}
530
531/*
532 * Process an ACK packet.
533 *
534 * ack.firstPacket is the sequence number of the first soft-ACK'd/NAK'd packet
535 * in the ACK array. Anything before that is hard-ACK'd and may be discarded.
536 *
537 * A hard-ACK means that a packet has been processed and may be discarded; a
538 * soft-ACK means that the packet may be discarded and retransmission
539 * requested. A phase is complete when all packets are hard-ACK'd.
540 */
541static void rxrpc_input_ack(struct rxrpc_call *call, struct sk_buff *skb,
542 u16 skew)
543{
David Howells9c7ad432016-09-23 13:50:40 +0100544 u8 ack_reason;
David Howells248f2192016-09-08 11:10:12 +0100545 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
546 union {
547 struct rxrpc_ackpacket ack;
548 struct rxrpc_ackinfo info;
549 u8 acks[RXRPC_MAXACKS];
550 } buf;
David Howells8e831342016-09-22 00:29:31 +0100551 rxrpc_serial_t acked_serial;
David Howells248f2192016-09-08 11:10:12 +0100552 rxrpc_seq_t first_soft_ack, hard_ack;
553 int nr_acks, offset;
554
555 _enter("");
556
557 if (skb_copy_bits(skb, sp->offset, &buf.ack, sizeof(buf.ack)) < 0) {
558 _debug("extraction failure");
559 return rxrpc_proto_abort("XAK", call, 0);
560 }
561 sp->offset += sizeof(buf.ack);
562
David Howells8e831342016-09-22 00:29:31 +0100563 acked_serial = ntohl(buf.ack.serial);
David Howells248f2192016-09-08 11:10:12 +0100564 first_soft_ack = ntohl(buf.ack.firstPacket);
565 hard_ack = first_soft_ack - 1;
566 nr_acks = buf.ack.nAcks;
David Howells9c7ad432016-09-23 13:50:40 +0100567 ack_reason = (buf.ack.reason < RXRPC_ACK__INVALID ?
568 buf.ack.reason : RXRPC_ACK__INVALID);
David Howells248f2192016-09-08 11:10:12 +0100569
David Howells9c7ad432016-09-23 13:50:40 +0100570 trace_rxrpc_rx_ack(call, first_soft_ack, ack_reason, nr_acks);
David Howellsec71eb92016-09-17 10:49:13 +0100571
David Howells248f2192016-09-08 11:10:12 +0100572 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
573 sp->hdr.serial,
574 ntohs(buf.ack.maxSkew),
575 first_soft_ack,
576 ntohl(buf.ack.previousPacket),
David Howells8e831342016-09-22 00:29:31 +0100577 acked_serial,
David Howells9c7ad432016-09-23 13:50:40 +0100578 rxrpc_ack_names[ack_reason],
David Howells248f2192016-09-08 11:10:12 +0100579 buf.ack.nAcks);
580
David Howells8e831342016-09-22 00:29:31 +0100581 if (buf.ack.reason == RXRPC_ACK_PING_RESPONSE)
582 rxrpc_input_ping_response(call, skb->tstamp, acked_serial,
583 sp->hdr.serial);
David Howells50235c42016-09-22 00:29:31 +0100584 if (buf.ack.reason == RXRPC_ACK_REQUESTED)
585 rxrpc_input_requested_ack(call, skb->tstamp, acked_serial,
586 sp->hdr.serial);
David Howells8e831342016-09-22 00:29:31 +0100587
David Howells248f2192016-09-08 11:10:12 +0100588 if (buf.ack.reason == RXRPC_ACK_PING) {
589 _proto("Rx ACK %%%u PING Request", sp->hdr.serial);
590 rxrpc_propose_ACK(call, RXRPC_ACK_PING_RESPONSE,
David Howells9c7ad432016-09-23 13:50:40 +0100591 skew, sp->hdr.serial, true, true,
592 rxrpc_propose_ack_respond_to_ping);
David Howells248f2192016-09-08 11:10:12 +0100593 } else if (sp->hdr.flags & RXRPC_REQUEST_ACK) {
594 rxrpc_propose_ACK(call, RXRPC_ACK_REQUESTED,
David Howells9c7ad432016-09-23 13:50:40 +0100595 skew, sp->hdr.serial, true, true,
596 rxrpc_propose_ack_respond_to_ack);
David Howells248f2192016-09-08 11:10:12 +0100597 }
598
599 offset = sp->offset + nr_acks + 3;
David Howells89a80ed2016-09-13 22:36:22 +0100600 if (skb->len >= offset + sizeof(buf.info)) {
David Howells248f2192016-09-08 11:10:12 +0100601 if (skb_copy_bits(skb, offset, &buf.info, sizeof(buf.info)) < 0)
602 return rxrpc_proto_abort("XAI", call, 0);
603 rxrpc_input_ackinfo(call, skb, &buf.info);
604 }
605
606 if (first_soft_ack == 0)
607 return rxrpc_proto_abort("AK0", call, 0);
608
609 /* Ignore ACKs unless we are or have just been transmitting. */
610 switch (call->state) {
611 case RXRPC_CALL_CLIENT_SEND_REQUEST:
612 case RXRPC_CALL_CLIENT_AWAIT_REPLY:
613 case RXRPC_CALL_SERVER_SEND_REPLY:
614 case RXRPC_CALL_SERVER_AWAIT_ACK:
615 break;
616 default:
617 return;
618 }
619
620 /* Discard any out-of-order or duplicate ACKs. */
David Howells98dafac2016-09-23 14:04:38 +0100621 if (before_eq(sp->hdr.serial, call->acks_latest)) {
David Howells248f2192016-09-08 11:10:12 +0100622 _debug("discard ACK %d <= %d",
623 sp->hdr.serial, call->acks_latest);
624 return;
625 }
626 call->acks_latest = sp->hdr.serial;
627
David Howells248f2192016-09-08 11:10:12 +0100628 if (before(hard_ack, call->tx_hard_ack) ||
629 after(hard_ack, call->tx_top))
630 return rxrpc_proto_abort("AKW", call, 0);
David Howells70790db2016-09-23 12:39:22 +0100631 if (nr_acks > call->tx_top - hard_ack)
632 return rxrpc_proto_abort("AKN", call, 0);
David Howells248f2192016-09-08 11:10:12 +0100633
634 if (after(hard_ack, call->tx_hard_ack))
635 rxrpc_rotate_tx_window(call, hard_ack);
636
David Howells70790db2016-09-23 12:39:22 +0100637 if (nr_acks > 0) {
638 if (skb_copy_bits(skb, sp->offset, buf.acks, nr_acks) < 0)
639 return rxrpc_proto_abort("XSA", call, 0);
640 rxrpc_input_soft_acks(call, buf.acks, first_soft_ack, nr_acks);
641 }
David Howells248f2192016-09-08 11:10:12 +0100642
David Howells70790db2016-09-23 12:39:22 +0100643 if (test_bit(RXRPC_CALL_TX_LAST, &call->flags)) {
644 rxrpc_end_tx_phase(call, false, "ETA");
645 return;
646 }
647
David Howells248f2192016-09-08 11:10:12 +0100648}
649
650/*
651 * Process an ACKALL packet.
652 */
653static void rxrpc_input_ackall(struct rxrpc_call *call, struct sk_buff *skb)
654{
655 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
656
657 _proto("Rx ACKALL %%%u", sp->hdr.serial);
658
David Howells70790db2016-09-23 12:39:22 +0100659 rxrpc_rotate_tx_window(call, call->tx_top);
660 if (test_bit(RXRPC_CALL_TX_LAST, &call->flags))
661 rxrpc_end_tx_phase(call, false, "ETL");
David Howells248f2192016-09-08 11:10:12 +0100662}
663
664/*
665 * Process an ABORT packet.
666 */
667static void rxrpc_input_abort(struct rxrpc_call *call, struct sk_buff *skb)
David Howells17926a72007-04-26 15:48:28 -0700668{
669 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
David Howells0d12f8a2016-03-04 15:53:46 +0000670 __be32 wtmp;
David Howells248f2192016-09-08 11:10:12 +0100671 u32 abort_code = RX_CALL_DEAD;
672
673 _enter("");
674
675 if (skb->len >= 4 &&
676 skb_copy_bits(skb, sp->offset, &wtmp, sizeof(wtmp)) >= 0)
677 abort_code = ntohl(wtmp);
678
679 _proto("Rx ABORT %%%u { %x }", sp->hdr.serial, abort_code);
680
681 if (rxrpc_set_call_completion(call, RXRPC_CALL_REMOTELY_ABORTED,
682 abort_code, ECONNABORTED))
683 rxrpc_notify_socket(call);
684}
685
686/*
687 * Process an incoming call packet.
688 */
689static void rxrpc_input_call_packet(struct rxrpc_call *call,
690 struct sk_buff *skb, u16 skew)
691{
692 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
David Howells17926a72007-04-26 15:48:28 -0700693
694 _enter("%p,%p", call, skb);
695
David Howells17926a72007-04-26 15:48:28 -0700696 switch (sp->hdr.type) {
David Howells248f2192016-09-08 11:10:12 +0100697 case RXRPC_PACKET_TYPE_DATA:
698 rxrpc_input_data(call, skb, skew);
699 break;
David Howells17926a72007-04-26 15:48:28 -0700700
David Howells248f2192016-09-08 11:10:12 +0100701 case RXRPC_PACKET_TYPE_ACK:
702 rxrpc_input_ack(call, skb, skew);
703 break;
David Howells17926a72007-04-26 15:48:28 -0700704
705 case RXRPC_PACKET_TYPE_BUSY:
David Howells0d12f8a2016-03-04 15:53:46 +0000706 _proto("Rx BUSY %%%u", sp->hdr.serial);
David Howells17926a72007-04-26 15:48:28 -0700707
David Howells248f2192016-09-08 11:10:12 +0100708 /* Just ignore BUSY packets from the server; the retry and
709 * lifespan timers will take care of business. BUSY packets
710 * from the client don't make sense.
711 */
712 break;
David Howells17926a72007-04-26 15:48:28 -0700713
David Howells248f2192016-09-08 11:10:12 +0100714 case RXRPC_PACKET_TYPE_ABORT:
715 rxrpc_input_abort(call, skb);
716 break;
717
718 case RXRPC_PACKET_TYPE_ACKALL:
719 rxrpc_input_ackall(call, skb);
720 break;
David Howells17926a72007-04-26 15:48:28 -0700721
722 default:
David Howells0d12f8a2016-03-04 15:53:46 +0000723 _proto("Rx %s %%%u", rxrpc_pkts[sp->hdr.type], sp->hdr.serial);
David Howells17926a72007-04-26 15:48:28 -0700724 break;
725 }
726
David Howells17926a72007-04-26 15:48:28 -0700727 _leave("");
728}
729
730/*
731 * post connection-level events to the connection
David Howells18bfeba2016-08-23 15:27:25 +0100732 * - this includes challenges, responses, some aborts and call terminal packet
733 * retransmission.
David Howells17926a72007-04-26 15:48:28 -0700734 */
David Howells2e7e9752016-08-09 10:11:48 +0100735static void rxrpc_post_packet_to_conn(struct rxrpc_connection *conn,
David Howells17926a72007-04-26 15:48:28 -0700736 struct sk_buff *skb)
737{
738 _enter("%p,%p", conn, skb);
739
David Howells17926a72007-04-26 15:48:28 -0700740 skb_queue_tail(&conn->rx_queue, skb);
David Howells2e7e9752016-08-09 10:11:48 +0100741 rxrpc_queue_conn(conn);
David Howells17926a72007-04-26 15:48:28 -0700742}
743
David Howells44ba0692015-04-01 16:31:26 +0100744/*
745 * post endpoint-level events to the local endpoint
746 * - this includes debug and version messages
747 */
748static void rxrpc_post_packet_to_local(struct rxrpc_local *local,
749 struct sk_buff *skb)
750{
751 _enter("%p,%p", local, skb);
752
David Howells44ba0692015-04-01 16:31:26 +0100753 skb_queue_tail(&local->event_queue, skb);
David Howells5acbee42016-06-27 10:32:02 +0100754 rxrpc_queue_local(local);
David Howells44ba0692015-04-01 16:31:26 +0100755}
756
David Howells0d12f8a2016-03-04 15:53:46 +0000757/*
David Howells248f2192016-09-08 11:10:12 +0100758 * put a packet up for transport-level abort
759 */
760static void rxrpc_reject_packet(struct rxrpc_local *local, struct sk_buff *skb)
761{
762 CHECK_SLAB_OKAY(&local->usage);
763
764 skb_queue_tail(&local->reject_queue, skb);
765 rxrpc_queue_local(local);
766}
767
768/*
David Howells0d12f8a2016-03-04 15:53:46 +0000769 * Extract the wire header from a packet and translate the byte order.
770 */
771static noinline
772int rxrpc_extract_header(struct rxrpc_skb_priv *sp, struct sk_buff *skb)
773{
774 struct rxrpc_wire_header whdr;
775
776 /* dig out the RxRPC connection details */
Willem de Bruijn4d0fc732016-04-07 11:44:59 -0400777 if (skb_copy_bits(skb, 0, &whdr, sizeof(whdr)) < 0)
David Howells0d12f8a2016-03-04 15:53:46 +0000778 return -EBADMSG;
David Howells0d12f8a2016-03-04 15:53:46 +0000779
780 memset(sp, 0, sizeof(*sp));
781 sp->hdr.epoch = ntohl(whdr.epoch);
782 sp->hdr.cid = ntohl(whdr.cid);
783 sp->hdr.callNumber = ntohl(whdr.callNumber);
784 sp->hdr.seq = ntohl(whdr.seq);
785 sp->hdr.serial = ntohl(whdr.serial);
786 sp->hdr.flags = whdr.flags;
787 sp->hdr.type = whdr.type;
788 sp->hdr.userStatus = whdr.userStatus;
789 sp->hdr.securityIndex = whdr.securityIndex;
790 sp->hdr._rsvd = ntohs(whdr._rsvd);
791 sp->hdr.serviceId = ntohs(whdr.serviceId);
David Howells248f2192016-09-08 11:10:12 +0100792 sp->offset = sizeof(whdr);
David Howells0d12f8a2016-03-04 15:53:46 +0000793 return 0;
794}
795
David Howells17926a72007-04-26 15:48:28 -0700796/*
797 * handle data received on the local endpoint
798 * - may be called in interrupt context
David Howells4f95dd72016-04-04 14:00:35 +0100799 *
800 * The socket is locked by the caller and this prevents the socket from being
801 * shut down and the local endpoint from going away, thus sk_user_data will not
802 * be cleared until this function returns.
David Howells17926a72007-04-26 15:48:28 -0700803 */
David Howells248f2192016-09-08 11:10:12 +0100804void rxrpc_data_ready(struct sock *udp_sk)
David Howells17926a72007-04-26 15:48:28 -0700805{
David Howells8496af52016-07-01 07:51:50 +0100806 struct rxrpc_connection *conn;
David Howells248f2192016-09-08 11:10:12 +0100807 struct rxrpc_channel *chan;
808 struct rxrpc_call *call;
David Howells17926a72007-04-26 15:48:28 -0700809 struct rxrpc_skb_priv *sp;
David Howells248f2192016-09-08 11:10:12 +0100810 struct rxrpc_local *local = udp_sk->sk_user_data;
David Howells17926a72007-04-26 15:48:28 -0700811 struct sk_buff *skb;
David Howells248f2192016-09-08 11:10:12 +0100812 unsigned int channel;
David Howells563ea7d2016-08-23 15:27:25 +0100813 int ret, skew;
David Howells17926a72007-04-26 15:48:28 -0700814
David Howells248f2192016-09-08 11:10:12 +0100815 _enter("%p", udp_sk);
David Howells17926a72007-04-26 15:48:28 -0700816
817 ASSERT(!irqs_disabled());
818
David Howells248f2192016-09-08 11:10:12 +0100819 skb = skb_recv_datagram(udp_sk, 0, 1, &ret);
David Howells17926a72007-04-26 15:48:28 -0700820 if (!skb) {
David Howells17926a72007-04-26 15:48:28 -0700821 if (ret == -EAGAIN)
822 return;
823 _debug("UDP socket error %d", ret);
824 return;
825 }
826
David Howells71f3ca42016-09-17 10:49:14 +0100827 rxrpc_new_skb(skb, rxrpc_skb_rx_received);
David Howells17926a72007-04-26 15:48:28 -0700828
829 _net("recv skb %p", skb);
830
831 /* we'll probably need to checksum it (didn't call sock_recvmsg) */
832 if (skb_checksum_complete(skb)) {
David Howells71f3ca42016-09-17 10:49:14 +0100833 rxrpc_free_skb(skb, rxrpc_skb_rx_freed);
Eric Dumazet02c22342016-04-27 16:44:30 -0700834 __UDP_INC_STATS(&init_net, UDP_MIB_INERRORS, 0);
David Howells17926a72007-04-26 15:48:28 -0700835 _leave(" [CSUM failed]");
836 return;
837 }
838
Eric Dumazet02c22342016-04-27 16:44:30 -0700839 __UDP_INC_STATS(&init_net, UDP_MIB_INDATAGRAMS, 0);
Herbert Xu1781f7f2007-12-11 11:30:32 -0800840
David Howells0d12f8a2016-03-04 15:53:46 +0000841 /* The socket buffer we have is owned by UDP, with UDP's data all over
842 * it, but we really want our own data there.
843 */
David Howells17926a72007-04-26 15:48:28 -0700844 skb_orphan(skb);
845 sp = rxrpc_skb(skb);
David Howells17926a72007-04-26 15:48:28 -0700846
David Howells89b475a2016-09-23 12:39:22 +0100847 /* dig out the RxRPC connection details */
848 if (rxrpc_extract_header(sp, skb) < 0)
849 goto bad_message;
850
David Howells8a681c362016-09-17 10:49:15 +0100851 if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) {
852 static int lose;
853 if ((lose++ & 7) == 7) {
David Howells89b475a2016-09-23 12:39:22 +0100854 trace_rxrpc_rx_lose(sp);
David Howells8a681c362016-09-17 10:49:15 +0100855 rxrpc_lose_skb(skb, rxrpc_skb_rx_lost);
856 return;
857 }
858 }
859
David Howells49e19ec2016-09-08 11:10:12 +0100860 trace_rxrpc_rx_packet(sp);
David Howells17926a72007-04-26 15:48:28 -0700861
862 _net("Rx RxRPC %s ep=%x call=%x:%x",
863 sp->hdr.flags & RXRPC_CLIENT_INITIATED ? "ToServer" : "ToClient",
David Howells0d12f8a2016-03-04 15:53:46 +0000864 sp->hdr.epoch, sp->hdr.cid, sp->hdr.callNumber);
David Howells17926a72007-04-26 15:48:28 -0700865
David Howells351c1e62016-03-04 15:56:06 +0000866 if (sp->hdr.type >= RXRPC_N_PACKET_TYPES ||
867 !((RXRPC_SUPPORTED_PACKET_TYPES >> sp->hdr.type) & 1)) {
David Howells17926a72007-04-26 15:48:28 -0700868 _proto("Rx Bad Packet Type %u", sp->hdr.type);
869 goto bad_message;
870 }
871
David Howells248f2192016-09-08 11:10:12 +0100872 switch (sp->hdr.type) {
873 case RXRPC_PACKET_TYPE_VERSION:
David Howells44ba0692015-04-01 16:31:26 +0100874 rxrpc_post_packet_to_local(local, skb);
875 goto out;
David Howellsbc6e1ea2016-06-10 22:30:27 +0100876
David Howells248f2192016-09-08 11:10:12 +0100877 case RXRPC_PACKET_TYPE_BUSY:
878 if (sp->hdr.flags & RXRPC_CLIENT_INITIATED)
879 goto discard;
880
881 case RXRPC_PACKET_TYPE_DATA:
882 if (sp->hdr.callNumber == 0)
883 goto bad_message;
884 if (sp->hdr.flags & RXRPC_JUMBO_PACKET &&
885 !rxrpc_validate_jumbo(skb))
886 goto bad_message;
887 break;
888 }
David Howells17926a72007-04-26 15:48:28 -0700889
David Howells8496af52016-07-01 07:51:50 +0100890 rcu_read_lock();
891
David Howells8496af52016-07-01 07:51:50 +0100892 conn = rxrpc_find_connection_rcu(local, skb);
David Howells248f2192016-09-08 11:10:12 +0100893 if (conn) {
894 if (sp->hdr.securityIndex != conn->security_ix)
895 goto wrong_security;
David Howells563ea7d2016-08-23 15:27:25 +0100896
David Howells248f2192016-09-08 11:10:12 +0100897 if (sp->hdr.callNumber == 0) {
898 /* Connection-level packet */
899 _debug("CONN %p {%d}", conn, conn->debug_id);
900 rxrpc_post_packet_to_conn(conn, skb);
901 goto out_unlock;
902 }
David Howells8496af52016-07-01 07:51:50 +0100903
David Howells248f2192016-09-08 11:10:12 +0100904 /* Note the serial number skew here */
905 skew = (int)sp->hdr.serial - (int)conn->hi_serial;
906 if (skew >= 0) {
907 if (skew > 0)
908 conn->hi_serial = sp->hdr.serial;
909 } else {
910 skew = -skew;
911 skew = min(skew, 65535);
912 }
913
David Howells8496af52016-07-01 07:51:50 +0100914 /* Call-bound packets are routed by connection channel. */
David Howells248f2192016-09-08 11:10:12 +0100915 channel = sp->hdr.cid & RXRPC_CHANNELMASK;
916 chan = &conn->channels[channel];
Tim Smith77276402014-03-03 23:04:45 +0000917
David Howells18bfeba2016-08-23 15:27:25 +0100918 /* Ignore really old calls */
919 if (sp->hdr.callNumber < chan->last_call)
920 goto discard_unlock;
921
922 if (sp->hdr.callNumber == chan->last_call) {
David Howells248f2192016-09-08 11:10:12 +0100923 /* For the previous service call, if completed successfully, we
924 * discard all further packets.
David Howells18bfeba2016-08-23 15:27:25 +0100925 */
David Howells2266ffd2016-08-24 13:06:14 +0100926 if (rxrpc_conn_is_service(conn) &&
David Howells18bfeba2016-08-23 15:27:25 +0100927 (chan->last_type == RXRPC_PACKET_TYPE_ACK ||
928 sp->hdr.type == RXRPC_PACKET_TYPE_ABORT))
929 goto discard_unlock;
930
David Howells248f2192016-09-08 11:10:12 +0100931 /* But otherwise we need to retransmit the final packet from
932 * data cached in the connection record.
David Howells18bfeba2016-08-23 15:27:25 +0100933 */
934 rxrpc_post_packet_to_conn(conn, skb);
935 goto out_unlock;
936 }
937
938 call = rcu_dereference(chan->call);
David Howells248f2192016-09-08 11:10:12 +0100939 } else {
940 skew = 0;
941 call = NULL;
Tim Smith77276402014-03-03 23:04:45 +0000942 }
David Howells44ba0692015-04-01 16:31:26 +0100943
David Howells248f2192016-09-08 11:10:12 +0100944 if (!call || atomic_read(&call->usage) == 0) {
945 if (!(sp->hdr.type & RXRPC_CLIENT_INITIATED) ||
946 sp->hdr.callNumber == 0 ||
947 sp->hdr.type != RXRPC_PACKET_TYPE_DATA)
948 goto bad_message_unlock;
949 if (sp->hdr.seq != 1)
950 goto discard_unlock;
951 call = rxrpc_new_incoming_call(local, conn, skb);
952 if (!call) {
953 rcu_read_unlock();
954 goto reject_packet;
955 }
David Howells8e831342016-09-22 00:29:31 +0100956 rxrpc_send_ping(call, skb, skew);
David Howells248f2192016-09-08 11:10:12 +0100957 }
958
959 rxrpc_input_call_packet(call, skb, skew);
960 goto discard_unlock;
961
David Howells18bfeba2016-08-23 15:27:25 +0100962discard_unlock:
David Howells8496af52016-07-01 07:51:50 +0100963 rcu_read_unlock();
David Howells248f2192016-09-08 11:10:12 +0100964discard:
David Howells71f3ca42016-09-17 10:49:14 +0100965 rxrpc_free_skb(skb, rxrpc_skb_rx_freed);
David Howells44ba0692015-04-01 16:31:26 +0100966out:
David Howells49e19ec2016-09-08 11:10:12 +0100967 trace_rxrpc_rx_done(0, 0);
David Howells17926a72007-04-26 15:48:28 -0700968 return;
969
David Howells248f2192016-09-08 11:10:12 +0100970out_unlock:
David Howells8496af52016-07-01 07:51:50 +0100971 rcu_read_unlock();
David Howells248f2192016-09-08 11:10:12 +0100972 goto out;
David Howells8496af52016-07-01 07:51:50 +0100973
David Howells248f2192016-09-08 11:10:12 +0100974wrong_security:
975 rcu_read_unlock();
976 trace_rxrpc_abort("SEC", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq,
977 RXKADINCONSISTENCY, EBADMSG);
978 skb->priority = RXKADINCONSISTENCY;
979 goto post_abort;
David Howells17926a72007-04-26 15:48:28 -0700980
David Howells248f2192016-09-08 11:10:12 +0100981bad_message_unlock:
982 rcu_read_unlock();
David Howells17926a72007-04-26 15:48:28 -0700983bad_message:
David Howells248f2192016-09-08 11:10:12 +0100984 trace_rxrpc_abort("BAD", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq,
985 RX_PROTOCOL_ERROR, EBADMSG);
David Howells17926a72007-04-26 15:48:28 -0700986 skb->priority = RX_PROTOCOL_ERROR;
David Howells248f2192016-09-08 11:10:12 +0100987post_abort:
988 skb->mark = RXRPC_SKB_MARK_LOCAL_ABORT;
David Howells49e19ec2016-09-08 11:10:12 +0100989reject_packet:
990 trace_rxrpc_rx_done(skb->mark, skb->priority);
David Howells17926a72007-04-26 15:48:28 -0700991 rxrpc_reject_packet(local, skb);
David Howells17926a72007-04-26 15:48:28 -0700992 _leave(" [badmsg]");
993}