]>
Commit | Line | Data |
---|---|---|
17926a79 DH |
1 | /* RxRPC packet transmission |
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 | 14 | #include <linux/net.h> |
5a0e3ad6 | 15 | #include <linux/gfp.h> |
17926a79 | 16 | #include <linux/skbuff.h> |
bc3b2d7f | 17 | #include <linux/export.h> |
17926a79 DH |
18 | #include <net/sock.h> |
19 | #include <net/af_rxrpc.h> | |
20 | #include "ar-internal.h" | |
21 | ||
26cb02aa | 22 | struct rxrpc_ack_buffer { |
8d94aa38 | 23 | struct rxrpc_wire_header whdr; |
26cb02aa DH |
24 | struct rxrpc_ackpacket ack; |
25 | u8 acks[255]; | |
26 | u8 pad[3]; | |
8d94aa38 DH |
27 | struct rxrpc_ackinfo ackinfo; |
28 | }; | |
29 | ||
26cb02aa DH |
30 | struct rxrpc_abort_buffer { |
31 | struct rxrpc_wire_header whdr; | |
32 | __be32 abort_code; | |
33 | }; | |
34 | ||
ace45bec DH |
35 | static const char rxrpc_keepalive_string[] = ""; |
36 | ||
c7e86acf DH |
37 | /* |
38 | * Increase Tx backoff on transmission failure and clear it on success. | |
39 | */ | |
40 | static void rxrpc_tx_backoff(struct rxrpc_call *call, int ret) | |
41 | { | |
42 | if (ret < 0) { | |
43 | u16 tx_backoff = READ_ONCE(call->tx_backoff); | |
44 | ||
45 | if (tx_backoff < HZ) | |
46 | WRITE_ONCE(call->tx_backoff, tx_backoff + 1); | |
47 | } else { | |
48 | WRITE_ONCE(call->tx_backoff, 0); | |
49 | } | |
50 | } | |
51 | ||
415f44e4 DH |
52 | /* |
53 | * Arrange for a keepalive ping a certain time after we last transmitted. This | |
54 | * lets the far side know we're still interested in this call and helps keep | |
55 | * the route through any intervening firewall open. | |
56 | * | |
57 | * Receiving a response to the ping will prevent the ->expect_rx_by timer from | |
58 | * expiring. | |
59 | */ | |
60 | static void rxrpc_set_keepalive(struct rxrpc_call *call) | |
61 | { | |
62 | unsigned long now = jiffies, keepalive_at = call->next_rx_timo / 6; | |
63 | ||
64 | keepalive_at += now; | |
65 | WRITE_ONCE(call->keepalive_at, keepalive_at); | |
66 | rxrpc_reduce_call_timer(call, keepalive_at, now, | |
67 | rxrpc_timer_set_for_keepalive); | |
68 | } | |
69 | ||
8d94aa38 DH |
70 | /* |
71 | * Fill out an ACK packet. | |
72 | */ | |
1457cc4c DH |
73 | static size_t rxrpc_fill_out_ack(struct rxrpc_connection *conn, |
74 | struct rxrpc_call *call, | |
26cb02aa | 75 | struct rxrpc_ack_buffer *pkt, |
805b21b9 | 76 | rxrpc_seq_t *_hard_ack, |
a5af7e1f DH |
77 | rxrpc_seq_t *_top, |
78 | u8 reason) | |
8d94aa38 | 79 | { |
f3639df2 | 80 | rxrpc_serial_t serial; |
248f219c DH |
81 | rxrpc_seq_t hard_ack, top, seq; |
82 | int ix; | |
8d94aa38 DH |
83 | u32 mtu, jmax; |
84 | u8 *ackp = pkt->acks; | |
85 | ||
248f219c | 86 | /* Barrier against rxrpc_input_data(). */ |
f3639df2 | 87 | serial = call->ackr_serial; |
248f219c DH |
88 | hard_ack = READ_ONCE(call->rx_hard_ack); |
89 | top = smp_load_acquire(&call->rx_top); | |
805b21b9 DH |
90 | *_hard_ack = hard_ack; |
91 | *_top = top; | |
248f219c | 92 | |
8d94aa38 | 93 | pkt->ack.bufferSpace = htons(8); |
248f219c DH |
94 | pkt->ack.maxSkew = htons(call->ackr_skew); |
95 | pkt->ack.firstPacket = htonl(hard_ack + 1); | |
8d94aa38 | 96 | pkt->ack.previousPacket = htonl(call->ackr_prev_seq); |
f3639df2 | 97 | pkt->ack.serial = htonl(serial); |
a5af7e1f | 98 | pkt->ack.reason = reason; |
248f219c DH |
99 | pkt->ack.nAcks = top - hard_ack; |
100 | ||
a5af7e1f | 101 | if (reason == RXRPC_ACK_PING) |
8e83134d DH |
102 | pkt->whdr.flags |= RXRPC_REQUEST_ACK; |
103 | ||
248f219c DH |
104 | if (after(top, hard_ack)) { |
105 | seq = hard_ack + 1; | |
106 | do { | |
107 | ix = seq & RXRPC_RXTX_BUFF_MASK; | |
108 | if (call->rxtx_buffer[ix]) | |
109 | *ackp++ = RXRPC_ACK_TYPE_ACK; | |
110 | else | |
111 | *ackp++ = RXRPC_ACK_TYPE_NACK; | |
112 | seq++; | |
113 | } while (before_eq(seq, top)); | |
114 | } | |
8d94aa38 | 115 | |
1457cc4c DH |
116 | mtu = conn->params.peer->if_mtu; |
117 | mtu -= conn->params.peer->hdrsize; | |
75e42126 | 118 | jmax = (call->nr_jumbo_bad > 3) ? 1 : rxrpc_rx_jumbo_max; |
8d94aa38 DH |
119 | pkt->ackinfo.rxMTU = htonl(rxrpc_rx_mtu); |
120 | pkt->ackinfo.maxMTU = htonl(mtu); | |
75e42126 | 121 | pkt->ackinfo.rwind = htonl(call->rx_winsize); |
8d94aa38 DH |
122 | pkt->ackinfo.jumbo_max = htonl(jmax); |
123 | ||
124 | *ackp++ = 0; | |
125 | *ackp++ = 0; | |
126 | *ackp++ = 0; | |
248f219c | 127 | return top - hard_ack + 3; |
8d94aa38 DH |
128 | } |
129 | ||
130 | /* | |
26cb02aa | 131 | * Send an ACK call packet. |
8d94aa38 | 132 | */ |
bd1fdf8c DH |
133 | int rxrpc_send_ack_packet(struct rxrpc_call *call, bool ping, |
134 | rxrpc_serial_t *_serial) | |
8d94aa38 DH |
135 | { |
136 | struct rxrpc_connection *conn = NULL; | |
26cb02aa | 137 | struct rxrpc_ack_buffer *pkt; |
8d94aa38 DH |
138 | struct msghdr msg; |
139 | struct kvec iov[2]; | |
140 | rxrpc_serial_t serial; | |
805b21b9 | 141 | rxrpc_seq_t hard_ack, top; |
8d94aa38 | 142 | size_t len, n; |
26cb02aa | 143 | int ret; |
a5af7e1f | 144 | u8 reason; |
8d94aa38 DH |
145 | |
146 | spin_lock_bh(&call->lock); | |
147 | if (call->conn) | |
148 | conn = rxrpc_get_connection_maybe(call->conn); | |
149 | spin_unlock_bh(&call->lock); | |
150 | if (!conn) | |
151 | return -ECONNRESET; | |
152 | ||
153 | pkt = kzalloc(sizeof(*pkt), GFP_KERNEL); | |
154 | if (!pkt) { | |
155 | rxrpc_put_connection(conn); | |
156 | return -ENOMEM; | |
157 | } | |
158 | ||
8d94aa38 DH |
159 | msg.msg_name = &call->peer->srx.transport; |
160 | msg.msg_namelen = call->peer->srx.transport_len; | |
161 | msg.msg_control = NULL; | |
162 | msg.msg_controllen = 0; | |
163 | msg.msg_flags = 0; | |
164 | ||
165 | pkt->whdr.epoch = htonl(conn->proto.epoch); | |
166 | pkt->whdr.cid = htonl(call->cid); | |
167 | pkt->whdr.callNumber = htonl(call->call_id); | |
168 | pkt->whdr.seq = 0; | |
26cb02aa DH |
169 | pkt->whdr.type = RXRPC_PACKET_TYPE_ACK; |
170 | pkt->whdr.flags = RXRPC_SLOW_START_OK | conn->out_clientflag; | |
8d94aa38 DH |
171 | pkt->whdr.userStatus = 0; |
172 | pkt->whdr.securityIndex = call->security_ix; | |
173 | pkt->whdr._rsvd = 0; | |
174 | pkt->whdr.serviceId = htons(call->service_id); | |
175 | ||
26cb02aa | 176 | spin_lock_bh(&call->lock); |
a5af7e1f DH |
177 | if (ping) { |
178 | reason = RXRPC_ACK_PING; | |
179 | } else { | |
180 | reason = call->ackr_reason; | |
181 | if (!call->ackr_reason) { | |
182 | spin_unlock_bh(&call->lock); | |
183 | ret = 0; | |
184 | goto out; | |
185 | } | |
186 | call->ackr_reason = 0; | |
8d94aa38 | 187 | } |
1457cc4c | 188 | n = rxrpc_fill_out_ack(conn, call, pkt, &hard_ack, &top, reason); |
26cb02aa DH |
189 | |
190 | spin_unlock_bh(&call->lock); | |
191 | ||
192 | iov[0].iov_base = pkt; | |
193 | iov[0].iov_len = sizeof(pkt->whdr) + sizeof(pkt->ack) + n; | |
194 | iov[1].iov_base = &pkt->ackinfo; | |
195 | iov[1].iov_len = sizeof(pkt->ackinfo); | |
196 | len = iov[0].iov_len + iov[1].iov_len; | |
8d94aa38 | 197 | |
b86e218e DH |
198 | serial = atomic_inc_return(&conn->serial); |
199 | pkt->whdr.serial = htonl(serial); | |
4764c0da | 200 | trace_rxrpc_tx_ack(call->debug_id, serial, |
26cb02aa DH |
201 | ntohl(pkt->ack.firstPacket), |
202 | ntohl(pkt->ack.serial), | |
203 | pkt->ack.reason, pkt->ack.nAcks); | |
bd1fdf8c DH |
204 | if (_serial) |
205 | *_serial = serial; | |
b86e218e | 206 | |
8e83134d | 207 | if (ping) { |
a5af7e1f | 208 | call->ping_serial = serial; |
8e83134d DH |
209 | smp_wmb(); |
210 | /* We need to stick a time in before we send the packet in case | |
211 | * the reply gets back before kernel_sendmsg() completes - but | |
212 | * asking UDP to send the packet can take a relatively long | |
b604dd98 | 213 | * time. |
8e83134d | 214 | */ |
a5af7e1f | 215 | call->ping_time = ktime_get_real(); |
8e83134d DH |
216 | set_bit(RXRPC_CALL_PINGING, &call->flags); |
217 | trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_ping, serial); | |
218 | } | |
26cb02aa DH |
219 | |
220 | ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 2, len); | |
330bdcfa | 221 | conn->params.peer->last_tx_at = ktime_get_seconds(); |
6b47fe1d DH |
222 | if (ret < 0) |
223 | trace_rxrpc_tx_fail(call->debug_id, serial, ret, | |
4764c0da DH |
224 | rxrpc_tx_point_call_ack); |
225 | else | |
226 | trace_rxrpc_tx_packet(call->debug_id, &pkt->whdr, | |
227 | rxrpc_tx_point_call_ack); | |
c7e86acf | 228 | rxrpc_tx_backoff(call, ret); |
8d94aa38 | 229 | |
26cb02aa | 230 | if (call->state < RXRPC_CALL_COMPLETE) { |
805b21b9 | 231 | if (ret < 0) { |
a5af7e1f DH |
232 | if (ping) |
233 | clear_bit(RXRPC_CALL_PINGING, &call->flags); | |
248f219c DH |
234 | rxrpc_propose_ACK(call, pkt->ack.reason, |
235 | ntohs(pkt->ack.maxSkew), | |
236 | ntohl(pkt->ack.serial), | |
c7e86acf | 237 | false, true, |
9c7ad434 | 238 | rxrpc_propose_ack_retry_tx); |
805b21b9 DH |
239 | } else { |
240 | spin_lock_bh(&call->lock); | |
241 | if (after(hard_ack, call->ackr_consumed)) | |
242 | call->ackr_consumed = hard_ack; | |
243 | if (after(top, call->ackr_seen)) | |
244 | call->ackr_seen = top; | |
245 | spin_unlock_bh(&call->lock); | |
248f219c | 246 | } |
415f44e4 DH |
247 | |
248 | rxrpc_set_keepalive(call); | |
248f219c DH |
249 | } |
250 | ||
8d94aa38 DH |
251 | out: |
252 | rxrpc_put_connection(conn); | |
253 | kfree(pkt); | |
254 | return ret; | |
255 | } | |
256 | ||
26cb02aa DH |
257 | /* |
258 | * Send an ABORT call packet. | |
259 | */ | |
260 | int rxrpc_send_abort_packet(struct rxrpc_call *call) | |
261 | { | |
262 | struct rxrpc_connection *conn = NULL; | |
263 | struct rxrpc_abort_buffer pkt; | |
264 | struct msghdr msg; | |
265 | struct kvec iov[1]; | |
266 | rxrpc_serial_t serial; | |
267 | int ret; | |
268 | ||
dcbefc30 DH |
269 | /* Don't bother sending aborts for a client call once the server has |
270 | * hard-ACK'd all of its request data. After that point, we're not | |
271 | * going to stop the operation proceeding, and whilst we might limit | |
272 | * the reply, it's not worth it if we can send a new call on the same | |
273 | * channel instead, thereby closing off this call. | |
274 | */ | |
275 | if (rxrpc_is_client_call(call) && | |
276 | test_bit(RXRPC_CALL_TX_LAST, &call->flags)) | |
277 | return 0; | |
278 | ||
26cb02aa DH |
279 | spin_lock_bh(&call->lock); |
280 | if (call->conn) | |
281 | conn = rxrpc_get_connection_maybe(call->conn); | |
282 | spin_unlock_bh(&call->lock); | |
283 | if (!conn) | |
284 | return -ECONNRESET; | |
285 | ||
286 | msg.msg_name = &call->peer->srx.transport; | |
287 | msg.msg_namelen = call->peer->srx.transport_len; | |
288 | msg.msg_control = NULL; | |
289 | msg.msg_controllen = 0; | |
290 | msg.msg_flags = 0; | |
291 | ||
292 | pkt.whdr.epoch = htonl(conn->proto.epoch); | |
293 | pkt.whdr.cid = htonl(call->cid); | |
294 | pkt.whdr.callNumber = htonl(call->call_id); | |
295 | pkt.whdr.seq = 0; | |
296 | pkt.whdr.type = RXRPC_PACKET_TYPE_ABORT; | |
297 | pkt.whdr.flags = conn->out_clientflag; | |
298 | pkt.whdr.userStatus = 0; | |
299 | pkt.whdr.securityIndex = call->security_ix; | |
300 | pkt.whdr._rsvd = 0; | |
301 | pkt.whdr.serviceId = htons(call->service_id); | |
302 | pkt.abort_code = htonl(call->abort_code); | |
303 | ||
304 | iov[0].iov_base = &pkt; | |
305 | iov[0].iov_len = sizeof(pkt); | |
306 | ||
307 | serial = atomic_inc_return(&conn->serial); | |
308 | pkt.whdr.serial = htonl(serial); | |
309 | ||
310 | ret = kernel_sendmsg(conn->params.local->socket, | |
311 | &msg, iov, 1, sizeof(pkt)); | |
330bdcfa | 312 | conn->params.peer->last_tx_at = ktime_get_seconds(); |
6b47fe1d DH |
313 | if (ret < 0) |
314 | trace_rxrpc_tx_fail(call->debug_id, serial, ret, | |
4764c0da DH |
315 | rxrpc_tx_point_call_abort); |
316 | else | |
317 | trace_rxrpc_tx_packet(call->debug_id, &pkt.whdr, | |
318 | rxrpc_tx_point_call_abort); | |
c7e86acf | 319 | rxrpc_tx_backoff(call, ret); |
26cb02aa DH |
320 | |
321 | rxrpc_put_connection(conn); | |
322 | return ret; | |
323 | } | |
324 | ||
17926a79 DH |
325 | /* |
326 | * send a packet through the transport endpoint | |
327 | */ | |
a1767077 DH |
328 | int rxrpc_send_data_packet(struct rxrpc_call *call, struct sk_buff *skb, |
329 | bool retrans) | |
17926a79 | 330 | { |
5a924b89 DH |
331 | struct rxrpc_connection *conn = call->conn; |
332 | struct rxrpc_wire_header whdr; | |
333 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); | |
17926a79 | 334 | struct msghdr msg; |
5a924b89 DH |
335 | struct kvec iov[2]; |
336 | rxrpc_serial_t serial; | |
337 | size_t len; | |
17926a79 DH |
338 | int ret, opt; |
339 | ||
340 | _enter(",{%d}", skb->len); | |
341 | ||
5a924b89 DH |
342 | /* Each transmission of a Tx packet needs a new serial number */ |
343 | serial = atomic_inc_return(&conn->serial); | |
17926a79 | 344 | |
5a924b89 DH |
345 | whdr.epoch = htonl(conn->proto.epoch); |
346 | whdr.cid = htonl(call->cid); | |
347 | whdr.callNumber = htonl(call->call_id); | |
348 | whdr.seq = htonl(sp->hdr.seq); | |
349 | whdr.serial = htonl(serial); | |
350 | whdr.type = RXRPC_PACKET_TYPE_DATA; | |
351 | whdr.flags = sp->hdr.flags; | |
352 | whdr.userStatus = 0; | |
353 | whdr.securityIndex = call->security_ix; | |
354 | whdr._rsvd = htons(sp->hdr._rsvd); | |
355 | whdr.serviceId = htons(call->service_id); | |
356 | ||
4e255721 DH |
357 | if (test_bit(RXRPC_CONN_PROBING_FOR_UPGRADE, &conn->flags) && |
358 | sp->hdr.seq == 1) | |
359 | whdr.userStatus = RXRPC_USERSTATUS_SERVICE_UPGRADE; | |
360 | ||
5a924b89 DH |
361 | iov[0].iov_base = &whdr; |
362 | iov[0].iov_len = sizeof(whdr); | |
363 | iov[1].iov_base = skb->head; | |
364 | iov[1].iov_len = skb->len; | |
365 | len = iov[0].iov_len + iov[1].iov_len; | |
366 | ||
367 | msg.msg_name = &call->peer->srx.transport; | |
368 | msg.msg_namelen = call->peer->srx.transport_len; | |
17926a79 DH |
369 | msg.msg_control = NULL; |
370 | msg.msg_controllen = 0; | |
371 | msg.msg_flags = 0; | |
372 | ||
57494343 DH |
373 | /* If our RTT cache needs working on, request an ACK. Also request |
374 | * ACKs if a DATA packet appears to have been lost. | |
b604dd98 DH |
375 | * |
376 | * However, we mustn't request an ACK on the last reply packet of a | |
377 | * service call, lest OpenAFS incorrectly send us an ACK with some | |
378 | * soft-ACKs in it and then never follow up with a proper hard ACK. | |
57494343 | 379 | */ |
b604dd98 DH |
380 | if ((!(sp->hdr.flags & RXRPC_LAST_PACKET) || |
381 | rxrpc_to_server(sp) | |
382 | ) && | |
bd1fdf8c DH |
383 | (test_and_clear_bit(RXRPC_CALL_EV_ACK_LOST, &call->events) || |
384 | retrans || | |
bf7d620a DH |
385 | call->cong_mode == RXRPC_CALL_SLOW_START || |
386 | (call->peer->rtt_usage < 3 && sp->hdr.seq & 1) || | |
387 | ktime_before(ktime_add_ms(call->peer->rtt_last_req, 1000), | |
388 | ktime_get_real()))) | |
0d4b103c DH |
389 | whdr.flags |= RXRPC_REQUEST_ACK; |
390 | ||
8a681c36 DH |
391 | if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) { |
392 | static int lose; | |
393 | if ((lose++ & 7) == 7) { | |
a1767077 | 394 | ret = 0; |
526949e8 AB |
395 | trace_rxrpc_tx_data(call, sp->hdr.seq, serial, |
396 | whdr.flags, retrans, true); | |
397 | goto done; | |
8a681c36 DH |
398 | } |
399 | } | |
400 | ||
526949e8 AB |
401 | trace_rxrpc_tx_data(call, sp->hdr.seq, serial, whdr.flags, retrans, |
402 | false); | |
5a924b89 | 403 | |
17926a79 DH |
404 | /* send the packet with the don't fragment bit set if we currently |
405 | * think it's small enough */ | |
5a924b89 DH |
406 | if (iov[1].iov_len >= call->peer->maxdata) |
407 | goto send_fragmentable; | |
408 | ||
409 | down_read(&conn->params.local->defrag_sem); | |
b604dd98 DH |
410 | |
411 | sp->hdr.serial = serial; | |
412 | smp_wmb(); /* Set serial before timestamp */ | |
413 | skb->tstamp = ktime_get_real(); | |
414 | ||
5a924b89 DH |
415 | /* send the packet by UDP |
416 | * - returns -EMSGSIZE if UDP would have to fragment the packet | |
417 | * to go out of the interface | |
418 | * - in which case, we'll have processed the ICMP error | |
419 | * message and update the peer record | |
420 | */ | |
421 | ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 2, len); | |
330bdcfa | 422 | conn->params.peer->last_tx_at = ktime_get_seconds(); |
5a924b89 DH |
423 | |
424 | up_read(&conn->params.local->defrag_sem); | |
6b47fe1d DH |
425 | if (ret < 0) |
426 | trace_rxrpc_tx_fail(call->debug_id, serial, ret, | |
4764c0da DH |
427 | rxrpc_tx_point_call_data_nofrag); |
428 | else | |
429 | trace_rxrpc_tx_packet(call->debug_id, &whdr, | |
430 | rxrpc_tx_point_call_data_nofrag); | |
c7e86acf | 431 | rxrpc_tx_backoff(call, ret); |
5a924b89 DH |
432 | if (ret == -EMSGSIZE) |
433 | goto send_fragmentable; | |
434 | ||
435 | done: | |
50235c4b | 436 | if (ret >= 0) { |
0d4b103c | 437 | if (whdr.flags & RXRPC_REQUEST_ACK) { |
b604dd98 | 438 | call->peer->rtt_last_req = skb->tstamp; |
50235c4b | 439 | trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_data, serial); |
bd1fdf8c DH |
440 | if (call->peer->rtt_usage > 1) { |
441 | unsigned long nowj = jiffies, ack_lost_at; | |
442 | ||
443 | ack_lost_at = nsecs_to_jiffies(2 * call->peer->rtt); | |
444 | if (ack_lost_at < 1) | |
445 | ack_lost_at = 1; | |
446 | ||
447 | ack_lost_at += nowj; | |
448 | WRITE_ONCE(call->ack_lost_at, ack_lost_at); | |
449 | rxrpc_reduce_call_timer(call, ack_lost_at, nowj, | |
450 | rxrpc_timer_set_for_lost_ack); | |
451 | } | |
0d4b103c | 452 | } |
c54e43d7 DH |
453 | |
454 | if (sp->hdr.seq == 1 && | |
455 | !test_and_set_bit(RXRPC_CALL_BEGAN_RX_TIMER, | |
456 | &call->flags)) { | |
457 | unsigned long nowj = jiffies, expect_rx_by; | |
458 | ||
459 | expect_rx_by = nowj + call->next_rx_timo; | |
460 | WRITE_ONCE(call->expect_rx_by, expect_rx_by); | |
461 | rxrpc_reduce_call_timer(call, expect_rx_by, nowj, | |
462 | rxrpc_timer_set_for_normal); | |
463 | } | |
415f44e4 | 464 | |
c7e86acf DH |
465 | rxrpc_set_keepalive(call); |
466 | } else { | |
467 | /* Cancel the call if the initial transmission fails, | |
468 | * particularly if that's due to network routing issues that | |
469 | * aren't going away anytime soon. The layer above can arrange | |
470 | * the retransmission. | |
471 | */ | |
472 | if (!test_and_set_bit(RXRPC_CALL_BEGAN_RX_TIMER, &call->flags)) | |
473 | rxrpc_set_call_completion(call, RXRPC_CALL_LOCAL_ERROR, | |
474 | RX_USER_ABORT, ret); | |
475 | } | |
415f44e4 | 476 | |
5a924b89 DH |
477 | _leave(" = %d [%u]", ret, call->peer->maxdata); |
478 | return ret; | |
17926a79 DH |
479 | |
480 | send_fragmentable: | |
481 | /* attempt to send this message with fragmentation enabled */ | |
482 | _debug("send fragment"); | |
483 | ||
985a5c82 DH |
484 | down_write(&conn->params.local->defrag_sem); |
485 | ||
b604dd98 DH |
486 | sp->hdr.serial = serial; |
487 | smp_wmb(); /* Set serial before timestamp */ | |
488 | skb->tstamp = ktime_get_real(); | |
489 | ||
985a5c82 DH |
490 | switch (conn->params.local->srx.transport.family) { |
491 | case AF_INET: | |
492 | opt = IP_PMTUDISC_DONT; | |
493 | ret = kernel_setsockopt(conn->params.local->socket, | |
494 | SOL_IP, IP_MTU_DISCOVER, | |
495 | (char *)&opt, sizeof(opt)); | |
496 | if (ret == 0) { | |
5a924b89 DH |
497 | ret = kernel_sendmsg(conn->params.local->socket, &msg, |
498 | iov, 2, len); | |
330bdcfa | 499 | conn->params.peer->last_tx_at = ktime_get_seconds(); |
985a5c82 DH |
500 | |
501 | opt = IP_PMTUDISC_DO; | |
502 | kernel_setsockopt(conn->params.local->socket, SOL_IP, | |
503 | IP_MTU_DISCOVER, | |
504 | (char *)&opt, sizeof(opt)); | |
505 | } | |
506 | break; | |
75b54cb5 | 507 | |
d1912747 | 508 | #ifdef CONFIG_AF_RXRPC_IPV6 |
75b54cb5 DH |
509 | case AF_INET6: |
510 | opt = IPV6_PMTUDISC_DONT; | |
511 | ret = kernel_setsockopt(conn->params.local->socket, | |
512 | SOL_IPV6, IPV6_MTU_DISCOVER, | |
513 | (char *)&opt, sizeof(opt)); | |
514 | if (ret == 0) { | |
515 | ret = kernel_sendmsg(conn->params.local->socket, &msg, | |
93c62c45 | 516 | iov, 2, len); |
330bdcfa | 517 | conn->params.peer->last_tx_at = ktime_get_seconds(); |
75b54cb5 DH |
518 | |
519 | opt = IPV6_PMTUDISC_DO; | |
520 | kernel_setsockopt(conn->params.local->socket, | |
521 | SOL_IPV6, IPV6_MTU_DISCOVER, | |
522 | (char *)&opt, sizeof(opt)); | |
523 | } | |
524 | break; | |
d1912747 | 525 | #endif |
17926a79 DH |
526 | } |
527 | ||
6b47fe1d DH |
528 | if (ret < 0) |
529 | trace_rxrpc_tx_fail(call->debug_id, serial, ret, | |
4764c0da DH |
530 | rxrpc_tx_point_call_data_frag); |
531 | else | |
532 | trace_rxrpc_tx_packet(call->debug_id, &whdr, | |
533 | rxrpc_tx_point_call_data_frag); | |
c7e86acf | 534 | rxrpc_tx_backoff(call, ret); |
6b47fe1d | 535 | |
985a5c82 | 536 | up_write(&conn->params.local->defrag_sem); |
5a924b89 | 537 | goto done; |
17926a79 | 538 | } |
248f219c DH |
539 | |
540 | /* | |
541 | * reject packets through the local endpoint | |
542 | */ | |
543 | void rxrpc_reject_packets(struct rxrpc_local *local) | |
544 | { | |
1c2bc7b9 | 545 | struct sockaddr_rxrpc srx; |
248f219c DH |
546 | struct rxrpc_skb_priv *sp; |
547 | struct rxrpc_wire_header whdr; | |
548 | struct sk_buff *skb; | |
549 | struct msghdr msg; | |
550 | struct kvec iov[2]; | |
551 | size_t size; | |
552 | __be32 code; | |
ece64fec | 553 | int ret, ioc; |
248f219c DH |
554 | |
555 | _enter("%d", local->debug_id); | |
556 | ||
557 | iov[0].iov_base = &whdr; | |
558 | iov[0].iov_len = sizeof(whdr); | |
559 | iov[1].iov_base = &code; | |
560 | iov[1].iov_len = sizeof(code); | |
248f219c | 561 | |
1c2bc7b9 | 562 | msg.msg_name = &srx.transport; |
248f219c DH |
563 | msg.msg_control = NULL; |
564 | msg.msg_controllen = 0; | |
565 | msg.msg_flags = 0; | |
566 | ||
248f219c | 567 | memset(&whdr, 0, sizeof(whdr)); |
248f219c DH |
568 | |
569 | while ((skb = skb_dequeue(&local->reject_queue))) { | |
71f3ca40 | 570 | rxrpc_see_skb(skb, rxrpc_skb_rx_seen); |
248f219c | 571 | sp = rxrpc_skb(skb); |
1c2bc7b9 | 572 | |
ece64fec DH |
573 | switch (skb->mark) { |
574 | case RXRPC_SKB_MARK_REJECT_BUSY: | |
575 | whdr.type = RXRPC_PACKET_TYPE_BUSY; | |
576 | size = sizeof(whdr); | |
577 | ioc = 1; | |
578 | break; | |
579 | case RXRPC_SKB_MARK_REJECT_ABORT: | |
580 | whdr.type = RXRPC_PACKET_TYPE_ABORT; | |
581 | code = htonl(skb->priority); | |
582 | size = sizeof(whdr) + sizeof(code); | |
583 | ioc = 2; | |
584 | break; | |
585 | default: | |
586 | rxrpc_free_skb(skb, rxrpc_skb_rx_freed); | |
587 | continue; | |
588 | } | |
589 | ||
5a790b73 | 590 | if (rxrpc_extract_addr_from_skb(&srx, skb) == 0) { |
1c2bc7b9 DH |
591 | msg.msg_namelen = srx.transport_len; |
592 | ||
248f219c DH |
593 | whdr.epoch = htonl(sp->hdr.epoch); |
594 | whdr.cid = htonl(sp->hdr.cid); | |
595 | whdr.callNumber = htonl(sp->hdr.callNumber); | |
596 | whdr.serviceId = htons(sp->hdr.serviceId); | |
597 | whdr.flags = sp->hdr.flags; | |
598 | whdr.flags ^= RXRPC_CLIENT_INITIATED; | |
599 | whdr.flags &= RXRPC_CLIENT_INITIATED; | |
600 | ||
d6672a5a Y |
601 | ret = kernel_sendmsg(local->socket, &msg, |
602 | iov, ioc, size); | |
6b47fe1d DH |
603 | if (ret < 0) |
604 | trace_rxrpc_tx_fail(local->debug_id, 0, ret, | |
4764c0da DH |
605 | rxrpc_tx_point_reject); |
606 | else | |
607 | trace_rxrpc_tx_packet(local->debug_id, &whdr, | |
608 | rxrpc_tx_point_reject); | |
248f219c DH |
609 | } |
610 | ||
71f3ca40 | 611 | rxrpc_free_skb(skb, rxrpc_skb_rx_freed); |
248f219c DH |
612 | } |
613 | ||
614 | _leave(""); | |
615 | } | |
ace45bec DH |
616 | |
617 | /* | |
618 | * Send a VERSION reply to a peer as a keepalive. | |
619 | */ | |
620 | void rxrpc_send_keepalive(struct rxrpc_peer *peer) | |
621 | { | |
622 | struct rxrpc_wire_header whdr; | |
623 | struct msghdr msg; | |
624 | struct kvec iov[2]; | |
625 | size_t len; | |
626 | int ret; | |
627 | ||
628 | _enter(""); | |
629 | ||
630 | msg.msg_name = &peer->srx.transport; | |
631 | msg.msg_namelen = peer->srx.transport_len; | |
632 | msg.msg_control = NULL; | |
633 | msg.msg_controllen = 0; | |
634 | msg.msg_flags = 0; | |
635 | ||
636 | whdr.epoch = htonl(peer->local->rxnet->epoch); | |
637 | whdr.cid = 0; | |
638 | whdr.callNumber = 0; | |
639 | whdr.seq = 0; | |
640 | whdr.serial = 0; | |
641 | whdr.type = RXRPC_PACKET_TYPE_VERSION; /* Not client-initiated */ | |
642 | whdr.flags = RXRPC_LAST_PACKET; | |
643 | whdr.userStatus = 0; | |
644 | whdr.securityIndex = 0; | |
645 | whdr._rsvd = 0; | |
646 | whdr.serviceId = 0; | |
647 | ||
648 | iov[0].iov_base = &whdr; | |
649 | iov[0].iov_len = sizeof(whdr); | |
650 | iov[1].iov_base = (char *)rxrpc_keepalive_string; | |
651 | iov[1].iov_len = sizeof(rxrpc_keepalive_string); | |
652 | ||
653 | len = iov[0].iov_len + iov[1].iov_len; | |
654 | ||
655 | _proto("Tx VERSION (keepalive)"); | |
656 | ||
657 | ret = kernel_sendmsg(peer->local->socket, &msg, iov, 2, len); | |
658 | if (ret < 0) | |
6b47fe1d | 659 | trace_rxrpc_tx_fail(peer->debug_id, 0, ret, |
4764c0da DH |
660 | rxrpc_tx_point_version_keepalive); |
661 | else | |
662 | trace_rxrpc_tx_packet(peer->debug_id, &whdr, | |
663 | rxrpc_tx_point_version_keepalive); | |
ace45bec | 664 | |
330bdcfa | 665 | peer->last_tx_at = ktime_get_seconds(); |
ace45bec DH |
666 | _leave(""); |
667 | } |