blob: cf73dc006c3bf0d3866461c63a5a7c51c161c90b [file] [log] [blame]
David Howells17926a72007-04-26 15:48:28 -07001/* 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
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/net.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/gfp.h>
David Howells17926a72007-04-26 15:48:28 -070016#include <linux/skbuff.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040017#include <linux/export.h>
David Howells17926a72007-04-26 15:48:28 -070018#include <net/sock.h>
19#include <net/af_rxrpc.h>
20#include "ar-internal.h"
21
David Howells26cb02a2016-10-06 08:11:49 +010022struct rxrpc_ack_buffer {
David Howells8d94aa32016-09-07 09:19:31 +010023 struct rxrpc_wire_header whdr;
David Howells26cb02a2016-10-06 08:11:49 +010024 struct rxrpc_ackpacket ack;
25 u8 acks[255];
26 u8 pad[3];
David Howells8d94aa32016-09-07 09:19:31 +010027 struct rxrpc_ackinfo ackinfo;
28};
29
David Howells26cb02a2016-10-06 08:11:49 +010030struct rxrpc_abort_buffer {
31 struct rxrpc_wire_header whdr;
32 __be32 abort_code;
33};
34
David Howells8d94aa32016-09-07 09:19:31 +010035/*
David Howells415f44e2017-11-24 10:18:42 +000036 * Arrange for a keepalive ping a certain time after we last transmitted. This
37 * lets the far side know we're still interested in this call and helps keep
38 * the route through any intervening firewall open.
39 *
40 * Receiving a response to the ping will prevent the ->expect_rx_by timer from
41 * expiring.
42 */
43static void rxrpc_set_keepalive(struct rxrpc_call *call)
44{
45 unsigned long now = jiffies, keepalive_at = call->next_rx_timo / 6;
46
47 keepalive_at += now;
48 WRITE_ONCE(call->keepalive_at, keepalive_at);
49 rxrpc_reduce_call_timer(call, keepalive_at, now,
50 rxrpc_timer_set_for_keepalive);
51}
52
53/*
David Howells8d94aa32016-09-07 09:19:31 +010054 * Fill out an ACK packet.
55 */
David Howells1457cc42017-11-02 15:06:55 +000056static size_t rxrpc_fill_out_ack(struct rxrpc_connection *conn,
57 struct rxrpc_call *call,
David Howells26cb02a2016-10-06 08:11:49 +010058 struct rxrpc_ack_buffer *pkt,
David Howells805b21b2016-09-24 18:05:26 +010059 rxrpc_seq_t *_hard_ack,
David Howellsa5af7e12016-10-06 08:11:49 +010060 rxrpc_seq_t *_top,
61 u8 reason)
David Howells8d94aa32016-09-07 09:19:31 +010062{
David Howellsf3639df2016-09-17 10:49:13 +010063 rxrpc_serial_t serial;
David Howells248f2192016-09-08 11:10:12 +010064 rxrpc_seq_t hard_ack, top, seq;
65 int ix;
David Howells8d94aa32016-09-07 09:19:31 +010066 u32 mtu, jmax;
67 u8 *ackp = pkt->acks;
68
David Howells248f2192016-09-08 11:10:12 +010069 /* Barrier against rxrpc_input_data(). */
David Howellsf3639df2016-09-17 10:49:13 +010070 serial = call->ackr_serial;
David Howells248f2192016-09-08 11:10:12 +010071 hard_ack = READ_ONCE(call->rx_hard_ack);
72 top = smp_load_acquire(&call->rx_top);
David Howells805b21b2016-09-24 18:05:26 +010073 *_hard_ack = hard_ack;
74 *_top = top;
David Howells248f2192016-09-08 11:10:12 +010075
David Howells8d94aa32016-09-07 09:19:31 +010076 pkt->ack.bufferSpace = htons(8);
David Howells248f2192016-09-08 11:10:12 +010077 pkt->ack.maxSkew = htons(call->ackr_skew);
78 pkt->ack.firstPacket = htonl(hard_ack + 1);
David Howells8d94aa32016-09-07 09:19:31 +010079 pkt->ack.previousPacket = htonl(call->ackr_prev_seq);
David Howellsf3639df2016-09-17 10:49:13 +010080 pkt->ack.serial = htonl(serial);
David Howellsa5af7e12016-10-06 08:11:49 +010081 pkt->ack.reason = reason;
David Howells248f2192016-09-08 11:10:12 +010082 pkt->ack.nAcks = top - hard_ack;
David Howells8d94aa32016-09-07 09:19:31 +010083
David Howellsa5af7e12016-10-06 08:11:49 +010084 if (reason == RXRPC_ACK_PING)
David Howells8e831342016-09-22 00:29:31 +010085 pkt->whdr.flags |= RXRPC_REQUEST_ACK;
86
David Howells248f2192016-09-08 11:10:12 +010087 if (after(top, hard_ack)) {
88 seq = hard_ack + 1;
89 do {
90 ix = seq & RXRPC_RXTX_BUFF_MASK;
91 if (call->rxtx_buffer[ix])
92 *ackp++ = RXRPC_ACK_TYPE_ACK;
93 else
94 *ackp++ = RXRPC_ACK_TYPE_NACK;
95 seq++;
96 } while (before_eq(seq, top));
97 }
98
David Howells1457cc42017-11-02 15:06:55 +000099 mtu = conn->params.peer->if_mtu;
100 mtu -= conn->params.peer->hdrsize;
David Howells75e42122016-09-13 22:36:22 +0100101 jmax = (call->nr_jumbo_bad > 3) ? 1 : rxrpc_rx_jumbo_max;
David Howells8d94aa32016-09-07 09:19:31 +0100102 pkt->ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
103 pkt->ackinfo.maxMTU = htonl(mtu);
David Howells75e42122016-09-13 22:36:22 +0100104 pkt->ackinfo.rwind = htonl(call->rx_winsize);
David Howells8d94aa32016-09-07 09:19:31 +0100105 pkt->ackinfo.jumbo_max = htonl(jmax);
106
107 *ackp++ = 0;
108 *ackp++ = 0;
109 *ackp++ = 0;
David Howells248f2192016-09-08 11:10:12 +0100110 return top - hard_ack + 3;
David Howells8d94aa32016-09-07 09:19:31 +0100111}
112
113/*
David Howells26cb02a2016-10-06 08:11:49 +0100114 * Send an ACK call packet.
David Howells8d94aa32016-09-07 09:19:31 +0100115 */
David Howellsbd1fdf82017-11-24 10:18:42 +0000116int rxrpc_send_ack_packet(struct rxrpc_call *call, bool ping,
117 rxrpc_serial_t *_serial)
David Howells8d94aa32016-09-07 09:19:31 +0100118{
119 struct rxrpc_connection *conn = NULL;
David Howells26cb02a2016-10-06 08:11:49 +0100120 struct rxrpc_ack_buffer *pkt;
David Howells8d94aa32016-09-07 09:19:31 +0100121 struct msghdr msg;
122 struct kvec iov[2];
123 rxrpc_serial_t serial;
David Howells805b21b2016-09-24 18:05:26 +0100124 rxrpc_seq_t hard_ack, top;
David Howells8d94aa32016-09-07 09:19:31 +0100125 size_t len, n;
David Howells26cb02a2016-10-06 08:11:49 +0100126 int ret;
David Howellsa5af7e12016-10-06 08:11:49 +0100127 u8 reason;
David Howells8d94aa32016-09-07 09:19:31 +0100128
129 spin_lock_bh(&call->lock);
130 if (call->conn)
131 conn = rxrpc_get_connection_maybe(call->conn);
132 spin_unlock_bh(&call->lock);
133 if (!conn)
134 return -ECONNRESET;
135
136 pkt = kzalloc(sizeof(*pkt), GFP_KERNEL);
137 if (!pkt) {
138 rxrpc_put_connection(conn);
139 return -ENOMEM;
140 }
141
David Howells8d94aa32016-09-07 09:19:31 +0100142 msg.msg_name = &call->peer->srx.transport;
143 msg.msg_namelen = call->peer->srx.transport_len;
144 msg.msg_control = NULL;
145 msg.msg_controllen = 0;
146 msg.msg_flags = 0;
147
148 pkt->whdr.epoch = htonl(conn->proto.epoch);
149 pkt->whdr.cid = htonl(call->cid);
150 pkt->whdr.callNumber = htonl(call->call_id);
151 pkt->whdr.seq = 0;
David Howells26cb02a2016-10-06 08:11:49 +0100152 pkt->whdr.type = RXRPC_PACKET_TYPE_ACK;
153 pkt->whdr.flags = RXRPC_SLOW_START_OK | conn->out_clientflag;
David Howells8d94aa32016-09-07 09:19:31 +0100154 pkt->whdr.userStatus = 0;
155 pkt->whdr.securityIndex = call->security_ix;
156 pkt->whdr._rsvd = 0;
157 pkt->whdr.serviceId = htons(call->service_id);
158
David Howells26cb02a2016-10-06 08:11:49 +0100159 spin_lock_bh(&call->lock);
David Howellsa5af7e12016-10-06 08:11:49 +0100160 if (ping) {
161 reason = RXRPC_ACK_PING;
162 } else {
163 reason = call->ackr_reason;
164 if (!call->ackr_reason) {
165 spin_unlock_bh(&call->lock);
166 ret = 0;
167 goto out;
168 }
169 call->ackr_reason = 0;
David Howells8d94aa32016-09-07 09:19:31 +0100170 }
David Howells1457cc42017-11-02 15:06:55 +0000171 n = rxrpc_fill_out_ack(conn, call, pkt, &hard_ack, &top, reason);
David Howells26cb02a2016-10-06 08:11:49 +0100172
173 spin_unlock_bh(&call->lock);
174
175 iov[0].iov_base = pkt;
176 iov[0].iov_len = sizeof(pkt->whdr) + sizeof(pkt->ack) + n;
177 iov[1].iov_base = &pkt->ackinfo;
178 iov[1].iov_len = sizeof(pkt->ackinfo);
179 len = iov[0].iov_len + iov[1].iov_len;
David Howells8d94aa32016-09-07 09:19:31 +0100180
David Howellsb86e2182016-09-23 15:08:48 +0100181 serial = atomic_inc_return(&conn->serial);
182 pkt->whdr.serial = htonl(serial);
David Howells26cb02a2016-10-06 08:11:49 +0100183 trace_rxrpc_tx_ack(call, serial,
184 ntohl(pkt->ack.firstPacket),
185 ntohl(pkt->ack.serial),
186 pkt->ack.reason, pkt->ack.nAcks);
David Howellsbd1fdf82017-11-24 10:18:42 +0000187 if (_serial)
188 *_serial = serial;
David Howellsb86e2182016-09-23 15:08:48 +0100189
David Howells8e831342016-09-22 00:29:31 +0100190 if (ping) {
David Howellsa5af7e12016-10-06 08:11:49 +0100191 call->ping_serial = serial;
David Howells8e831342016-09-22 00:29:31 +0100192 smp_wmb();
193 /* We need to stick a time in before we send the packet in case
194 * the reply gets back before kernel_sendmsg() completes - but
195 * asking UDP to send the packet can take a relatively long
196 * time, so we update the time after, on the assumption that
197 * the packet transmission is more likely to happen towards the
198 * end of the kernel_sendmsg() call.
199 */
David Howellsa5af7e12016-10-06 08:11:49 +0100200 call->ping_time = ktime_get_real();
David Howells8e831342016-09-22 00:29:31 +0100201 set_bit(RXRPC_CALL_PINGING, &call->flags);
202 trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_ping, serial);
203 }
David Howells26cb02a2016-10-06 08:11:49 +0100204
205 ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 2, len);
David Howells8e831342016-09-22 00:29:31 +0100206 if (ping)
David Howellsa5af7e12016-10-06 08:11:49 +0100207 call->ping_time = ktime_get_real();
David Howells8d94aa32016-09-07 09:19:31 +0100208
David Howells26cb02a2016-10-06 08:11:49 +0100209 if (call->state < RXRPC_CALL_COMPLETE) {
David Howells805b21b2016-09-24 18:05:26 +0100210 if (ret < 0) {
David Howellsa5af7e12016-10-06 08:11:49 +0100211 if (ping)
212 clear_bit(RXRPC_CALL_PINGING, &call->flags);
David Howells248f2192016-09-08 11:10:12 +0100213 rxrpc_propose_ACK(call, pkt->ack.reason,
214 ntohs(pkt->ack.maxSkew),
215 ntohl(pkt->ack.serial),
David Howells9c7ad432016-09-23 13:50:40 +0100216 true, true,
217 rxrpc_propose_ack_retry_tx);
David Howells805b21b2016-09-24 18:05:26 +0100218 } else {
219 spin_lock_bh(&call->lock);
220 if (after(hard_ack, call->ackr_consumed))
221 call->ackr_consumed = hard_ack;
222 if (after(top, call->ackr_seen))
223 call->ackr_seen = top;
224 spin_unlock_bh(&call->lock);
David Howells248f2192016-09-08 11:10:12 +0100225 }
David Howells415f44e2017-11-24 10:18:42 +0000226
227 rxrpc_set_keepalive(call);
David Howells248f2192016-09-08 11:10:12 +0100228 }
229
David Howells8d94aa32016-09-07 09:19:31 +0100230out:
231 rxrpc_put_connection(conn);
232 kfree(pkt);
233 return ret;
234}
235
David Howells5873c082014-02-07 18:58:44 +0000236/*
David Howells26cb02a2016-10-06 08:11:49 +0100237 * Send an ABORT call packet.
238 */
239int rxrpc_send_abort_packet(struct rxrpc_call *call)
240{
241 struct rxrpc_connection *conn = NULL;
242 struct rxrpc_abort_buffer pkt;
243 struct msghdr msg;
244 struct kvec iov[1];
245 rxrpc_serial_t serial;
246 int ret;
247
David Howellsdcbefc32017-11-02 15:06:26 +0000248 /* Don't bother sending aborts for a client call once the server has
249 * hard-ACK'd all of its request data. After that point, we're not
250 * going to stop the operation proceeding, and whilst we might limit
251 * the reply, it's not worth it if we can send a new call on the same
252 * channel instead, thereby closing off this call.
253 */
254 if (rxrpc_is_client_call(call) &&
255 test_bit(RXRPC_CALL_TX_LAST, &call->flags))
256 return 0;
257
David Howells26cb02a2016-10-06 08:11:49 +0100258 spin_lock_bh(&call->lock);
259 if (call->conn)
260 conn = rxrpc_get_connection_maybe(call->conn);
261 spin_unlock_bh(&call->lock);
262 if (!conn)
263 return -ECONNRESET;
264
265 msg.msg_name = &call->peer->srx.transport;
266 msg.msg_namelen = call->peer->srx.transport_len;
267 msg.msg_control = NULL;
268 msg.msg_controllen = 0;
269 msg.msg_flags = 0;
270
271 pkt.whdr.epoch = htonl(conn->proto.epoch);
272 pkt.whdr.cid = htonl(call->cid);
273 pkt.whdr.callNumber = htonl(call->call_id);
274 pkt.whdr.seq = 0;
275 pkt.whdr.type = RXRPC_PACKET_TYPE_ABORT;
276 pkt.whdr.flags = conn->out_clientflag;
277 pkt.whdr.userStatus = 0;
278 pkt.whdr.securityIndex = call->security_ix;
279 pkt.whdr._rsvd = 0;
280 pkt.whdr.serviceId = htons(call->service_id);
281 pkt.abort_code = htonl(call->abort_code);
282
283 iov[0].iov_base = &pkt;
284 iov[0].iov_len = sizeof(pkt);
285
286 serial = atomic_inc_return(&conn->serial);
287 pkt.whdr.serial = htonl(serial);
288
289 ret = kernel_sendmsg(conn->params.local->socket,
290 &msg, iov, 1, sizeof(pkt));
291
292 rxrpc_put_connection(conn);
293 return ret;
294}
295
296/*
David Howells17926a72007-04-26 15:48:28 -0700297 * send a packet through the transport endpoint
298 */
David Howellsa1767072016-09-29 22:37:15 +0100299int rxrpc_send_data_packet(struct rxrpc_call *call, struct sk_buff *skb,
300 bool retrans)
David Howells17926a72007-04-26 15:48:28 -0700301{
David Howells5a924b82016-09-22 00:29:31 +0100302 struct rxrpc_connection *conn = call->conn;
303 struct rxrpc_wire_header whdr;
304 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
David Howells17926a72007-04-26 15:48:28 -0700305 struct msghdr msg;
David Howells5a924b82016-09-22 00:29:31 +0100306 struct kvec iov[2];
307 rxrpc_serial_t serial;
308 size_t len;
David Howellsa1767072016-09-29 22:37:15 +0100309 bool lost = false;
David Howells17926a72007-04-26 15:48:28 -0700310 int ret, opt;
311
312 _enter(",{%d}", skb->len);
313
David Howells5a924b82016-09-22 00:29:31 +0100314 /* Each transmission of a Tx packet needs a new serial number */
315 serial = atomic_inc_return(&conn->serial);
David Howells17926a72007-04-26 15:48:28 -0700316
David Howells5a924b82016-09-22 00:29:31 +0100317 whdr.epoch = htonl(conn->proto.epoch);
318 whdr.cid = htonl(call->cid);
319 whdr.callNumber = htonl(call->call_id);
320 whdr.seq = htonl(sp->hdr.seq);
321 whdr.serial = htonl(serial);
322 whdr.type = RXRPC_PACKET_TYPE_DATA;
323 whdr.flags = sp->hdr.flags;
324 whdr.userStatus = 0;
325 whdr.securityIndex = call->security_ix;
326 whdr._rsvd = htons(sp->hdr._rsvd);
327 whdr.serviceId = htons(call->service_id);
328
David Howells4e255722017-06-05 14:30:49 +0100329 if (test_bit(RXRPC_CONN_PROBING_FOR_UPGRADE, &conn->flags) &&
330 sp->hdr.seq == 1)
331 whdr.userStatus = RXRPC_USERSTATUS_SERVICE_UPGRADE;
332
David Howells5a924b82016-09-22 00:29:31 +0100333 iov[0].iov_base = &whdr;
334 iov[0].iov_len = sizeof(whdr);
335 iov[1].iov_base = skb->head;
336 iov[1].iov_len = skb->len;
337 len = iov[0].iov_len + iov[1].iov_len;
338
339 msg.msg_name = &call->peer->srx.transport;
340 msg.msg_namelen = call->peer->srx.transport_len;
David Howells17926a72007-04-26 15:48:28 -0700341 msg.msg_control = NULL;
342 msg.msg_controllen = 0;
343 msg.msg_flags = 0;
344
David Howells57494342016-09-24 18:05:27 +0100345 /* If our RTT cache needs working on, request an ACK. Also request
346 * ACKs if a DATA packet appears to have been lost.
347 */
David Howellsbf7d6202016-10-06 08:11:51 +0100348 if (!(sp->hdr.flags & RXRPC_LAST_PACKET) &&
David Howellsbd1fdf82017-11-24 10:18:42 +0000349 (test_and_clear_bit(RXRPC_CALL_EV_ACK_LOST, &call->events) ||
350 retrans ||
David Howellsbf7d6202016-10-06 08:11:51 +0100351 call->cong_mode == RXRPC_CALL_SLOW_START ||
352 (call->peer->rtt_usage < 3 && sp->hdr.seq & 1) ||
353 ktime_before(ktime_add_ms(call->peer->rtt_last_req, 1000),
354 ktime_get_real())))
David Howells0d4b1032016-09-22 00:29:31 +0100355 whdr.flags |= RXRPC_REQUEST_ACK;
356
David Howells8a681c362016-09-17 10:49:15 +0100357 if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) {
358 static int lose;
359 if ((lose++ & 7) == 7) {
David Howellsa1767072016-09-29 22:37:15 +0100360 ret = 0;
361 lost = true;
362 goto done;
David Howells8a681c362016-09-17 10:49:15 +0100363 }
364 }
365
David Howells5a924b82016-09-22 00:29:31 +0100366 _proto("Tx DATA %%%u { #%u }", serial, sp->hdr.seq);
367
David Howells17926a72007-04-26 15:48:28 -0700368 /* send the packet with the don't fragment bit set if we currently
369 * think it's small enough */
David Howells5a924b82016-09-22 00:29:31 +0100370 if (iov[1].iov_len >= call->peer->maxdata)
371 goto send_fragmentable;
David Howells17926a72007-04-26 15:48:28 -0700372
David Howells5a924b82016-09-22 00:29:31 +0100373 down_read(&conn->params.local->defrag_sem);
374 /* send the packet by UDP
375 * - returns -EMSGSIZE if UDP would have to fragment the packet
376 * to go out of the interface
377 * - in which case, we'll have processed the ICMP error
378 * message and update the peer record
379 */
380 ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 2, len);
David Howells17926a72007-04-26 15:48:28 -0700381
David Howells5a924b82016-09-22 00:29:31 +0100382 up_read(&conn->params.local->defrag_sem);
383 if (ret == -EMSGSIZE)
384 goto send_fragmentable;
385
386done:
David Howellsa1767072016-09-29 22:37:15 +0100387 trace_rxrpc_tx_data(call, sp->hdr.seq, serial, whdr.flags,
388 retrans, lost);
David Howells50235c42016-09-22 00:29:31 +0100389 if (ret >= 0) {
David Howells0d4b1032016-09-22 00:29:31 +0100390 ktime_t now = ktime_get_real();
391 skb->tstamp = now;
David Howells50235c42016-09-22 00:29:31 +0100392 smp_wmb();
David Howells5a924b82016-09-22 00:29:31 +0100393 sp->hdr.serial = serial;
David Howells0d4b1032016-09-22 00:29:31 +0100394 if (whdr.flags & RXRPC_REQUEST_ACK) {
395 call->peer->rtt_last_req = now;
David Howells50235c42016-09-22 00:29:31 +0100396 trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_data, serial);
David Howellsbd1fdf82017-11-24 10:18:42 +0000397 if (call->peer->rtt_usage > 1) {
398 unsigned long nowj = jiffies, ack_lost_at;
399
400 ack_lost_at = nsecs_to_jiffies(2 * call->peer->rtt);
401 if (ack_lost_at < 1)
402 ack_lost_at = 1;
403
404 ack_lost_at += nowj;
405 WRITE_ONCE(call->ack_lost_at, ack_lost_at);
406 rxrpc_reduce_call_timer(call, ack_lost_at, nowj,
407 rxrpc_timer_set_for_lost_ack);
408 }
David Howells0d4b1032016-09-22 00:29:31 +0100409 }
David Howells17926a72007-04-26 15:48:28 -0700410 }
David Howells415f44e2017-11-24 10:18:42 +0000411
412 rxrpc_set_keepalive(call);
413
David Howells5a924b82016-09-22 00:29:31 +0100414 _leave(" = %d [%u]", ret, call->peer->maxdata);
415 return ret;
David Howells17926a72007-04-26 15:48:28 -0700416
417send_fragmentable:
418 /* attempt to send this message with fragmentation enabled */
419 _debug("send fragment");
420
David Howells985a5c82016-06-17 11:53:37 +0100421 down_write(&conn->params.local->defrag_sem);
David Howells17926a72007-04-26 15:48:28 -0700422
David Howells985a5c82016-06-17 11:53:37 +0100423 switch (conn->params.local->srx.transport.family) {
424 case AF_INET:
425 opt = IP_PMTUDISC_DONT;
426 ret = kernel_setsockopt(conn->params.local->socket,
427 SOL_IP, IP_MTU_DISCOVER,
428 (char *)&opt, sizeof(opt));
429 if (ret == 0) {
David Howells5a924b82016-09-22 00:29:31 +0100430 ret = kernel_sendmsg(conn->params.local->socket, &msg,
431 iov, 2, len);
David Howells985a5c82016-06-17 11:53:37 +0100432
433 opt = IP_PMTUDISC_DO;
434 kernel_setsockopt(conn->params.local->socket, SOL_IP,
435 IP_MTU_DISCOVER,
436 (char *)&opt, sizeof(opt));
437 }
438 break;
David Howells75b54cb2016-09-13 08:49:05 +0100439
David Howellsd1912742016-09-17 07:26:01 +0100440#ifdef CONFIG_AF_RXRPC_IPV6
David Howells75b54cb2016-09-13 08:49:05 +0100441 case AF_INET6:
442 opt = IPV6_PMTUDISC_DONT;
443 ret = kernel_setsockopt(conn->params.local->socket,
444 SOL_IPV6, IPV6_MTU_DISCOVER,
445 (char *)&opt, sizeof(opt));
446 if (ret == 0) {
447 ret = kernel_sendmsg(conn->params.local->socket, &msg,
David Howells93c62c42018-02-22 14:38:14 +0000448 iov, 2, len);
David Howells75b54cb2016-09-13 08:49:05 +0100449
450 opt = IPV6_PMTUDISC_DO;
451 kernel_setsockopt(conn->params.local->socket,
452 SOL_IPV6, IPV6_MTU_DISCOVER,
453 (char *)&opt, sizeof(opt));
454 }
455 break;
David Howellsd1912742016-09-17 07:26:01 +0100456#endif
David Howells17926a72007-04-26 15:48:28 -0700457 }
458
David Howells985a5c82016-06-17 11:53:37 +0100459 up_write(&conn->params.local->defrag_sem);
David Howells5a924b82016-09-22 00:29:31 +0100460 goto done;
David Howells17926a72007-04-26 15:48:28 -0700461}
David Howells248f2192016-09-08 11:10:12 +0100462
463/*
464 * reject packets through the local endpoint
465 */
466void rxrpc_reject_packets(struct rxrpc_local *local)
467{
David Howells1c2bc7b2016-09-13 08:49:05 +0100468 struct sockaddr_rxrpc srx;
David Howells248f2192016-09-08 11:10:12 +0100469 struct rxrpc_skb_priv *sp;
470 struct rxrpc_wire_header whdr;
471 struct sk_buff *skb;
472 struct msghdr msg;
473 struct kvec iov[2];
474 size_t size;
475 __be32 code;
476
477 _enter("%d", local->debug_id);
478
479 iov[0].iov_base = &whdr;
480 iov[0].iov_len = sizeof(whdr);
481 iov[1].iov_base = &code;
482 iov[1].iov_len = sizeof(code);
483 size = sizeof(whdr) + sizeof(code);
484
David Howells1c2bc7b2016-09-13 08:49:05 +0100485 msg.msg_name = &srx.transport;
David Howells248f2192016-09-08 11:10:12 +0100486 msg.msg_control = NULL;
487 msg.msg_controllen = 0;
488 msg.msg_flags = 0;
489
David Howells248f2192016-09-08 11:10:12 +0100490 memset(&whdr, 0, sizeof(whdr));
491 whdr.type = RXRPC_PACKET_TYPE_ABORT;
492
493 while ((skb = skb_dequeue(&local->reject_queue))) {
David Howells71f3ca42016-09-17 10:49:14 +0100494 rxrpc_see_skb(skb, rxrpc_skb_rx_seen);
David Howells248f2192016-09-08 11:10:12 +0100495 sp = rxrpc_skb(skb);
David Howells1c2bc7b2016-09-13 08:49:05 +0100496
David Howells7b674e32017-08-29 10:18:37 +0100497 if (rxrpc_extract_addr_from_skb(local, &srx, skb) == 0) {
David Howells1c2bc7b2016-09-13 08:49:05 +0100498 msg.msg_namelen = srx.transport_len;
499
David Howells248f2192016-09-08 11:10:12 +0100500 code = htonl(skb->priority);
501
502 whdr.epoch = htonl(sp->hdr.epoch);
503 whdr.cid = htonl(sp->hdr.cid);
504 whdr.callNumber = htonl(sp->hdr.callNumber);
505 whdr.serviceId = htons(sp->hdr.serviceId);
506 whdr.flags = sp->hdr.flags;
507 whdr.flags ^= RXRPC_CLIENT_INITIATED;
508 whdr.flags &= RXRPC_CLIENT_INITIATED;
509
510 kernel_sendmsg(local->socket, &msg, iov, 2, size);
David Howells248f2192016-09-08 11:10:12 +0100511 }
512
David Howells71f3ca42016-09-17 10:49:14 +0100513 rxrpc_free_skb(skb, rxrpc_skb_rx_freed);
David Howells248f2192016-09-08 11:10:12 +0100514 }
515
516 _leave("");
517}