1 /* ar-skbuff.c: socket buffer destruction handling
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 #include <linux/module.h>
15 #include <linux/net.h>
16 #include <linux/skbuff.h>
18 #include <net/af_rxrpc.h>
19 #include "ar-internal.h"
22 * set up for the ACK at the end of the receive phase when we discard the final
23 * receive phase data packet
24 * - called with softirqs disabled
26 static void rxrpc_request_final_ACK(struct rxrpc_call
*call
)
28 /* the call may be aborted before we have a chance to ACK it */
29 write_lock(&call
->state_lock
);
31 switch (call
->state
) {
32 case RXRPC_CALL_CLIENT_RECV_REPLY
:
33 call
->state
= RXRPC_CALL_CLIENT_FINAL_ACK
;
34 _debug("request final ACK");
36 /* get an extra ref on the call for the final-ACK generator to
39 set_bit(RXRPC_CALL_EV_ACK_FINAL
, &call
->events
);
40 if (try_to_del_timer_sync(&call
->ack_timer
) >= 0)
41 rxrpc_queue_call(call
);
44 case RXRPC_CALL_SERVER_RECV_REQUEST
:
45 call
->state
= RXRPC_CALL_SERVER_ACK_REQUEST
;
50 write_unlock(&call
->state_lock
);
54 * drop the bottom ACK off of the call ACK window and advance the window
56 static void rxrpc_hard_ACK_data(struct rxrpc_call
*call
,
57 struct rxrpc_skb_priv
*sp
)
62 spin_lock_bh(&call
->lock
);
64 _debug("hard ACK #%u", sp
->hdr
.seq
);
66 for (loop
= 0; loop
< RXRPC_ACKR_WINDOW_ASZ
; loop
++) {
67 call
->ackr_window
[loop
] >>= 1;
68 call
->ackr_window
[loop
] |=
69 call
->ackr_window
[loop
+ 1] << (BITS_PER_LONG
- 1);
73 ASSERTCMP(seq
, ==, call
->rx_data_eaten
+ 1);
74 call
->rx_data_eaten
= seq
;
76 if (call
->ackr_win_top
< UINT_MAX
)
79 ASSERTIFCMP(call
->state
<= RXRPC_CALL_COMPLETE
,
80 call
->rx_data_post
, >=, call
->rx_data_recv
);
81 ASSERTIFCMP(call
->state
<= RXRPC_CALL_COMPLETE
,
82 call
->rx_data_recv
, >=, call
->rx_data_eaten
);
84 if (sp
->hdr
.flags
& RXRPC_LAST_PACKET
) {
85 rxrpc_request_final_ACK(call
);
86 } else if (atomic_dec_and_test(&call
->ackr_not_idle
) &&
87 test_and_clear_bit(RXRPC_CALL_TX_SOFT_ACK
, &call
->flags
)) {
88 /* We previously soft-ACK'd some received packets that have now
89 * been consumed, so send a hard-ACK if no more packets are
90 * immediately forthcoming to allow the transmitter to free up
93 _debug("send Rx idle ACK");
94 __rxrpc_propose_ACK(call
, RXRPC_ACK_IDLE
, sp
->hdr
.serial
,
98 spin_unlock_bh(&call
->lock
);
102 * rxrpc_kernel_data_consumed - Record consumption of data message
103 * @call: The call to which the message pertains.
104 * @skb: Message holding data
106 * Record the consumption of a data message and generate an ACK if appropriate.
107 * The call state is shifted if this was the final packet. The caller must be
108 * in process context with no spinlocks held.
110 * TODO: Actually generate the ACK here rather than punting this to the
113 void rxrpc_kernel_data_consumed(struct rxrpc_call
*call
, struct sk_buff
*skb
)
115 struct rxrpc_skb_priv
*sp
= rxrpc_skb(skb
);
117 _enter("%d,%p{%u}", call
->debug_id
, skb
, sp
->hdr
.seq
);
119 ASSERTCMP(sp
->call
, ==, call
);
120 ASSERTCMP(sp
->hdr
.type
, ==, RXRPC_PACKET_TYPE_DATA
);
122 /* TODO: Fix the sequence number tracking */
123 ASSERTCMP(sp
->hdr
.seq
, >=, call
->rx_data_recv
);
124 ASSERTCMP(sp
->hdr
.seq
, <=, call
->rx_data_recv
+ 1);
125 ASSERTCMP(sp
->hdr
.seq
, >, call
->rx_data_eaten
);
127 call
->rx_data_recv
= sp
->hdr
.seq
;
128 rxrpc_hard_ACK_data(call
, sp
);
130 EXPORT_SYMBOL(rxrpc_kernel_data_consumed
);
133 * Destroy a packet that has an RxRPC control buffer
135 void rxrpc_packet_destructor(struct sk_buff
*skb
)
137 struct rxrpc_skb_priv
*sp
= rxrpc_skb(skb
);
138 struct rxrpc_call
*call
= sp
->call
;
140 _enter("%p{%p}", skb
, call
);
143 if (atomic_dec_return(&call
->skb_count
) < 0)
145 rxrpc_put_call(call
);
155 * rxrpc_kernel_free_skb - Free an RxRPC socket buffer
156 * @skb: The socket buffer to be freed
158 * Let RxRPC free its own socket buffer, permitting it to maintain debug
161 void rxrpc_kernel_free_skb(struct sk_buff
*skb
)
165 EXPORT_SYMBOL(rxrpc_kernel_free_skb
);