blob: 8834aa62737149e819cdc8345fcf892071ecee96 [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 Howells3a927892017-04-06 10:11:56 +010033 if (rxrpc_abort_call(why, call, seq, RX_PROTOCOL_ERROR, -EBADMSG)) {
David Howells248f2192016-09-08 11:10:12 +010034 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 Howells57494342016-09-24 18:05:27 +010040 * Do TCP-style congestion management [RFC 5681].
41 */
42static void rxrpc_congestion_management(struct rxrpc_call *call,
43 struct sk_buff *skb,
David Howellsed1e8672016-09-29 22:37:16 +010044 struct rxrpc_ack_summary *summary,
45 rxrpc_serial_t acked_serial)
David Howells57494342016-09-24 18:05:27 +010046{
47 enum rxrpc_congest_change change = rxrpc_cong_no_change;
David Howells57494342016-09-24 18:05:27 +010048 unsigned int cumulative_acks = call->cong_cumul_acks;
49 unsigned int cwnd = call->cong_cwnd;
50 bool resend = false;
51
52 summary->flight_size =
53 (call->tx_top - call->tx_hard_ack) - summary->nr_acks;
54
55 if (test_and_clear_bit(RXRPC_CALL_RETRANS_TIMEOUT, &call->flags)) {
56 summary->retrans_timeo = true;
57 call->cong_ssthresh = max_t(unsigned int,
58 summary->flight_size / 2, 2);
59 cwnd = 1;
David Howells8782def2016-09-30 09:26:12 +010060 if (cwnd >= call->cong_ssthresh &&
David Howells57494342016-09-24 18:05:27 +010061 call->cong_mode == RXRPC_CALL_SLOW_START) {
62 call->cong_mode = RXRPC_CALL_CONGEST_AVOIDANCE;
63 call->cong_tstamp = skb->tstamp;
64 cumulative_acks = 0;
65 }
66 }
67
68 cumulative_acks += summary->nr_new_acks;
69 cumulative_acks += summary->nr_rot_new_acks;
70 if (cumulative_acks > 255)
71 cumulative_acks = 255;
72
73 summary->mode = call->cong_mode;
74 summary->cwnd = call->cong_cwnd;
75 summary->ssthresh = call->cong_ssthresh;
76 summary->cumulative_acks = cumulative_acks;
77 summary->dup_acks = call->cong_dup_acks;
78
79 switch (call->cong_mode) {
80 case RXRPC_CALL_SLOW_START:
81 if (summary->nr_nacks > 0)
82 goto packet_loss_detected;
83 if (summary->cumulative_acks > 0)
84 cwnd += 1;
David Howells8782def2016-09-30 09:26:12 +010085 if (cwnd >= call->cong_ssthresh) {
David Howells57494342016-09-24 18:05:27 +010086 call->cong_mode = RXRPC_CALL_CONGEST_AVOIDANCE;
87 call->cong_tstamp = skb->tstamp;
88 }
89 goto out;
90
91 case RXRPC_CALL_CONGEST_AVOIDANCE:
92 if (summary->nr_nacks > 0)
93 goto packet_loss_detected;
94
95 /* We analyse the number of packets that get ACK'd per RTT
96 * period and increase the window if we managed to fill it.
97 */
98 if (call->peer->rtt_usage == 0)
99 goto out;
100 if (ktime_before(skb->tstamp,
101 ktime_add_ns(call->cong_tstamp,
102 call->peer->rtt)))
103 goto out_no_clear_ca;
104 change = rxrpc_cong_rtt_window_end;
105 call->cong_tstamp = skb->tstamp;
106 if (cumulative_acks >= cwnd)
107 cwnd++;
108 goto out;
109
110 case RXRPC_CALL_PACKET_LOSS:
111 if (summary->nr_nacks == 0)
112 goto resume_normality;
113
114 if (summary->new_low_nack) {
115 change = rxrpc_cong_new_low_nack;
116 call->cong_dup_acks = 1;
117 if (call->cong_extra > 1)
118 call->cong_extra = 1;
119 goto send_extra_data;
120 }
121
122 call->cong_dup_acks++;
123 if (call->cong_dup_acks < 3)
124 goto send_extra_data;
125
126 change = rxrpc_cong_begin_retransmission;
127 call->cong_mode = RXRPC_CALL_FAST_RETRANSMIT;
128 call->cong_ssthresh = max_t(unsigned int,
129 summary->flight_size / 2, 2);
130 cwnd = call->cong_ssthresh + 3;
131 call->cong_extra = 0;
132 call->cong_dup_acks = 0;
133 resend = true;
134 goto out;
135
136 case RXRPC_CALL_FAST_RETRANSMIT:
137 if (!summary->new_low_nack) {
138 if (summary->nr_new_acks == 0)
139 cwnd += 1;
140 call->cong_dup_acks++;
141 if (call->cong_dup_acks == 2) {
142 change = rxrpc_cong_retransmit_again;
143 call->cong_dup_acks = 0;
144 resend = true;
145 }
146 } else {
147 change = rxrpc_cong_progress;
148 cwnd = call->cong_ssthresh;
149 if (summary->nr_nacks == 0)
150 goto resume_normality;
151 }
152 goto out;
153
154 default:
155 BUG();
156 goto out;
157 }
158
159resume_normality:
160 change = rxrpc_cong_cleared_nacks;
161 call->cong_dup_acks = 0;
162 call->cong_extra = 0;
163 call->cong_tstamp = skb->tstamp;
David Howells8782def2016-09-30 09:26:12 +0100164 if (cwnd < call->cong_ssthresh)
David Howells57494342016-09-24 18:05:27 +0100165 call->cong_mode = RXRPC_CALL_SLOW_START;
166 else
167 call->cong_mode = RXRPC_CALL_CONGEST_AVOIDANCE;
168out:
169 cumulative_acks = 0;
170out_no_clear_ca:
171 if (cwnd >= RXRPC_RXTX_BUFF_SIZE - 1)
172 cwnd = RXRPC_RXTX_BUFF_SIZE - 1;
173 call->cong_cwnd = cwnd;
174 call->cong_cumul_acks = cumulative_acks;
David Howellsed1e8672016-09-29 22:37:16 +0100175 trace_rxrpc_congest(call, summary, acked_serial, change);
David Howells57494342016-09-24 18:05:27 +0100176 if (resend && !test_and_set_bit(RXRPC_CALL_EV_RESEND, &call->events))
177 rxrpc_queue_call(call);
178 return;
179
180packet_loss_detected:
181 change = rxrpc_cong_saw_nack;
182 call->cong_mode = RXRPC_CALL_PACKET_LOSS;
183 call->cong_dup_acks = 0;
184 goto send_extra_data;
185
186send_extra_data:
187 /* Send some previously unsent DATA if we have some to advance the ACK
188 * state.
189 */
190 if (call->rxtx_annotations[call->tx_top & RXRPC_RXTX_BUFF_MASK] &
191 RXRPC_TX_ANNO_LAST ||
192 summary->nr_acks != call->tx_top - call->tx_hard_ack) {
193 call->cong_extra++;
194 wake_up(&call->waitq);
195 }
196 goto out_no_clear_ca;
197}
198
199/*
David Howells8e831342016-09-22 00:29:31 +0100200 * Ping the other end to fill our RTT cache and to retrieve the rwind
201 * and MTU parameters.
202 */
203static void rxrpc_send_ping(struct rxrpc_call *call, struct sk_buff *skb,
204 int skew)
205{
206 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
David Howellsfc943f62016-09-22 00:29:32 +0100207 ktime_t now = skb->tstamp;
David Howells8e831342016-09-22 00:29:31 +0100208
David Howellsfc943f62016-09-22 00:29:32 +0100209 if (call->peer->rtt_usage < 3 ||
210 ktime_before(ktime_add_ms(call->peer->rtt_last_req, 1000), now))
211 rxrpc_propose_ACK(call, RXRPC_ACK_PING, skew, sp->hdr.serial,
David Howells9c7ad432016-09-23 13:50:40 +0100212 true, true,
213 rxrpc_propose_ack_ping_for_params);
David Howells8e831342016-09-22 00:29:31 +0100214}
215
216/*
David Howells248f2192016-09-08 11:10:12 +0100217 * Apply a hard ACK by advancing the Tx window.
David Howells17926a72007-04-26 15:48:28 -0700218 */
David Howellsc479d5f2018-10-08 15:46:01 +0100219static bool rxrpc_rotate_tx_window(struct rxrpc_call *call, rxrpc_seq_t to,
David Howells31a1b9892016-09-24 18:05:26 +0100220 struct rxrpc_ack_summary *summary)
David Howells17926a72007-04-26 15:48:28 -0700221{
David Howells248f2192016-09-08 11:10:12 +0100222 struct sk_buff *skb, *list = NULL;
David Howellsc479d5f2018-10-08 15:46:01 +0100223 bool rot_last = false;
David Howells248f2192016-09-08 11:10:12 +0100224 int ix;
David Howells70790dbe2016-09-23 12:39:22 +0100225 u8 annotation;
David Howells17926a72007-04-26 15:48:28 -0700226
David Howells31a1b9892016-09-24 18:05:26 +0100227 if (call->acks_lowest_nak == call->tx_hard_ack) {
228 call->acks_lowest_nak = to;
229 } else if (before_eq(call->acks_lowest_nak, to)) {
230 summary->new_low_nack = true;
231 call->acks_lowest_nak = to;
232 }
233
David Howells17926a72007-04-26 15:48:28 -0700234 spin_lock(&call->lock);
235
David Howells248f2192016-09-08 11:10:12 +0100236 while (before(call->tx_hard_ack, to)) {
237 call->tx_hard_ack++;
238 ix = call->tx_hard_ack & RXRPC_RXTX_BUFF_MASK;
239 skb = call->rxtx_buffer[ix];
David Howells70790dbe2016-09-23 12:39:22 +0100240 annotation = call->rxtx_annotations[ix];
David Howells71f3ca42016-09-17 10:49:14 +0100241 rxrpc_see_skb(skb, rxrpc_skb_tx_rotated);
David Howells248f2192016-09-08 11:10:12 +0100242 call->rxtx_buffer[ix] = NULL;
243 call->rxtx_annotations[ix] = 0;
244 skb->next = list;
245 list = skb;
David Howells70790dbe2016-09-23 12:39:22 +0100246
David Howellsc479d5f2018-10-08 15:46:01 +0100247 if (annotation & RXRPC_TX_ANNO_LAST) {
David Howells70790dbe2016-09-23 12:39:22 +0100248 set_bit(RXRPC_CALL_TX_LAST, &call->flags);
David Howellsc479d5f2018-10-08 15:46:01 +0100249 rot_last = true;
250 }
David Howells31a1b9892016-09-24 18:05:26 +0100251 if ((annotation & RXRPC_TX_ANNO_MASK) != RXRPC_TX_ANNO_ACK)
252 summary->nr_rot_new_acks++;
David Howells17926a72007-04-26 15:48:28 -0700253 }
254
255 spin_unlock(&call->lock);
David Howells17926a72007-04-26 15:48:28 -0700256
David Howellsc479d5f2018-10-08 15:46:01 +0100257 trace_rxrpc_transmit(call, (rot_last ?
David Howells70790dbe2016-09-23 12:39:22 +0100258 rxrpc_transmit_rotate_last :
259 rxrpc_transmit_rotate));
David Howellsbc4abfc2016-09-13 22:36:21 +0100260 wake_up(&call->waitq);
261
David Howells248f2192016-09-08 11:10:12 +0100262 while (list) {
263 skb = list;
264 list = skb->next;
265 skb->next = NULL;
David Howells71f3ca42016-09-17 10:49:14 +0100266 rxrpc_free_skb(skb, rxrpc_skb_tx_freed);
David Howells248f2192016-09-08 11:10:12 +0100267 }
David Howellsc479d5f2018-10-08 15:46:01 +0100268
269 return rot_last;
David Howells17926a72007-04-26 15:48:28 -0700270}
271
272/*
David Howells248f2192016-09-08 11:10:12 +0100273 * End the transmission phase of a call.
274 *
275 * This occurs when we get an ACKALL packet, the first DATA packet of a reply,
276 * or a final ACK packet.
David Howells17926a72007-04-26 15:48:28 -0700277 */
David Howells70790dbe2016-09-23 12:39:22 +0100278static bool rxrpc_end_tx_phase(struct rxrpc_call *call, bool reply_begun,
279 const char *abort_why)
David Howells17926a72007-04-26 15:48:28 -0700280{
David Howells17926a72007-04-26 15:48:28 -0700281
David Howells70790dbe2016-09-23 12:39:22 +0100282 ASSERT(test_bit(RXRPC_CALL_TX_LAST, &call->flags));
David Howells248f2192016-09-08 11:10:12 +0100283
284 write_lock(&call->state_lock);
285
286 switch (call->state) {
David Howells70790dbe2016-09-23 12:39:22 +0100287 case RXRPC_CALL_CLIENT_SEND_REQUEST:
David Howells17926a72007-04-26 15:48:28 -0700288 case RXRPC_CALL_CLIENT_AWAIT_REPLY:
David Howells70790dbe2016-09-23 12:39:22 +0100289 if (reply_begun)
290 call->state = RXRPC_CALL_CLIENT_RECV_REPLY;
291 else
292 call->state = RXRPC_CALL_CLIENT_AWAIT_REPLY;
David Howells17926a72007-04-26 15:48:28 -0700293 break;
David Howells70790dbe2016-09-23 12:39:22 +0100294
David Howells248f2192016-09-08 11:10:12 +0100295 case RXRPC_CALL_SERVER_AWAIT_ACK:
296 __rxrpc_call_completed(call);
297 rxrpc_notify_socket(call);
David Howells17926a72007-04-26 15:48:28 -0700298 break;
David Howells70790dbe2016-09-23 12:39:22 +0100299
300 default:
301 goto bad_state;
David Howells17926a72007-04-26 15:48:28 -0700302 }
David Howells248f2192016-09-08 11:10:12 +0100303
304 write_unlock(&call->state_lock);
David Howells70790dbe2016-09-23 12:39:22 +0100305 if (call->state == RXRPC_CALL_CLIENT_AWAIT_REPLY) {
306 trace_rxrpc_transmit(call, rxrpc_transmit_await_reply);
307 } else {
308 trace_rxrpc_transmit(call, rxrpc_transmit_end);
309 }
David Howells248f2192016-09-08 11:10:12 +0100310 _leave(" = ok");
311 return true;
David Howells70790dbe2016-09-23 12:39:22 +0100312
313bad_state:
314 write_unlock(&call->state_lock);
315 kdebug("end_tx %s", rxrpc_call_states[call->state]);
316 rxrpc_proto_abort(abort_why, call, call->tx_top);
317 return false;
318}
319
320/*
321 * Begin the reply reception phase of a call.
322 */
323static bool rxrpc_receiving_reply(struct rxrpc_call *call)
324{
David Howells31a1b9892016-09-24 18:05:26 +0100325 struct rxrpc_ack_summary summary = { 0 };
David Howellsa158bdd2017-11-24 10:18:41 +0000326 unsigned long now, timo;
David Howells70790dbe2016-09-23 12:39:22 +0100327 rxrpc_seq_t top = READ_ONCE(call->tx_top);
328
David Howellsdd7c1ee2016-09-24 18:05:27 +0100329 if (call->ackr_reason) {
330 spin_lock_bh(&call->lock);
331 call->ackr_reason = 0;
David Howellsdd7c1ee2016-09-24 18:05:27 +0100332 spin_unlock_bh(&call->lock);
David Howellsa158bdd2017-11-24 10:18:41 +0000333 now = jiffies;
334 timo = now + MAX_JIFFY_OFFSET;
335 WRITE_ONCE(call->resend_at, timo);
336 WRITE_ONCE(call->ack_at, timo);
337 trace_rxrpc_timer(call, rxrpc_timer_init_for_reply, now);
David Howellsdd7c1ee2016-09-24 18:05:27 +0100338 }
339
David Howells70790dbe2016-09-23 12:39:22 +0100340 if (!test_bit(RXRPC_CALL_TX_LAST, &call->flags)) {
David Howellsc479d5f2018-10-08 15:46:01 +0100341 if (!rxrpc_rotate_tx_window(call, top, &summary)) {
342 rxrpc_proto_abort("TXL", call, top);
343 return false;
344 }
David Howells70790dbe2016-09-23 12:39:22 +0100345 }
346 if (!rxrpc_end_tx_phase(call, true, "ETD"))
347 return false;
348 call->tx_phase = false;
349 return true;
David Howells248f2192016-09-08 11:10:12 +0100350}
351
352/*
353 * Scan a jumbo packet to validate its structure and to work out how many
354 * subpackets it contains.
355 *
356 * A jumbo packet is a collection of consecutive packets glued together with
357 * little headers between that indicate how to change the initial header for
358 * each subpacket.
359 *
360 * RXRPC_JUMBO_PACKET must be set on all but the last subpacket - and all but
361 * the last are RXRPC_JUMBO_DATALEN in size. The last subpacket may be of any
362 * size.
363 */
364static bool rxrpc_validate_jumbo(struct sk_buff *skb)
365{
366 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
David Howells775e5b72016-09-30 13:26:03 +0100367 unsigned int offset = sizeof(struct rxrpc_wire_header);
David Howells89a80ed2016-09-13 22:36:22 +0100368 unsigned int len = skb->len;
David Howells248f2192016-09-08 11:10:12 +0100369 int nr_jumbo = 1;
370 u8 flags = sp->hdr.flags;
371
372 do {
373 nr_jumbo++;
374 if (len - offset < RXRPC_JUMBO_SUBPKTLEN)
375 goto protocol_error;
376 if (flags & RXRPC_LAST_PACKET)
377 goto protocol_error;
378 offset += RXRPC_JUMBO_DATALEN;
379 if (skb_copy_bits(skb, offset, &flags, 1) < 0)
380 goto protocol_error;
381 offset += sizeof(struct rxrpc_jumbo_header);
382 } while (flags & RXRPC_JUMBO_PACKET);
383
384 sp->nr_jumbo = nr_jumbo;
385 return true;
386
387protocol_error:
388 return false;
389}
390
391/*
392 * Handle reception of a duplicate packet.
393 *
394 * We have to take care to avoid an attack here whereby we're given a series of
395 * jumbograms, each with a sequence number one before the preceding one and
396 * filled up to maximum UDP size. If they never send us the first packet in
397 * the sequence, they can cause us to have to hold on to around 2MiB of kernel
398 * space until the call times out.
399 *
400 * We limit the space usage by only accepting three duplicate jumbo packets per
401 * call. After that, we tell the other side we're no longer accepting jumbos
402 * (that information is encoded in the ACK packet).
403 */
404static void rxrpc_input_dup_data(struct rxrpc_call *call, rxrpc_seq_t seq,
David Howells75e42122016-09-13 22:36:22 +0100405 u8 annotation, bool *_jumbo_bad)
David Howells248f2192016-09-08 11:10:12 +0100406{
407 /* Discard normal packets that are duplicates. */
408 if (annotation == 0)
409 return;
410
411 /* Skip jumbo subpackets that are duplicates. When we've had three or
412 * more partially duplicate jumbo packets, we refuse to take any more
413 * jumbos for this call.
414 */
David Howells75e42122016-09-13 22:36:22 +0100415 if (!*_jumbo_bad) {
416 call->nr_jumbo_bad++;
417 *_jumbo_bad = true;
David Howells248f2192016-09-08 11:10:12 +0100418 }
David Howells17926a72007-04-26 15:48:28 -0700419}
420
421/*
David Howells248f2192016-09-08 11:10:12 +0100422 * Process a DATA packet, adding the packet to the Rx ring.
David Howells17926a72007-04-26 15:48:28 -0700423 */
David Howells248f2192016-09-08 11:10:12 +0100424static void rxrpc_input_data(struct rxrpc_call *call, struct sk_buff *skb,
425 u16 skew)
426{
427 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
David Howells146d8fe2017-03-04 00:01:41 +0000428 enum rxrpc_call_state state;
David Howells775e5b72016-09-30 13:26:03 +0100429 unsigned int offset = sizeof(struct rxrpc_wire_header);
David Howells248f2192016-09-08 11:10:12 +0100430 unsigned int ix;
431 rxrpc_serial_t serial = sp->hdr.serial, ack_serial = 0;
432 rxrpc_seq_t seq = sp->hdr.seq, hard_ack;
David Howells75e42122016-09-13 22:36:22 +0100433 bool immediate_ack = false, jumbo_bad = false, queued;
David Howells248f2192016-09-08 11:10:12 +0100434 u16 len;
435 u8 ack = 0, flags, annotation = 0;
436
437 _enter("{%u,%u},{%u,%u}",
David Howells89a80ed2016-09-13 22:36:22 +0100438 call->rx_hard_ack, call->rx_top, skb->len, seq);
David Howells248f2192016-09-08 11:10:12 +0100439
440 _proto("Rx DATA %%%u { #%u f=%02x }",
441 sp->hdr.serial, seq, sp->hdr.flags);
442
David Howells146d8fe2017-03-04 00:01:41 +0000443 state = READ_ONCE(call->state);
444 if (state >= RXRPC_CALL_COMPLETE)
David Howells248f2192016-09-08 11:10:12 +0100445 return;
446
David Howellsa158bdd2017-11-24 10:18:41 +0000447 if (call->state == RXRPC_CALL_SERVER_RECV_REQUEST) {
448 unsigned long timo = READ_ONCE(call->next_req_timo);
449 unsigned long now, expect_req_by;
450
451 if (timo) {
452 now = jiffies;
453 expect_req_by = now + timo;
454 WRITE_ONCE(call->expect_req_by, expect_req_by);
455 rxrpc_reduce_call_timer(call, expect_req_by, now,
456 rxrpc_timer_set_for_idle);
457 }
458 }
459
David Howells248f2192016-09-08 11:10:12 +0100460 /* Received data implicitly ACKs all of the request packets we sent
461 * when we're acting as a client.
462 */
David Howells146d8fe2017-03-04 00:01:41 +0000463 if ((state == RXRPC_CALL_CLIENT_SEND_REQUEST ||
464 state == RXRPC_CALL_CLIENT_AWAIT_REPLY) &&
David Howells70790dbe2016-09-23 12:39:22 +0100465 !rxrpc_receiving_reply(call))
David Howells248f2192016-09-08 11:10:12 +0100466 return;
467
468 call->ackr_prev_seq = seq;
469
470 hard_ack = READ_ONCE(call->rx_hard_ack);
471 if (after(seq, hard_ack + call->rx_winsize)) {
472 ack = RXRPC_ACK_EXCEEDS_WINDOW;
473 ack_serial = serial;
474 goto ack;
475 }
476
477 flags = sp->hdr.flags;
478 if (flags & RXRPC_JUMBO_PACKET) {
David Howells75e42122016-09-13 22:36:22 +0100479 if (call->nr_jumbo_bad > 3) {
David Howells248f2192016-09-08 11:10:12 +0100480 ack = RXRPC_ACK_NOSPACE;
481 ack_serial = serial;
482 goto ack;
483 }
484 annotation = 1;
485 }
486
487next_subpacket:
488 queued = false;
489 ix = seq & RXRPC_RXTX_BUFF_MASK;
David Howells89a80ed2016-09-13 22:36:22 +0100490 len = skb->len;
David Howells248f2192016-09-08 11:10:12 +0100491 if (flags & RXRPC_JUMBO_PACKET)
492 len = RXRPC_JUMBO_DATALEN;
493
494 if (flags & RXRPC_LAST_PACKET) {
David Howells816c9fc2016-09-17 10:49:11 +0100495 if (test_bit(RXRPC_CALL_RX_LAST, &call->flags) &&
David Howells248f2192016-09-08 11:10:12 +0100496 seq != call->rx_top)
497 return rxrpc_proto_abort("LSN", call, seq);
498 } else {
499 if (test_bit(RXRPC_CALL_RX_LAST, &call->flags) &&
500 after_eq(seq, call->rx_top))
501 return rxrpc_proto_abort("LSA", call, seq);
502 }
503
David Howells4764c0d2018-07-23 17:18:37 +0100504 trace_rxrpc_rx_data(call->debug_id, seq, serial, flags, annotation);
David Howells248f2192016-09-08 11:10:12 +0100505 if (before_eq(seq, hard_ack)) {
506 ack = RXRPC_ACK_DUPLICATE;
507 ack_serial = serial;
508 goto skip;
509 }
510
511 if (flags & RXRPC_REQUEST_ACK && !ack) {
512 ack = RXRPC_ACK_REQUESTED;
513 ack_serial = serial;
514 }
515
516 if (call->rxtx_buffer[ix]) {
David Howells75e42122016-09-13 22:36:22 +0100517 rxrpc_input_dup_data(call, seq, annotation, &jumbo_bad);
David Howells248f2192016-09-08 11:10:12 +0100518 if (ack != RXRPC_ACK_DUPLICATE) {
519 ack = RXRPC_ACK_DUPLICATE;
520 ack_serial = serial;
521 }
522 immediate_ack = true;
523 goto skip;
524 }
525
526 /* Queue the packet. We use a couple of memory barriers here as need
527 * to make sure that rx_top is perceived to be set after the buffer
528 * pointer and that the buffer pointer is set after the annotation and
529 * the skb data.
530 *
531 * Barriers against rxrpc_recvmsg_data() and rxrpc_rotate_rx_window()
532 * and also rxrpc_fill_out_ack().
533 */
David Howells71f3ca42016-09-17 10:49:14 +0100534 rxrpc_get_skb(skb, rxrpc_skb_rx_got);
David Howells248f2192016-09-08 11:10:12 +0100535 call->rxtx_annotations[ix] = annotation;
536 smp_wmb();
537 call->rxtx_buffer[ix] = skb;
David Howellsa7056c52016-09-24 18:05:27 +0100538 if (after(seq, call->rx_top)) {
David Howells248f2192016-09-08 11:10:12 +0100539 smp_store_release(&call->rx_top, seq);
David Howellsa7056c52016-09-24 18:05:27 +0100540 } else if (before(seq, call->rx_top)) {
541 /* Send an immediate ACK if we fill in a hole */
542 if (!ack) {
543 ack = RXRPC_ACK_DELAY;
544 ack_serial = serial;
545 }
546 immediate_ack = true;
547 }
David Howells58dc63c2016-09-17 10:49:13 +0100548 if (flags & RXRPC_LAST_PACKET) {
David Howells816c9fc2016-09-17 10:49:11 +0100549 set_bit(RXRPC_CALL_RX_LAST, &call->flags);
David Howells58dc63c2016-09-17 10:49:13 +0100550 trace_rxrpc_receive(call, rxrpc_receive_queue_last, serial, seq);
551 } else {
552 trace_rxrpc_receive(call, rxrpc_receive_queue, serial, seq);
553 }
David Howells248f2192016-09-08 11:10:12 +0100554 queued = true;
555
556 if (after_eq(seq, call->rx_expect_next)) {
557 if (after(seq, call->rx_expect_next)) {
558 _net("OOS %u > %u", seq, call->rx_expect_next);
559 ack = RXRPC_ACK_OUT_OF_SEQUENCE;
560 ack_serial = serial;
561 }
562 call->rx_expect_next = seq + 1;
563 }
564
565skip:
566 offset += len;
567 if (flags & RXRPC_JUMBO_PACKET) {
568 if (skb_copy_bits(skb, offset, &flags, 1) < 0)
569 return rxrpc_proto_abort("XJF", call, seq);
570 offset += sizeof(struct rxrpc_jumbo_header);
571 seq++;
572 serial++;
573 annotation++;
574 if (flags & RXRPC_JUMBO_PACKET)
575 annotation |= RXRPC_RX_ANNO_JLAST;
David Howells75e42122016-09-13 22:36:22 +0100576 if (after(seq, hard_ack + call->rx_winsize)) {
577 ack = RXRPC_ACK_EXCEEDS_WINDOW;
578 ack_serial = serial;
579 if (!jumbo_bad) {
580 call->nr_jumbo_bad++;
581 jumbo_bad = true;
582 }
583 goto ack;
584 }
David Howells248f2192016-09-08 11:10:12 +0100585
586 _proto("Rx DATA Jumbo %%%u", serial);
587 goto next_subpacket;
588 }
589
590 if (queued && flags & RXRPC_LAST_PACKET && !ack) {
591 ack = RXRPC_ACK_DELAY;
592 ack_serial = serial;
593 }
594
595ack:
596 if (ack)
597 rxrpc_propose_ACK(call, ack, skew, ack_serial,
David Howells9c7ad432016-09-23 13:50:40 +0100598 immediate_ack, true,
599 rxrpc_propose_ack_input_data);
David Howells4764c0d2018-07-23 17:18:37 +0100600 else
601 rxrpc_propose_ACK(call, RXRPC_ACK_DELAY, skew, serial,
602 false, true,
603 rxrpc_propose_ack_input_data);
David Howells248f2192016-09-08 11:10:12 +0100604
David Howells4272d302018-07-23 17:18:37 +0100605 if (sp->hdr.seq == READ_ONCE(call->rx_hard_ack) + 1) {
606 trace_rxrpc_notify_socket(call->debug_id, serial);
David Howells248f2192016-09-08 11:10:12 +0100607 rxrpc_notify_socket(call);
David Howells4272d302018-07-23 17:18:37 +0100608 }
David Howells248f2192016-09-08 11:10:12 +0100609 _leave(" [queued]");
610}
611
612/*
David Howells50235c42016-09-22 00:29:31 +0100613 * Process a requested ACK.
614 */
615static void rxrpc_input_requested_ack(struct rxrpc_call *call,
616 ktime_t resp_time,
617 rxrpc_serial_t orig_serial,
618 rxrpc_serial_t ack_serial)
619{
620 struct rxrpc_skb_priv *sp;
621 struct sk_buff *skb;
622 ktime_t sent_at;
623 int ix;
624
625 for (ix = 0; ix < RXRPC_RXTX_BUFF_SIZE; ix++) {
626 skb = call->rxtx_buffer[ix];
627 if (!skb)
628 continue;
629
David Howellsb604dd92018-09-27 15:13:08 +0100630 sent_at = skb->tstamp;
631 smp_rmb(); /* Read timestamp before serial. */
David Howells50235c42016-09-22 00:29:31 +0100632 sp = rxrpc_skb(skb);
633 if (sp->hdr.serial != orig_serial)
634 continue;
David Howells50235c42016-09-22 00:29:31 +0100635 goto found;
636 }
David Howellsb604dd92018-09-27 15:13:08 +0100637
David Howells50235c42016-09-22 00:29:31 +0100638 return;
639
640found:
641 rxrpc_peer_add_rtt(call, rxrpc_rtt_rx_requested_ack,
642 orig_serial, ack_serial, sent_at, resp_time);
643}
644
645/*
David Howellsbd1fdf82017-11-24 10:18:42 +0000646 * Process the response to a ping that we sent to find out if we lost an ACK.
647 *
648 * If we got back a ping response that indicates a lower tx_top than what we
649 * had at the time of the ping transmission, we adjudge all the DATA packets
650 * sent between the response tx_top and the ping-time tx_top to have been lost.
651 */
652static void rxrpc_input_check_for_lost_ack(struct rxrpc_call *call)
653{
654 rxrpc_seq_t top, bottom, seq;
655 bool resend = false;
656
657 spin_lock_bh(&call->lock);
658
659 bottom = call->tx_hard_ack + 1;
660 top = call->acks_lost_top;
661 if (before(bottom, top)) {
662 for (seq = bottom; before_eq(seq, top); seq++) {
663 int ix = seq & RXRPC_RXTX_BUFF_MASK;
664 u8 annotation = call->rxtx_annotations[ix];
665 u8 anno_type = annotation & RXRPC_TX_ANNO_MASK;
666
667 if (anno_type != RXRPC_TX_ANNO_UNACK)
668 continue;
669 annotation &= ~RXRPC_TX_ANNO_MASK;
670 annotation |= RXRPC_TX_ANNO_RETRANS;
671 call->rxtx_annotations[ix] = annotation;
672 resend = true;
673 }
674 }
675
676 spin_unlock_bh(&call->lock);
677
678 if (resend && !test_and_set_bit(RXRPC_CALL_EV_RESEND, &call->events))
679 rxrpc_queue_call(call);
680}
681
682/*
David Howells8e831342016-09-22 00:29:31 +0100683 * Process a ping response.
684 */
685static void rxrpc_input_ping_response(struct rxrpc_call *call,
686 ktime_t resp_time,
687 rxrpc_serial_t orig_serial,
688 rxrpc_serial_t ack_serial)
689{
690 rxrpc_serial_t ping_serial;
691 ktime_t ping_time;
692
David Howellsa5af7e12016-10-06 08:11:49 +0100693 ping_time = call->ping_time;
David Howells8e831342016-09-22 00:29:31 +0100694 smp_rmb();
David Howellsa5af7e12016-10-06 08:11:49 +0100695 ping_serial = call->ping_serial;
David Howells8e831342016-09-22 00:29:31 +0100696
David Howellsbd1fdf82017-11-24 10:18:42 +0000697 if (orig_serial == call->acks_lost_ping)
698 rxrpc_input_check_for_lost_ack(call);
699
David Howells8e831342016-09-22 00:29:31 +0100700 if (!test_bit(RXRPC_CALL_PINGING, &call->flags) ||
701 before(orig_serial, ping_serial))
702 return;
703 clear_bit(RXRPC_CALL_PINGING, &call->flags);
704 if (after(orig_serial, ping_serial))
705 return;
706
707 rxrpc_peer_add_rtt(call, rxrpc_rtt_rx_ping_response,
708 orig_serial, ack_serial, ping_time, resp_time);
709}
710
711/*
David Howells248f2192016-09-08 11:10:12 +0100712 * Process the extra information that may be appended to an ACK packet
713 */
714static void rxrpc_input_ackinfo(struct rxrpc_call *call, struct sk_buff *skb,
715 struct rxrpc_ackinfo *ackinfo)
716{
717 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
718 struct rxrpc_peer *peer;
719 unsigned int mtu;
David Howells702f2ac2017-03-10 07:48:49 +0000720 bool wake = false;
David Howells01fd0742016-09-13 10:23:01 +0100721 u32 rwind = ntohl(ackinfo->rwind);
David Howells248f2192016-09-08 11:10:12 +0100722
723 _proto("Rx ACK %%%u Info { rx=%u max=%u rwin=%u jm=%u }",
724 sp->hdr.serial,
725 ntohl(ackinfo->rxMTU), ntohl(ackinfo->maxMTU),
David Howells01fd0742016-09-13 10:23:01 +0100726 rwind, ntohl(ackinfo->jumbo_max));
David Howells248f2192016-09-08 11:10:12 +0100727
David Howells702f2ac2017-03-10 07:48:49 +0000728 if (call->tx_winsize != rwind) {
729 if (rwind > RXRPC_RXTX_BUFF_SIZE - 1)
730 rwind = RXRPC_RXTX_BUFF_SIZE - 1;
731 if (rwind > call->tx_winsize)
732 wake = true;
David Howells740586d2017-04-06 10:12:00 +0100733 trace_rxrpc_rx_rwind_change(call, sp->hdr.serial,
734 ntohl(ackinfo->rwind), wake);
David Howells702f2ac2017-03-10 07:48:49 +0000735 call->tx_winsize = rwind;
736 }
737
David Howells08511152016-09-30 09:33:27 +0100738 if (call->cong_ssthresh > rwind)
739 call->cong_ssthresh = rwind;
David Howells248f2192016-09-08 11:10:12 +0100740
741 mtu = min(ntohl(ackinfo->rxMTU), ntohl(ackinfo->maxMTU));
742
743 peer = call->peer;
744 if (mtu < peer->maxdata) {
745 spin_lock_bh(&peer->lock);
746 peer->maxdata = mtu;
747 peer->mtu = mtu + peer->hdrsize;
748 spin_unlock_bh(&peer->lock);
749 _net("Net MTU %u (maxdata %u)", peer->mtu, peer->maxdata);
750 }
David Howells702f2ac2017-03-10 07:48:49 +0000751
752 if (wake)
753 wake_up(&call->waitq);
David Howells248f2192016-09-08 11:10:12 +0100754}
755
756/*
757 * Process individual soft ACKs.
758 *
759 * Each ACK in the array corresponds to one packet and can be either an ACK or
760 * a NAK. If we get find an explicitly NAK'd packet we resend immediately;
761 * packets that lie beyond the end of the ACK list are scheduled for resend by
762 * the timer on the basis that the peer might just not have processed them at
763 * the time the ACK was sent.
764 */
765static void rxrpc_input_soft_acks(struct rxrpc_call *call, u8 *acks,
David Howells31a1b9892016-09-24 18:05:26 +0100766 rxrpc_seq_t seq, int nr_acks,
767 struct rxrpc_ack_summary *summary)
David Howells248f2192016-09-08 11:10:12 +0100768{
David Howells248f2192016-09-08 11:10:12 +0100769 int ix;
David Howellsf07373e2016-09-22 00:29:32 +0100770 u8 annotation, anno_type;
David Howells248f2192016-09-08 11:10:12 +0100771
772 for (; nr_acks > 0; nr_acks--, seq++) {
773 ix = seq & RXRPC_RXTX_BUFF_MASK;
David Howellsf07373e2016-09-22 00:29:32 +0100774 annotation = call->rxtx_annotations[ix];
775 anno_type = annotation & RXRPC_TX_ANNO_MASK;
776 annotation &= ~RXRPC_TX_ANNO_MASK;
David Howellsd01dc4c2016-09-17 10:49:12 +0100777 switch (*acks++) {
David Howells248f2192016-09-08 11:10:12 +0100778 case RXRPC_ACK_TYPE_ACK:
David Howells31a1b9892016-09-24 18:05:26 +0100779 summary->nr_acks++;
David Howellsf07373e2016-09-22 00:29:32 +0100780 if (anno_type == RXRPC_TX_ANNO_ACK)
781 continue;
David Howells31a1b9892016-09-24 18:05:26 +0100782 summary->nr_new_acks++;
David Howellsf07373e2016-09-22 00:29:32 +0100783 call->rxtx_annotations[ix] =
784 RXRPC_TX_ANNO_ACK | annotation;
David Howells248f2192016-09-08 11:10:12 +0100785 break;
786 case RXRPC_ACK_TYPE_NACK:
David Howells31a1b9892016-09-24 18:05:26 +0100787 if (!summary->nr_nacks &&
788 call->acks_lowest_nak != seq) {
789 call->acks_lowest_nak = seq;
790 summary->new_low_nack = true;
791 }
792 summary->nr_nacks++;
David Howellsf07373e2016-09-22 00:29:32 +0100793 if (anno_type == RXRPC_TX_ANNO_NAK)
David Howells248f2192016-09-08 11:10:12 +0100794 continue;
David Howells31a1b9892016-09-24 18:05:26 +0100795 summary->nr_new_nacks++;
David Howellsbe8aa332016-09-23 12:39:23 +0100796 if (anno_type == RXRPC_TX_ANNO_RETRANS)
797 continue;
David Howellsf07373e2016-09-22 00:29:32 +0100798 call->rxtx_annotations[ix] =
799 RXRPC_TX_ANNO_NAK | annotation;
David Howells248f2192016-09-08 11:10:12 +0100800 break;
801 default:
802 return rxrpc_proto_abort("SFT", call, 0);
803 }
804 }
David Howells248f2192016-09-08 11:10:12 +0100805}
806
807/*
808 * Process an ACK packet.
809 *
810 * ack.firstPacket is the sequence number of the first soft-ACK'd/NAK'd packet
811 * in the ACK array. Anything before that is hard-ACK'd and may be discarded.
812 *
813 * A hard-ACK means that a packet has been processed and may be discarded; a
814 * soft-ACK means that the packet may be discarded and retransmission
815 * requested. A phase is complete when all packets are hard-ACK'd.
816 */
817static void rxrpc_input_ack(struct rxrpc_call *call, struct sk_buff *skb,
818 u16 skew)
819{
David Howells31a1b9892016-09-24 18:05:26 +0100820 struct rxrpc_ack_summary summary = { 0 };
David Howells248f2192016-09-08 11:10:12 +0100821 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
822 union {
823 struct rxrpc_ackpacket ack;
824 struct rxrpc_ackinfo info;
825 u8 acks[RXRPC_MAXACKS];
826 } buf;
David Howells8e831342016-09-22 00:29:31 +0100827 rxrpc_serial_t acked_serial;
David Howells248f2192016-09-08 11:10:12 +0100828 rxrpc_seq_t first_soft_ack, hard_ack;
David Howells775e5b72016-09-30 13:26:03 +0100829 int nr_acks, offset, ioffset;
David Howells248f2192016-09-08 11:10:12 +0100830
831 _enter("");
832
David Howells775e5b72016-09-30 13:26:03 +0100833 offset = sizeof(struct rxrpc_wire_header);
834 if (skb_copy_bits(skb, offset, &buf.ack, sizeof(buf.ack)) < 0) {
David Howells248f2192016-09-08 11:10:12 +0100835 _debug("extraction failure");
836 return rxrpc_proto_abort("XAK", call, 0);
837 }
David Howells775e5b72016-09-30 13:26:03 +0100838 offset += sizeof(buf.ack);
David Howells248f2192016-09-08 11:10:12 +0100839
David Howells8e831342016-09-22 00:29:31 +0100840 acked_serial = ntohl(buf.ack.serial);
David Howells248f2192016-09-08 11:10:12 +0100841 first_soft_ack = ntohl(buf.ack.firstPacket);
842 hard_ack = first_soft_ack - 1;
843 nr_acks = buf.ack.nAcks;
David Howells31a1b9892016-09-24 18:05:26 +0100844 summary.ack_reason = (buf.ack.reason < RXRPC_ACK__INVALID ?
845 buf.ack.reason : RXRPC_ACK__INVALID);
David Howells248f2192016-09-08 11:10:12 +0100846
David Howellsb1d9f7fd2017-01-05 10:38:34 +0000847 trace_rxrpc_rx_ack(call, sp->hdr.serial, acked_serial,
848 first_soft_ack, ntohl(buf.ack.previousPacket),
849 summary.ack_reason, nr_acks);
David Howellsec71eb92016-09-17 10:49:13 +0100850
David Howells8e831342016-09-22 00:29:31 +0100851 if (buf.ack.reason == RXRPC_ACK_PING_RESPONSE)
852 rxrpc_input_ping_response(call, skb->tstamp, acked_serial,
853 sp->hdr.serial);
David Howells50235c42016-09-22 00:29:31 +0100854 if (buf.ack.reason == RXRPC_ACK_REQUESTED)
855 rxrpc_input_requested_ack(call, skb->tstamp, acked_serial,
856 sp->hdr.serial);
David Howells8e831342016-09-22 00:29:31 +0100857
David Howells248f2192016-09-08 11:10:12 +0100858 if (buf.ack.reason == RXRPC_ACK_PING) {
859 _proto("Rx ACK %%%u PING Request", sp->hdr.serial);
860 rxrpc_propose_ACK(call, RXRPC_ACK_PING_RESPONSE,
David Howells9c7ad432016-09-23 13:50:40 +0100861 skew, sp->hdr.serial, true, true,
862 rxrpc_propose_ack_respond_to_ping);
David Howells248f2192016-09-08 11:10:12 +0100863 } else if (sp->hdr.flags & RXRPC_REQUEST_ACK) {
864 rxrpc_propose_ACK(call, RXRPC_ACK_REQUESTED,
David Howells9c7ad432016-09-23 13:50:40 +0100865 skew, sp->hdr.serial, true, true,
866 rxrpc_propose_ack_respond_to_ack);
David Howells248f2192016-09-08 11:10:12 +0100867 }
868
David Howells775e5b72016-09-30 13:26:03 +0100869 ioffset = offset + nr_acks + 3;
870 if (skb->len >= ioffset + sizeof(buf.info)) {
871 if (skb_copy_bits(skb, ioffset, &buf.info, sizeof(buf.info)) < 0)
David Howells248f2192016-09-08 11:10:12 +0100872 return rxrpc_proto_abort("XAI", call, 0);
873 rxrpc_input_ackinfo(call, skb, &buf.info);
874 }
875
876 if (first_soft_ack == 0)
877 return rxrpc_proto_abort("AK0", call, 0);
878
879 /* Ignore ACKs unless we are or have just been transmitting. */
David Howells146d8fe2017-03-04 00:01:41 +0000880 switch (READ_ONCE(call->state)) {
David Howells248f2192016-09-08 11:10:12 +0100881 case RXRPC_CALL_CLIENT_SEND_REQUEST:
882 case RXRPC_CALL_CLIENT_AWAIT_REPLY:
883 case RXRPC_CALL_SERVER_SEND_REPLY:
884 case RXRPC_CALL_SERVER_AWAIT_ACK:
885 break;
886 default:
887 return;
888 }
889
890 /* Discard any out-of-order or duplicate ACKs. */
David Howells98dafac2016-09-23 14:04:38 +0100891 if (before_eq(sp->hdr.serial, call->acks_latest)) {
David Howells248f2192016-09-08 11:10:12 +0100892 _debug("discard ACK %d <= %d",
893 sp->hdr.serial, call->acks_latest);
894 return;
895 }
David Howells57494342016-09-24 18:05:27 +0100896 call->acks_latest_ts = skb->tstamp;
David Howells248f2192016-09-08 11:10:12 +0100897 call->acks_latest = sp->hdr.serial;
898
David Howells248f2192016-09-08 11:10:12 +0100899 if (before(hard_ack, call->tx_hard_ack) ||
900 after(hard_ack, call->tx_top))
901 return rxrpc_proto_abort("AKW", call, 0);
David Howells70790dbe2016-09-23 12:39:22 +0100902 if (nr_acks > call->tx_top - hard_ack)
903 return rxrpc_proto_abort("AKN", call, 0);
David Howells248f2192016-09-08 11:10:12 +0100904
David Howellsc479d5f2018-10-08 15:46:01 +0100905 if (after(hard_ack, call->tx_hard_ack)) {
906 if (rxrpc_rotate_tx_window(call, hard_ack, &summary)) {
907 rxrpc_end_tx_phase(call, false, "ETA");
908 return;
909 }
910 }
David Howells248f2192016-09-08 11:10:12 +0100911
David Howells70790dbe2016-09-23 12:39:22 +0100912 if (nr_acks > 0) {
David Howells775e5b72016-09-30 13:26:03 +0100913 if (skb_copy_bits(skb, offset, buf.acks, nr_acks) < 0)
David Howells70790dbe2016-09-23 12:39:22 +0100914 return rxrpc_proto_abort("XSA", call, 0);
David Howells31a1b9892016-09-24 18:05:26 +0100915 rxrpc_input_soft_acks(call, buf.acks, first_soft_ack, nr_acks,
916 &summary);
David Howells70790dbe2016-09-23 12:39:22 +0100917 }
David Howells248f2192016-09-08 11:10:12 +0100918
David Howells0d967962016-09-24 18:05:27 +0100919 if (call->rxtx_annotations[call->tx_top & RXRPC_RXTX_BUFF_MASK] &
920 RXRPC_TX_ANNO_LAST &&
David Howellsa9f312d2016-10-06 08:11:49 +0100921 summary.nr_acks == call->tx_top - hard_ack &&
922 rxrpc_is_client_call(call))
David Howells0d967962016-09-24 18:05:27 +0100923 rxrpc_propose_ACK(call, RXRPC_ACK_PING, skew, sp->hdr.serial,
924 false, true,
925 rxrpc_propose_ack_ping_for_lost_reply);
David Howells57494342016-09-24 18:05:27 +0100926
David Howellsed1e8672016-09-29 22:37:16 +0100927 return rxrpc_congestion_management(call, skb, &summary, acked_serial);
David Howells248f2192016-09-08 11:10:12 +0100928}
929
930/*
931 * Process an ACKALL packet.
932 */
933static void rxrpc_input_ackall(struct rxrpc_call *call, struct sk_buff *skb)
934{
David Howells31a1b9892016-09-24 18:05:26 +0100935 struct rxrpc_ack_summary summary = { 0 };
David Howells248f2192016-09-08 11:10:12 +0100936 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
937
938 _proto("Rx ACKALL %%%u", sp->hdr.serial);
939
David Howellsc479d5f2018-10-08 15:46:01 +0100940 if (rxrpc_rotate_tx_window(call, call->tx_top, &summary))
David Howells70790dbe2016-09-23 12:39:22 +0100941 rxrpc_end_tx_phase(call, false, "ETL");
David Howells248f2192016-09-08 11:10:12 +0100942}
943
944/*
David Howells005ede22017-04-06 10:12:00 +0100945 * Process an ABORT packet directed at a call.
David Howells248f2192016-09-08 11:10:12 +0100946 */
947static void rxrpc_input_abort(struct rxrpc_call *call, struct sk_buff *skb)
David Howells17926a72007-04-26 15:48:28 -0700948{
949 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
David Howells0d12f8a2016-03-04 15:53:46 +0000950 __be32 wtmp;
David Howells248f2192016-09-08 11:10:12 +0100951 u32 abort_code = RX_CALL_DEAD;
952
953 _enter("");
954
955 if (skb->len >= 4 &&
David Howells775e5b72016-09-30 13:26:03 +0100956 skb_copy_bits(skb, sizeof(struct rxrpc_wire_header),
957 &wtmp, sizeof(wtmp)) >= 0)
David Howells248f2192016-09-08 11:10:12 +0100958 abort_code = ntohl(wtmp);
959
David Howells005ede22017-04-06 10:12:00 +0100960 trace_rxrpc_rx_abort(call, sp->hdr.serial, abort_code);
961
David Howells248f2192016-09-08 11:10:12 +0100962 _proto("Rx ABORT %%%u { %x }", sp->hdr.serial, abort_code);
963
964 if (rxrpc_set_call_completion(call, RXRPC_CALL_REMOTELY_ABORTED,
David Howells3a927892017-04-06 10:11:56 +0100965 abort_code, -ECONNABORTED))
David Howells248f2192016-09-08 11:10:12 +0100966 rxrpc_notify_socket(call);
967}
968
969/*
970 * Process an incoming call packet.
971 */
972static void rxrpc_input_call_packet(struct rxrpc_call *call,
973 struct sk_buff *skb, u16 skew)
974{
975 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
David Howellsa158bdd2017-11-24 10:18:41 +0000976 unsigned long timo;
David Howells17926a72007-04-26 15:48:28 -0700977
978 _enter("%p,%p", call, skb);
979
David Howellsa158bdd2017-11-24 10:18:41 +0000980 timo = READ_ONCE(call->next_rx_timo);
981 if (timo) {
982 unsigned long now = jiffies, expect_rx_by;
983
David Howellsc54e43d2018-05-10 23:26:00 +0100984 expect_rx_by = now + timo;
David Howellsa158bdd2017-11-24 10:18:41 +0000985 WRITE_ONCE(call->expect_rx_by, expect_rx_by);
986 rxrpc_reduce_call_timer(call, expect_rx_by, now,
987 rxrpc_timer_set_for_normal);
988 }
David Howells3d7682a2017-11-29 14:25:50 +0000989
David Howells17926a72007-04-26 15:48:28 -0700990 switch (sp->hdr.type) {
David Howells248f2192016-09-08 11:10:12 +0100991 case RXRPC_PACKET_TYPE_DATA:
992 rxrpc_input_data(call, skb, skew);
993 break;
David Howells17926a72007-04-26 15:48:28 -0700994
David Howells248f2192016-09-08 11:10:12 +0100995 case RXRPC_PACKET_TYPE_ACK:
996 rxrpc_input_ack(call, skb, skew);
997 break;
David Howells17926a72007-04-26 15:48:28 -0700998
999 case RXRPC_PACKET_TYPE_BUSY:
David Howells0d12f8a2016-03-04 15:53:46 +00001000 _proto("Rx BUSY %%%u", sp->hdr.serial);
David Howells17926a72007-04-26 15:48:28 -07001001
David Howells248f2192016-09-08 11:10:12 +01001002 /* Just ignore BUSY packets from the server; the retry and
1003 * lifespan timers will take care of business. BUSY packets
1004 * from the client don't make sense.
1005 */
1006 break;
David Howells17926a72007-04-26 15:48:28 -07001007
David Howells248f2192016-09-08 11:10:12 +01001008 case RXRPC_PACKET_TYPE_ABORT:
1009 rxrpc_input_abort(call, skb);
1010 break;
1011
1012 case RXRPC_PACKET_TYPE_ACKALL:
1013 rxrpc_input_ackall(call, skb);
1014 break;
David Howells17926a72007-04-26 15:48:28 -07001015
1016 default:
David Howells17926a72007-04-26 15:48:28 -07001017 break;
1018 }
1019
David Howells17926a72007-04-26 15:48:28 -07001020 _leave("");
1021}
1022
1023/*
David Howellsb31562742016-10-06 08:11:49 +01001024 * Handle a new call on a channel implicitly completing the preceding call on
1025 * that channel.
1026 *
1027 * TODO: If callNumber > call_id + 1, renegotiate security.
1028 */
1029static void rxrpc_input_implicit_end_call(struct rxrpc_connection *conn,
1030 struct rxrpc_call *call)
1031{
David Howells146d8fe2017-03-04 00:01:41 +00001032 switch (READ_ONCE(call->state)) {
David Howellsb31562742016-10-06 08:11:49 +01001033 case RXRPC_CALL_SERVER_AWAIT_ACK:
1034 rxrpc_call_completed(call);
1035 break;
1036 case RXRPC_CALL_COMPLETE:
1037 break;
1038 default:
David Howells3a927892017-04-06 10:11:56 +01001039 if (rxrpc_abort_call("IMP", call, 0, RX_CALL_DEAD, -ESHUTDOWN)) {
David Howellsb31562742016-10-06 08:11:49 +01001040 set_bit(RXRPC_CALL_EV_ABORT, &call->events);
1041 rxrpc_queue_call(call);
1042 }
1043 break;
1044 }
1045
David Howellsb1d9f7fd2017-01-05 10:38:34 +00001046 trace_rxrpc_improper_term(call);
David Howellsb31562742016-10-06 08:11:49 +01001047 __rxrpc_disconnect_call(conn, call);
1048 rxrpc_notify_socket(call);
1049}
1050
1051/*
David Howells17926a72007-04-26 15:48:28 -07001052 * post connection-level events to the connection
David Howells18bfeba2016-08-23 15:27:25 +01001053 * - this includes challenges, responses, some aborts and call terminal packet
1054 * retransmission.
David Howells17926a72007-04-26 15:48:28 -07001055 */
David Howells2e7e9752016-08-09 10:11:48 +01001056static void rxrpc_post_packet_to_conn(struct rxrpc_connection *conn,
David Howells17926a72007-04-26 15:48:28 -07001057 struct sk_buff *skb)
1058{
1059 _enter("%p,%p", conn, skb);
1060
David Howells17926a72007-04-26 15:48:28 -07001061 skb_queue_tail(&conn->rx_queue, skb);
David Howells2e7e9752016-08-09 10:11:48 +01001062 rxrpc_queue_conn(conn);
David Howells17926a72007-04-26 15:48:28 -07001063}
1064
David Howells44ba0692015-04-01 16:31:26 +01001065/*
1066 * post endpoint-level events to the local endpoint
1067 * - this includes debug and version messages
1068 */
1069static void rxrpc_post_packet_to_local(struct rxrpc_local *local,
1070 struct sk_buff *skb)
1071{
1072 _enter("%p,%p", local, skb);
1073
David Howells44ba0692015-04-01 16:31:26 +01001074 skb_queue_tail(&local->event_queue, skb);
David Howells5acbee42016-06-27 10:32:02 +01001075 rxrpc_queue_local(local);
David Howells44ba0692015-04-01 16:31:26 +01001076}
1077
David Howells0d12f8a2016-03-04 15:53:46 +00001078/*
David Howells248f2192016-09-08 11:10:12 +01001079 * put a packet up for transport-level abort
1080 */
1081static void rxrpc_reject_packet(struct rxrpc_local *local, struct sk_buff *skb)
1082{
1083 CHECK_SLAB_OKAY(&local->usage);
1084
1085 skb_queue_tail(&local->reject_queue, skb);
1086 rxrpc_queue_local(local);
1087}
1088
1089/*
David Howells0d12f8a2016-03-04 15:53:46 +00001090 * Extract the wire header from a packet and translate the byte order.
1091 */
1092static noinline
1093int rxrpc_extract_header(struct rxrpc_skb_priv *sp, struct sk_buff *skb)
1094{
1095 struct rxrpc_wire_header whdr;
1096
1097 /* dig out the RxRPC connection details */
David Howellsfb46f6e2017-04-06 10:12:00 +01001098 if (skb_copy_bits(skb, 0, &whdr, sizeof(whdr)) < 0) {
1099 trace_rxrpc_rx_eproto(NULL, sp->hdr.serial,
1100 tracepoint_string("bad_hdr"));
David Howells0d12f8a2016-03-04 15:53:46 +00001101 return -EBADMSG;
David Howellsfb46f6e2017-04-06 10:12:00 +01001102 }
David Howells0d12f8a2016-03-04 15:53:46 +00001103
1104 memset(sp, 0, sizeof(*sp));
1105 sp->hdr.epoch = ntohl(whdr.epoch);
1106 sp->hdr.cid = ntohl(whdr.cid);
1107 sp->hdr.callNumber = ntohl(whdr.callNumber);
1108 sp->hdr.seq = ntohl(whdr.seq);
1109 sp->hdr.serial = ntohl(whdr.serial);
1110 sp->hdr.flags = whdr.flags;
1111 sp->hdr.type = whdr.type;
1112 sp->hdr.userStatus = whdr.userStatus;
1113 sp->hdr.securityIndex = whdr.securityIndex;
1114 sp->hdr._rsvd = ntohs(whdr._rsvd);
1115 sp->hdr.serviceId = ntohs(whdr.serviceId);
1116 return 0;
1117}
1118
David Howells17926a72007-04-26 15:48:28 -07001119/*
1120 * handle data received on the local endpoint
1121 * - may be called in interrupt context
David Howells4f95dd72016-04-04 14:00:35 +01001122 *
1123 * The socket is locked by the caller and this prevents the socket from being
1124 * shut down and the local endpoint from going away, thus sk_user_data will not
1125 * be cleared until this function returns.
David Howellsbfd28212018-10-08 15:45:56 +01001126 *
1127 * Called with the RCU read lock held from the IP layer via UDP.
David Howells17926a72007-04-26 15:48:28 -07001128 */
David Howells52719532018-10-04 11:10:51 +01001129int rxrpc_input_packet(struct sock *udp_sk, struct sk_buff *skb)
David Howells17926a72007-04-26 15:48:28 -07001130{
David Howells8496af52016-07-01 07:51:50 +01001131 struct rxrpc_connection *conn;
David Howells248f2192016-09-08 11:10:12 +01001132 struct rxrpc_channel *chan;
David Howells403fc2a2018-09-27 15:13:08 +01001133 struct rxrpc_call *call = NULL;
David Howells17926a72007-04-26 15:48:28 -07001134 struct rxrpc_skb_priv *sp;
David Howells248f2192016-09-08 11:10:12 +01001135 struct rxrpc_local *local = udp_sk->sk_user_data;
David Howells0099dc52018-09-27 15:13:09 +01001136 struct rxrpc_peer *peer = NULL;
1137 struct rxrpc_sock *rx = NULL;
David Howells248f2192016-09-08 11:10:12 +01001138 unsigned int channel;
David Howells2cfa2272018-10-05 14:05:35 +01001139 int skew = 0;
David Howells17926a72007-04-26 15:48:28 -07001140
David Howells248f2192016-09-08 11:10:12 +01001141 _enter("%p", udp_sk);
David Howells17926a72007-04-26 15:48:28 -07001142
David Howells52719532018-10-04 11:10:51 +01001143 if (skb->tstamp == 0)
1144 skb->tstamp = ktime_get_real();
1145
1146 rxrpc_new_skb(skb, rxrpc_skb_rx_received);
1147
1148 skb_pull(skb, sizeof(struct udphdr));
1149
Paolo Abeni7c13f972016-11-04 11:28:59 +01001150 /* The UDP protocol already released all skb resources;
1151 * we are free to add our own data there.
David Howells0d12f8a2016-03-04 15:53:46 +00001152 */
David Howells17926a72007-04-26 15:48:28 -07001153 sp = rxrpc_skb(skb);
David Howells17926a72007-04-26 15:48:28 -07001154
David Howells89b475a2016-09-23 12:39:22 +01001155 /* dig out the RxRPC connection details */
1156 if (rxrpc_extract_header(sp, skb) < 0)
1157 goto bad_message;
1158
David Howells8a681c362016-09-17 10:49:15 +01001159 if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) {
1160 static int lose;
1161 if ((lose++ & 7) == 7) {
David Howells89b475a2016-09-23 12:39:22 +01001162 trace_rxrpc_rx_lose(sp);
David Howells52719532018-10-04 11:10:51 +01001163 rxrpc_free_skb(skb, rxrpc_skb_rx_lost);
1164 return 0;
David Howells8a681c362016-09-17 10:49:15 +01001165 }
1166 }
1167
David Howells2cfa2272018-10-05 14:05:35 +01001168 if (skb->tstamp == 0)
1169 skb->tstamp = ktime_get_real();
David Howells49e19ec2016-09-08 11:10:12 +01001170 trace_rxrpc_rx_packet(sp);
David Howells17926a72007-04-26 15:48:28 -07001171
David Howells248f2192016-09-08 11:10:12 +01001172 switch (sp->hdr.type) {
1173 case RXRPC_PACKET_TYPE_VERSION:
David Howellsdc71db32018-09-27 15:13:08 +01001174 if (rxrpc_to_client(sp))
David Howellsace45be2018-03-30 21:04:43 +01001175 goto discard;
David Howells44ba0692015-04-01 16:31:26 +01001176 rxrpc_post_packet_to_local(local, skb);
1177 goto out;
David Howellsbc6e1ea2016-06-10 22:30:27 +01001178
David Howells248f2192016-09-08 11:10:12 +01001179 case RXRPC_PACKET_TYPE_BUSY:
David Howellsdc71db32018-09-27 15:13:08 +01001180 if (rxrpc_to_server(sp))
David Howells248f2192016-09-08 11:10:12 +01001181 goto discard;
Gustavo A. R. Silvae3cf39702017-10-19 16:54:48 -05001182 /* Fall through */
David Howells403fc2a2018-09-27 15:13:08 +01001183 case RXRPC_PACKET_TYPE_ACK:
1184 case RXRPC_PACKET_TYPE_ACKALL:
1185 if (sp->hdr.callNumber == 0)
1186 goto bad_message;
1187 /* Fall through */
1188 case RXRPC_PACKET_TYPE_ABORT:
1189 break;
David Howells248f2192016-09-08 11:10:12 +01001190
1191 case RXRPC_PACKET_TYPE_DATA:
David Howells403fc2a2018-09-27 15:13:08 +01001192 if (sp->hdr.callNumber == 0 ||
1193 sp->hdr.seq == 0)
David Howells248f2192016-09-08 11:10:12 +01001194 goto bad_message;
1195 if (sp->hdr.flags & RXRPC_JUMBO_PACKET &&
1196 !rxrpc_validate_jumbo(skb))
1197 goto bad_message;
1198 break;
David Howellsb41d7cf2018-04-02 23:51:39 +01001199
David Howells403fc2a2018-09-27 15:13:08 +01001200 case RXRPC_PACKET_TYPE_CHALLENGE:
1201 if (rxrpc_to_server(sp))
1202 goto discard;
1203 break;
1204 case RXRPC_PACKET_TYPE_RESPONSE:
1205 if (rxrpc_to_client(sp))
1206 goto discard;
1207 break;
1208
David Howellsb41d7cf2018-04-02 23:51:39 +01001209 /* Packet types 9-11 should just be ignored. */
1210 case RXRPC_PACKET_TYPE_PARAMS:
1211 case RXRPC_PACKET_TYPE_10:
1212 case RXRPC_PACKET_TYPE_11:
1213 goto discard;
David Howells403fc2a2018-09-27 15:13:08 +01001214
1215 default:
1216 _proto("Rx Bad Packet Type %u", sp->hdr.type);
1217 goto bad_message;
David Howells248f2192016-09-08 11:10:12 +01001218 }
David Howells17926a72007-04-26 15:48:28 -07001219
David Howells403fc2a2018-09-27 15:13:08 +01001220 if (sp->hdr.serviceId == 0)
1221 goto bad_message;
1222
David Howells403fc2a2018-09-27 15:13:08 +01001223 if (rxrpc_to_server(sp)) {
1224 /* Weed out packets to services we're not offering. Packets
1225 * that would begin a call are explicitly rejected and the rest
1226 * are just discarded.
1227 */
1228 rx = rcu_dereference(local->service);
1229 if (!rx || (sp->hdr.serviceId != rx->srx.srx_service &&
1230 sp->hdr.serviceId != rx->second_service)) {
1231 if (sp->hdr.type == RXRPC_PACKET_TYPE_DATA &&
1232 sp->hdr.seq == 1)
1233 goto unsupported_service;
David Howellsbfd28212018-10-08 15:45:56 +01001234 goto discard;
David Howells403fc2a2018-09-27 15:13:08 +01001235 }
1236 }
1237
David Howells0099dc52018-09-27 15:13:09 +01001238 conn = rxrpc_find_connection_rcu(local, skb, &peer);
David Howells248f2192016-09-08 11:10:12 +01001239 if (conn) {
1240 if (sp->hdr.securityIndex != conn->security_ix)
1241 goto wrong_security;
David Howells563ea7d2016-08-23 15:27:25 +01001242
David Howells4e255722017-06-05 14:30:49 +01001243 if (sp->hdr.serviceId != conn->service_id) {
1244 if (!test_bit(RXRPC_CONN_PROBING_FOR_UPGRADE, &conn->flags) ||
1245 conn->service_id != conn->params.service_id)
1246 goto reupgrade;
1247 conn->service_id = sp->hdr.serviceId;
1248 }
David Howells3d7682a2017-11-29 14:25:50 +00001249
David Howells248f2192016-09-08 11:10:12 +01001250 if (sp->hdr.callNumber == 0) {
1251 /* Connection-level packet */
1252 _debug("CONN %p {%d}", conn, conn->debug_id);
1253 rxrpc_post_packet_to_conn(conn, skb);
David Howellsbfd28212018-10-08 15:45:56 +01001254 goto out;
David Howells248f2192016-09-08 11:10:12 +01001255 }
David Howells8496af52016-07-01 07:51:50 +01001256
David Howells248f2192016-09-08 11:10:12 +01001257 /* Note the serial number skew here */
1258 skew = (int)sp->hdr.serial - (int)conn->hi_serial;
1259 if (skew >= 0) {
1260 if (skew > 0)
1261 conn->hi_serial = sp->hdr.serial;
1262 } else {
1263 skew = -skew;
1264 skew = min(skew, 65535);
1265 }
1266
David Howells8496af52016-07-01 07:51:50 +01001267 /* Call-bound packets are routed by connection channel. */
David Howells248f2192016-09-08 11:10:12 +01001268 channel = sp->hdr.cid & RXRPC_CHANNELMASK;
1269 chan = &conn->channels[channel];
Tim Smith77276402014-03-03 23:04:45 +00001270
David Howells18bfeba2016-08-23 15:27:25 +01001271 /* Ignore really old calls */
1272 if (sp->hdr.callNumber < chan->last_call)
David Howellsbfd28212018-10-08 15:45:56 +01001273 goto discard;
David Howells18bfeba2016-08-23 15:27:25 +01001274
1275 if (sp->hdr.callNumber == chan->last_call) {
David Howells57b0c9d2018-03-30 21:04:44 +01001276 if (chan->call ||
1277 sp->hdr.type == RXRPC_PACKET_TYPE_ABORT)
David Howellsbfd28212018-10-08 15:45:56 +01001278 goto discard;
David Howells18bfeba2016-08-23 15:27:25 +01001279
David Howells57b0c9d2018-03-30 21:04:44 +01001280 /* For the previous service call, if completed
1281 * successfully, we discard all further packets.
1282 */
1283 if (rxrpc_conn_is_service(conn) &&
1284 chan->last_type == RXRPC_PACKET_TYPE_ACK)
David Howellsbfd28212018-10-08 15:45:56 +01001285 goto discard;
David Howells57b0c9d2018-03-30 21:04:44 +01001286
1287 /* But otherwise we need to retransmit the final packet
1288 * from data cached in the connection record.
David Howells18bfeba2016-08-23 15:27:25 +01001289 */
David Howells4764c0d2018-07-23 17:18:37 +01001290 if (sp->hdr.type == RXRPC_PACKET_TYPE_DATA)
1291 trace_rxrpc_rx_data(chan->call_debug_id,
1292 sp->hdr.seq,
1293 sp->hdr.serial,
1294 sp->hdr.flags, 0);
David Howells18bfeba2016-08-23 15:27:25 +01001295 rxrpc_post_packet_to_conn(conn, skb);
David Howellsbfd28212018-10-08 15:45:56 +01001296 goto out;
David Howells18bfeba2016-08-23 15:27:25 +01001297 }
1298
1299 call = rcu_dereference(chan->call);
David Howellsb31562742016-10-06 08:11:49 +01001300
1301 if (sp->hdr.callNumber > chan->call_id) {
David Howellsbfd28212018-10-08 15:45:56 +01001302 if (rxrpc_to_client(sp))
David Howellsb31562742016-10-06 08:11:49 +01001303 goto reject_packet;
David Howellsb31562742016-10-06 08:11:49 +01001304 if (call)
1305 rxrpc_input_implicit_end_call(conn, call);
1306 call = NULL;
1307 }
David Howells4e255722017-06-05 14:30:49 +01001308
David Howells1a025022018-06-03 02:17:39 +01001309 if (call) {
1310 if (sp->hdr.serviceId != call->service_id)
1311 call->service_id = sp->hdr.serviceId;
1312 if ((int)sp->hdr.serial - (int)call->rx_serial > 0)
1313 call->rx_serial = sp->hdr.serial;
1314 if (!test_bit(RXRPC_CALL_RX_HEARD, &call->flags))
1315 set_bit(RXRPC_CALL_RX_HEARD, &call->flags);
1316 }
Tim Smith77276402014-03-03 23:04:45 +00001317 }
David Howells44ba0692015-04-01 16:31:26 +01001318
David Howells248f2192016-09-08 11:10:12 +01001319 if (!call || atomic_read(&call->usage) == 0) {
David Howellsdc71db32018-09-27 15:13:08 +01001320 if (rxrpc_to_client(sp) ||
David Howells248f2192016-09-08 11:10:12 +01001321 sp->hdr.type != RXRPC_PACKET_TYPE_DATA)
David Howellsbfd28212018-10-08 15:45:56 +01001322 goto bad_message;
David Howells248f2192016-09-08 11:10:12 +01001323 if (sp->hdr.seq != 1)
David Howellsbfd28212018-10-08 15:45:56 +01001324 goto discard;
David Howells0099dc52018-09-27 15:13:09 +01001325 call = rxrpc_new_incoming_call(local, rx, peer, conn, skb);
David Howellsbfd28212018-10-08 15:45:56 +01001326 if (!call)
David Howells248f2192016-09-08 11:10:12 +01001327 goto reject_packet;
David Howells8e831342016-09-22 00:29:31 +01001328 rxrpc_send_ping(call, skb, skew);
David Howells540b1c42017-02-27 15:43:06 +00001329 mutex_unlock(&call->user_mutex);
David Howells248f2192016-09-08 11:10:12 +01001330 }
1331
1332 rxrpc_input_call_packet(call, skb, skew);
David Howellsbfd28212018-10-08 15:45:56 +01001333 goto discard;
David Howells248f2192016-09-08 11:10:12 +01001334
David Howells248f2192016-09-08 11:10:12 +01001335discard:
David Howells71f3ca42016-09-17 10:49:14 +01001336 rxrpc_free_skb(skb, rxrpc_skb_rx_freed);
David Howells44ba0692015-04-01 16:31:26 +01001337out:
David Howells49e19ec2016-09-08 11:10:12 +01001338 trace_rxrpc_rx_done(0, 0);
David Howells52719532018-10-04 11:10:51 +01001339 return 0;
David Howells17926a72007-04-26 15:48:28 -07001340
David Howells248f2192016-09-08 11:10:12 +01001341wrong_security:
David Howellsa25e21f2018-03-27 23:03:00 +01001342 trace_rxrpc_abort(0, "SEC", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq,
David Howells248f2192016-09-08 11:10:12 +01001343 RXKADINCONSISTENCY, EBADMSG);
1344 skb->priority = RXKADINCONSISTENCY;
1345 goto post_abort;
David Howells17926a72007-04-26 15:48:28 -07001346
David Howells403fc2a2018-09-27 15:13:08 +01001347unsupported_service:
David Howells403fc2a2018-09-27 15:13:08 +01001348 trace_rxrpc_abort(0, "INV", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq,
1349 RX_INVALID_OPERATION, EOPNOTSUPP);
1350 skb->priority = RX_INVALID_OPERATION;
1351 goto post_abort;
1352
David Howells4e255722017-06-05 14:30:49 +01001353reupgrade:
David Howellsa25e21f2018-03-27 23:03:00 +01001354 trace_rxrpc_abort(0, "UPG", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq,
David Howells4e255722017-06-05 14:30:49 +01001355 RX_PROTOCOL_ERROR, EBADMSG);
1356 goto protocol_error;
1357
David Howells17926a72007-04-26 15:48:28 -07001358bad_message:
David Howellsa25e21f2018-03-27 23:03:00 +01001359 trace_rxrpc_abort(0, "BAD", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq,
David Howells248f2192016-09-08 11:10:12 +01001360 RX_PROTOCOL_ERROR, EBADMSG);
David Howells4e255722017-06-05 14:30:49 +01001361protocol_error:
David Howells17926a72007-04-26 15:48:28 -07001362 skb->priority = RX_PROTOCOL_ERROR;
David Howells248f2192016-09-08 11:10:12 +01001363post_abort:
David Howellsece64fe2018-09-27 15:13:08 +01001364 skb->mark = RXRPC_SKB_MARK_REJECT_ABORT;
David Howells49e19ec2016-09-08 11:10:12 +01001365reject_packet:
1366 trace_rxrpc_rx_done(skb->mark, skb->priority);
David Howells17926a72007-04-26 15:48:28 -07001367 rxrpc_reject_packet(local, skb);
David Howells17926a72007-04-26 15:48:28 -07001368 _leave(" [badmsg]");
David Howells52719532018-10-04 11:10:51 +01001369 return 0;
David Howells2cfa2272018-10-05 14:05:35 +01001370}