ar-skbuff.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* ar-skbuff.c: socket buffer destruction handling
  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. #include <linux/module.h>
  12. #include <linux/net.h>
  13. #include <linux/skbuff.h>
  14. #include <net/sock.h>
  15. #include <net/af_rxrpc.h>
  16. #include "ar-internal.h"
  17. /*
  18. * set up for the ACK at the end of the receive phase when we discard the final
  19. * receive phase data packet
  20. * - called with softirqs disabled
  21. */
  22. static void rxrpc_request_final_ACK(struct rxrpc_call *call)
  23. {
  24. /* the call may be aborted before we have a chance to ACK it */
  25. write_lock(&call->state_lock);
  26. switch (call->state) {
  27. case RXRPC_CALL_CLIENT_RECV_REPLY:
  28. call->state = RXRPC_CALL_CLIENT_FINAL_ACK;
  29. _debug("request final ACK");
  30. /* get an extra ref on the call for the final-ACK generator to
  31. * release */
  32. rxrpc_get_call(call);
  33. set_bit(RXRPC_CALL_ACK_FINAL, &call->events);
  34. if (try_to_del_timer_sync(&call->ack_timer) >= 0)
  35. rxrpc_queue_call(call);
  36. break;
  37. case RXRPC_CALL_SERVER_RECV_REQUEST:
  38. call->state = RXRPC_CALL_SERVER_ACK_REQUEST;
  39. default:
  40. break;
  41. }
  42. write_unlock(&call->state_lock);
  43. }
  44. /*
  45. * drop the bottom ACK off of the call ACK window and advance the window
  46. */
  47. static void rxrpc_hard_ACK_data(struct rxrpc_call *call,
  48. struct rxrpc_skb_priv *sp)
  49. {
  50. int loop;
  51. u32 seq;
  52. spin_lock_bh(&call->lock);
  53. _debug("hard ACK #%u", ntohl(sp->hdr.seq));
  54. for (loop = 0; loop < RXRPC_ACKR_WINDOW_ASZ; loop++) {
  55. call->ackr_window[loop] >>= 1;
  56. call->ackr_window[loop] |=
  57. call->ackr_window[loop + 1] << (BITS_PER_LONG - 1);
  58. }
  59. seq = ntohl(sp->hdr.seq);
  60. ASSERTCMP(seq, ==, call->rx_data_eaten + 1);
  61. call->rx_data_eaten = seq;
  62. if (call->ackr_win_top < UINT_MAX)
  63. call->ackr_win_top++;
  64. ASSERTIFCMP(call->state <= RXRPC_CALL_COMPLETE,
  65. call->rx_data_post, >=, call->rx_data_recv);
  66. ASSERTIFCMP(call->state <= RXRPC_CALL_COMPLETE,
  67. call->rx_data_recv, >=, call->rx_data_eaten);
  68. if (sp->hdr.flags & RXRPC_LAST_PACKET) {
  69. rxrpc_request_final_ACK(call);
  70. } else if (atomic_dec_and_test(&call->ackr_not_idle) &&
  71. test_and_clear_bit(RXRPC_CALL_TX_SOFT_ACK, &call->flags)) {
  72. /* We previously soft-ACK'd some received packets that have now
  73. * been consumed, so send a hard-ACK if no more packets are
  74. * immediately forthcoming to allow the transmitter to free up
  75. * its Tx bufferage.
  76. */
  77. _debug("send Rx idle ACK");
  78. __rxrpc_propose_ACK(call, RXRPC_ACK_IDLE, sp->hdr.serial,
  79. false);
  80. }
  81. spin_unlock_bh(&call->lock);
  82. }
  83. /*
  84. * destroy a packet that has an RxRPC control buffer
  85. * - advance the hard-ACK state of the parent call (done here in case something
  86. * in the kernel bypasses recvmsg() and steals the packet directly off of the
  87. * socket receive queue)
  88. */
  89. void rxrpc_packet_destructor(struct sk_buff *skb)
  90. {
  91. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  92. struct rxrpc_call *call = sp->call;
  93. _enter("%p{%p}", skb, call);
  94. if (call) {
  95. /* send the final ACK on a client call */
  96. if (sp->hdr.type == RXRPC_PACKET_TYPE_DATA)
  97. rxrpc_hard_ACK_data(call, sp);
  98. rxrpc_put_call(call);
  99. sp->call = NULL;
  100. }
  101. if (skb->sk)
  102. sock_rfree(skb);
  103. _leave("");
  104. }
  105. /**
  106. * rxrpc_kernel_free_skb - Free an RxRPC socket buffer
  107. * @skb: The socket buffer to be freed
  108. *
  109. * Let RxRPC free its own socket buffer, permitting it to maintain debug
  110. * accounting.
  111. */
  112. void rxrpc_kernel_free_skb(struct sk_buff *skb)
  113. {
  114. rxrpc_free_skb(skb);
  115. }
  116. EXPORT_SYMBOL(rxrpc_kernel_free_skb);