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