Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'rxrpc-fixes-20180928' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs

David Howells says:

====================
rxrpc: Fixes

Here are some miscellaneous fixes for AF_RXRPC:

(1) Remove a duplicate variable initialisation.

(2) Fix one of the checks made when we decide to set up a new incoming
service call in which a flag is being checked in the wrong field of
the packet header. This check is abstracted out into helper
functions.

(3) Fix RTT gathering. The code has been trying to make use of socket
timestamps, but wasn't actually enabling them. The code has also been
recording a transmit time for the outgoing packet for which we're
going to measure the RTT after sending the message - but we can get
the incoming packet before we get to that and record a negative RTT.

(4) Fix the emission of BUSY packets (we are emitting ABORTs instead).

(5) Improve error checking on incoming packets.

(6) Try to fix a bug in new service call handling whereby a BUG we should
never be able to reach somehow got triggered. Do this by moving much
of the checking as early as possible and not repeating it later
(depends on (5) above).

(7) Fix the sockopts set on a UDP6 socket to include the ones set on a
UDP4 socket so that we receive UDP4 errors and packet-too-large
notifications too.

(8) Fix the distribution of errors so that we do it at the point of
receiving an error in the UDP callback rather than deferring it
thereby cutting short any transmissions that would otherwise occur in
the window.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+193 -209
+1 -3
include/trace/events/rxrpc.h
··· 56 56 rxrpc_peer_new, 57 57 rxrpc_peer_processing, 58 58 rxrpc_peer_put, 59 - rxrpc_peer_queued_error, 60 59 }; 61 60 62 61 enum rxrpc_conn_trace { ··· 256 257 EM(rxrpc_peer_got, "GOT") \ 257 258 EM(rxrpc_peer_new, "NEW") \ 258 259 EM(rxrpc_peer_processing, "PRO") \ 259 - EM(rxrpc_peer_put, "PUT") \ 260 - E_(rxrpc_peer_queued_error, "QER") 260 + E_(rxrpc_peer_put, "PUT") 261 261 262 262 #define rxrpc_conn_traces \ 263 263 EM(rxrpc_conn_got, "GOT") \
+19 -17
net/rxrpc/ar-internal.h
··· 40 40 struct rxrpc_connection; 41 41 42 42 /* 43 - * Mark applied to socket buffers. 43 + * Mark applied to socket buffers in skb->mark. skb->priority is used 44 + * to pass supplementary information. 44 45 */ 45 46 enum rxrpc_skb_mark { 46 - RXRPC_SKB_MARK_DATA, /* data message */ 47 - RXRPC_SKB_MARK_FINAL_ACK, /* final ACK received message */ 48 - RXRPC_SKB_MARK_BUSY, /* server busy message */ 49 - RXRPC_SKB_MARK_REMOTE_ABORT, /* remote abort message */ 50 - RXRPC_SKB_MARK_LOCAL_ABORT, /* local abort message */ 51 - RXRPC_SKB_MARK_NET_ERROR, /* network error message */ 52 - RXRPC_SKB_MARK_LOCAL_ERROR, /* local error message */ 53 - RXRPC_SKB_MARK_NEW_CALL, /* local error message */ 47 + RXRPC_SKB_MARK_REJECT_BUSY, /* Reject with BUSY */ 48 + RXRPC_SKB_MARK_REJECT_ABORT, /* Reject with ABORT (code in skb->priority) */ 54 49 }; 55 50 56 51 /* ··· 288 293 struct hlist_node hash_link; 289 294 struct rxrpc_local *local; 290 295 struct hlist_head error_targets; /* targets for net error distribution */ 291 - struct work_struct error_distributor; 292 296 struct rb_root service_conns; /* Service connections */ 293 297 struct list_head keepalive_link; /* Link in net->peer_keepalive[] */ 294 298 time64_t last_tx_at; /* Last time packet sent here */ ··· 298 304 unsigned int maxdata; /* data size (MTU - hdrsize) */ 299 305 unsigned short hdrsize; /* header size (IP + UDP + RxRPC) */ 300 306 int debug_id; /* debug ID for printks */ 301 - int error_report; /* Net (+0) or local (+1000000) to distribute */ 302 - #define RXRPC_LOCAL_ERROR_OFFSET 1000000 303 307 struct sockaddr_rxrpc srx; /* remote address */ 304 308 305 309 /* calculated RTT cache */ ··· 454 462 u8 security_ix; /* security type */ 455 463 u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */ 456 464 }; 465 + 466 + static inline bool rxrpc_to_server(const struct rxrpc_skb_priv *sp) 467 + { 468 + return sp->hdr.flags & RXRPC_CLIENT_INITIATED; 469 + } 470 + 471 + static inline bool rxrpc_to_client(const struct rxrpc_skb_priv *sp) 472 + { 473 + return !rxrpc_to_server(sp); 474 + } 457 475 458 476 /* 459 477 * Flags in call->flags. ··· 719 717 int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t); 720 718 void rxrpc_discard_prealloc(struct rxrpc_sock *); 721 719 struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *, 720 + struct rxrpc_sock *, 721 + struct rxrpc_peer *, 722 722 struct rxrpc_connection *, 723 723 struct sk_buff *); 724 724 void rxrpc_accept_incoming_calls(struct rxrpc_local *); ··· 912 908 913 909 struct rxrpc_connection *rxrpc_alloc_connection(gfp_t); 914 910 struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *, 915 - struct sk_buff *); 911 + struct sk_buff *, 912 + struct rxrpc_peer **); 916 913 void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *); 917 914 void rxrpc_disconnect_call(struct rxrpc_call *); 918 915 void rxrpc_kill_connection(struct rxrpc_connection *); ··· 1036 1031 * peer_event.c 1037 1032 */ 1038 1033 void rxrpc_error_report(struct sock *); 1039 - void rxrpc_peer_error_distributor(struct work_struct *); 1040 1034 void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace, 1041 1035 rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t); 1042 1036 void rxrpc_peer_keepalive_worker(struct work_struct *); ··· 1048 1044 struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *, 1049 1045 struct sockaddr_rxrpc *, gfp_t); 1050 1046 struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t); 1051 - struct rxrpc_peer *rxrpc_lookup_incoming_peer(struct rxrpc_local *, 1052 - struct rxrpc_peer *); 1047 + void rxrpc_new_incoming_peer(struct rxrpc_local *, struct rxrpc_peer *); 1053 1048 void rxrpc_destroy_all_peers(struct rxrpc_net *); 1054 1049 struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *); 1055 1050 struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *); 1056 1051 void rxrpc_put_peer(struct rxrpc_peer *); 1057 - void __rxrpc_queue_peer_error(struct rxrpc_peer *); 1058 1052 1059 1053 /* 1060 1054 * proc.c
+14 -31
net/rxrpc/call_accept.c
··· 249 249 */ 250 250 static struct rxrpc_call *rxrpc_alloc_incoming_call(struct rxrpc_sock *rx, 251 251 struct rxrpc_local *local, 252 + struct rxrpc_peer *peer, 252 253 struct rxrpc_connection *conn, 253 254 struct sk_buff *skb) 254 255 { 255 256 struct rxrpc_backlog *b = rx->backlog; 256 - struct rxrpc_peer *peer, *xpeer; 257 257 struct rxrpc_call *call; 258 258 unsigned short call_head, conn_head, peer_head; 259 259 unsigned short call_tail, conn_tail, peer_tail; ··· 276 276 return NULL; 277 277 278 278 if (!conn) { 279 - /* No connection. We're going to need a peer to start off 280 - * with. If one doesn't yet exist, use a spare from the 281 - * preallocation set. We dump the address into the spare in 282 - * anticipation - and to save on stack space. 283 - */ 284 - xpeer = b->peer_backlog[peer_tail]; 285 - if (rxrpc_extract_addr_from_skb(local, &xpeer->srx, skb) < 0) 286 - return NULL; 287 - 288 - peer = rxrpc_lookup_incoming_peer(local, xpeer); 289 - if (peer == xpeer) { 279 + if (peer && !rxrpc_get_peer_maybe(peer)) 280 + peer = NULL; 281 + if (!peer) { 282 + peer = b->peer_backlog[peer_tail]; 283 + if (rxrpc_extract_addr_from_skb(local, &peer->srx, skb) < 0) 284 + return NULL; 290 285 b->peer_backlog[peer_tail] = NULL; 291 286 smp_store_release(&b->peer_backlog_tail, 292 287 (peer_tail + 1) & 293 288 (RXRPC_BACKLOG_MAX - 1)); 289 + 290 + rxrpc_new_incoming_peer(local, peer); 294 291 } 295 292 296 293 /* Now allocate and set up the connection */ ··· 332 335 * The call is returned with the user access mutex held. 333 336 */ 334 337 struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *local, 338 + struct rxrpc_sock *rx, 339 + struct rxrpc_peer *peer, 335 340 struct rxrpc_connection *conn, 336 341 struct sk_buff *skb) 337 342 { 338 343 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 339 - struct rxrpc_sock *rx; 340 344 struct rxrpc_call *call; 341 - u16 service_id = sp->hdr.serviceId; 342 345 343 346 _enter(""); 344 347 345 - /* Get the socket providing the service */ 346 - rx = rcu_dereference(local->service); 347 - if (rx && (service_id == rx->srx.srx_service || 348 - service_id == rx->second_service)) 349 - goto found_service; 350 - 351 - trace_rxrpc_abort(0, "INV", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq, 352 - RX_INVALID_OPERATION, EOPNOTSUPP); 353 - skb->mark = RXRPC_SKB_MARK_LOCAL_ABORT; 354 - skb->priority = RX_INVALID_OPERATION; 355 - _leave(" = NULL [service]"); 356 - return NULL; 357 - 358 - found_service: 359 348 spin_lock(&rx->incoming_lock); 360 349 if (rx->sk.sk_state == RXRPC_SERVER_LISTEN_DISABLED || 361 350 rx->sk.sk_state == RXRPC_CLOSE) { 362 351 trace_rxrpc_abort(0, "CLS", sp->hdr.cid, sp->hdr.callNumber, 363 352 sp->hdr.seq, RX_INVALID_OPERATION, ESHUTDOWN); 364 - skb->mark = RXRPC_SKB_MARK_LOCAL_ABORT; 353 + skb->mark = RXRPC_SKB_MARK_REJECT_ABORT; 365 354 skb->priority = RX_INVALID_OPERATION; 366 355 _leave(" = NULL [close]"); 367 356 call = NULL; 368 357 goto out; 369 358 } 370 359 371 - call = rxrpc_alloc_incoming_call(rx, local, conn, skb); 360 + call = rxrpc_alloc_incoming_call(rx, local, peer, conn, skb); 372 361 if (!call) { 373 - skb->mark = RXRPC_SKB_MARK_BUSY; 362 + skb->mark = RXRPC_SKB_MARK_REJECT_BUSY; 374 363 _leave(" = NULL [busy]"); 375 364 call = NULL; 376 365 goto out;
+1 -1
net/rxrpc/call_object.c
··· 400 400 rcu_assign_pointer(conn->channels[chan].call, call); 401 401 402 402 spin_lock(&conn->params.peer->lock); 403 - hlist_add_head(&call->error_link, &conn->params.peer->error_targets); 403 + hlist_add_head_rcu(&call->error_link, &conn->params.peer->error_targets); 404 404 spin_unlock(&conn->params.peer->lock); 405 405 406 406 _net("CALL incoming %d on CONN %d", call->debug_id, call->conn->debug_id);
+2 -2
net/rxrpc/conn_client.c
··· 710 710 } 711 711 712 712 spin_lock_bh(&call->conn->params.peer->lock); 713 - hlist_add_head(&call->error_link, 714 - &call->conn->params.peer->error_targets); 713 + hlist_add_head_rcu(&call->error_link, 714 + &call->conn->params.peer->error_targets); 715 715 spin_unlock_bh(&call->conn->params.peer->lock); 716 716 717 717 out:
+8 -6
net/rxrpc/conn_object.c
··· 69 69 * If successful, a pointer to the connection is returned, but no ref is taken. 70 70 * NULL is returned if there is no match. 71 71 * 72 + * When searching for a service call, if we find a peer but no connection, we 73 + * return that through *_peer in case we need to create a new service call. 74 + * 72 75 * The caller must be holding the RCU read lock. 73 76 */ 74 77 struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *local, 75 - struct sk_buff *skb) 78 + struct sk_buff *skb, 79 + struct rxrpc_peer **_peer) 76 80 { 77 81 struct rxrpc_connection *conn; 78 82 struct rxrpc_conn_proto k; ··· 89 85 if (rxrpc_extract_addr_from_skb(local, &srx, skb) < 0) 90 86 goto not_found; 91 87 92 - k.epoch = sp->hdr.epoch; 93 - k.cid = sp->hdr.cid & RXRPC_CIDMASK; 94 - 95 88 /* We may have to handle mixing IPv4 and IPv6 */ 96 89 if (srx.transport.family != local->srx.transport.family) { 97 90 pr_warn_ratelimited("AF_RXRPC: Protocol mismatch %u not %u\n", ··· 100 99 k.epoch = sp->hdr.epoch; 101 100 k.cid = sp->hdr.cid & RXRPC_CIDMASK; 102 101 103 - if (sp->hdr.flags & RXRPC_CLIENT_INITIATED) { 102 + if (rxrpc_to_server(sp)) { 104 103 /* We need to look up service connections by the full protocol 105 104 * parameter set. We look up the peer first as an intermediate 106 105 * step and then the connection from the peer's tree. ··· 108 107 peer = rxrpc_lookup_peer_rcu(local, &srx); 109 108 if (!peer) 110 109 goto not_found; 110 + *_peer = peer; 111 111 conn = rxrpc_find_service_conn_rcu(peer, skb); 112 112 if (!conn || atomic_read(&conn->usage) == 0) 113 113 goto not_found; ··· 216 214 call->peer->cong_cwnd = call->cong_cwnd; 217 215 218 216 spin_lock_bh(&conn->params.peer->lock); 219 - hlist_del_init(&call->error_link); 217 + hlist_del_rcu(&call->error_link); 220 218 spin_unlock_bh(&conn->params.peer->lock); 221 219 222 220 if (rxrpc_is_client_call(call))
+64 -26
net/rxrpc/input.c
··· 622 622 if (!skb) 623 623 continue; 624 624 625 + sent_at = skb->tstamp; 626 + smp_rmb(); /* Read timestamp before serial. */ 625 627 sp = rxrpc_skb(skb); 626 628 if (sp->hdr.serial != orig_serial) 627 629 continue; 628 - smp_rmb(); 629 - sent_at = skb->tstamp; 630 630 goto found; 631 631 } 632 + 632 633 return; 633 634 634 635 found: ··· 1125 1124 { 1126 1125 struct rxrpc_connection *conn; 1127 1126 struct rxrpc_channel *chan; 1128 - struct rxrpc_call *call; 1127 + struct rxrpc_call *call = NULL; 1129 1128 struct rxrpc_skb_priv *sp; 1130 1129 struct rxrpc_local *local = udp_sk->sk_user_data; 1130 + struct rxrpc_peer *peer = NULL; 1131 + struct rxrpc_sock *rx = NULL; 1131 1132 struct sk_buff *skb; 1132 1133 unsigned int channel; 1133 - int ret, skew; 1134 + int ret, skew = 0; 1134 1135 1135 1136 _enter("%p", udp_sk); 1136 1137 ··· 1145 1142 _debug("UDP socket error %d", ret); 1146 1143 return; 1147 1144 } 1145 + 1146 + if (skb->tstamp == 0) 1147 + skb->tstamp = ktime_get_real(); 1148 1148 1149 1149 rxrpc_new_skb(skb, rxrpc_skb_rx_received); 1150 1150 ··· 1183 1177 1184 1178 trace_rxrpc_rx_packet(sp); 1185 1179 1186 - _net("Rx RxRPC %s ep=%x call=%x:%x", 1187 - sp->hdr.flags & RXRPC_CLIENT_INITIATED ? "ToServer" : "ToClient", 1188 - sp->hdr.epoch, sp->hdr.cid, sp->hdr.callNumber); 1189 - 1190 - if (sp->hdr.type >= RXRPC_N_PACKET_TYPES || 1191 - !((RXRPC_SUPPORTED_PACKET_TYPES >> sp->hdr.type) & 1)) { 1192 - _proto("Rx Bad Packet Type %u", sp->hdr.type); 1193 - goto bad_message; 1194 - } 1195 - 1196 1180 switch (sp->hdr.type) { 1197 1181 case RXRPC_PACKET_TYPE_VERSION: 1198 - if (!(sp->hdr.flags & RXRPC_CLIENT_INITIATED)) 1182 + if (rxrpc_to_client(sp)) 1199 1183 goto discard; 1200 1184 rxrpc_post_packet_to_local(local, skb); 1201 1185 goto out; 1202 1186 1203 1187 case RXRPC_PACKET_TYPE_BUSY: 1204 - if (sp->hdr.flags & RXRPC_CLIENT_INITIATED) 1188 + if (rxrpc_to_server(sp)) 1205 1189 goto discard; 1206 1190 /* Fall through */ 1191 + case RXRPC_PACKET_TYPE_ACK: 1192 + case RXRPC_PACKET_TYPE_ACKALL: 1193 + if (sp->hdr.callNumber == 0) 1194 + goto bad_message; 1195 + /* Fall through */ 1196 + case RXRPC_PACKET_TYPE_ABORT: 1197 + break; 1207 1198 1208 1199 case RXRPC_PACKET_TYPE_DATA: 1209 - if (sp->hdr.callNumber == 0) 1200 + if (sp->hdr.callNumber == 0 || 1201 + sp->hdr.seq == 0) 1210 1202 goto bad_message; 1211 1203 if (sp->hdr.flags & RXRPC_JUMBO_PACKET && 1212 1204 !rxrpc_validate_jumbo(skb)) 1213 1205 goto bad_message; 1206 + break; 1207 + 1208 + case RXRPC_PACKET_TYPE_CHALLENGE: 1209 + if (rxrpc_to_server(sp)) 1210 + goto discard; 1211 + break; 1212 + case RXRPC_PACKET_TYPE_RESPONSE: 1213 + if (rxrpc_to_client(sp)) 1214 + goto discard; 1214 1215 break; 1215 1216 1216 1217 /* Packet types 9-11 should just be ignored. */ ··· 1225 1212 case RXRPC_PACKET_TYPE_10: 1226 1213 case RXRPC_PACKET_TYPE_11: 1227 1214 goto discard; 1215 + 1216 + default: 1217 + _proto("Rx Bad Packet Type %u", sp->hdr.type); 1218 + goto bad_message; 1228 1219 } 1220 + 1221 + if (sp->hdr.serviceId == 0) 1222 + goto bad_message; 1229 1223 1230 1224 rcu_read_lock(); 1231 1225 1232 - conn = rxrpc_find_connection_rcu(local, skb); 1226 + if (rxrpc_to_server(sp)) { 1227 + /* Weed out packets to services we're not offering. Packets 1228 + * that would begin a call are explicitly rejected and the rest 1229 + * are just discarded. 1230 + */ 1231 + rx = rcu_dereference(local->service); 1232 + if (!rx || (sp->hdr.serviceId != rx->srx.srx_service && 1233 + sp->hdr.serviceId != rx->second_service)) { 1234 + if (sp->hdr.type == RXRPC_PACKET_TYPE_DATA && 1235 + sp->hdr.seq == 1) 1236 + goto unsupported_service; 1237 + goto discard_unlock; 1238 + } 1239 + } 1240 + 1241 + conn = rxrpc_find_connection_rcu(local, skb, &peer); 1233 1242 if (conn) { 1234 1243 if (sp->hdr.securityIndex != conn->security_ix) 1235 1244 goto wrong_security; ··· 1315 1280 call = rcu_dereference(chan->call); 1316 1281 1317 1282 if (sp->hdr.callNumber > chan->call_id) { 1318 - if (!(sp->hdr.flags & RXRPC_CLIENT_INITIATED)) { 1283 + if (rxrpc_to_client(sp)) { 1319 1284 rcu_read_unlock(); 1320 1285 goto reject_packet; 1321 1286 } ··· 1332 1297 if (!test_bit(RXRPC_CALL_RX_HEARD, &call->flags)) 1333 1298 set_bit(RXRPC_CALL_RX_HEARD, &call->flags); 1334 1299 } 1335 - } else { 1336 - skew = 0; 1337 - call = NULL; 1338 1300 } 1339 1301 1340 1302 if (!call || atomic_read(&call->usage) == 0) { 1341 - if (!(sp->hdr.type & RXRPC_CLIENT_INITIATED) || 1342 - sp->hdr.callNumber == 0 || 1303 + if (rxrpc_to_client(sp) || 1343 1304 sp->hdr.type != RXRPC_PACKET_TYPE_DATA) 1344 1305 goto bad_message_unlock; 1345 1306 if (sp->hdr.seq != 1) 1346 1307 goto discard_unlock; 1347 - call = rxrpc_new_incoming_call(local, conn, skb); 1308 + call = rxrpc_new_incoming_call(local, rx, peer, conn, skb); 1348 1309 if (!call) { 1349 1310 rcu_read_unlock(); 1350 1311 goto reject_packet; ··· 1371 1340 skb->priority = RXKADINCONSISTENCY; 1372 1341 goto post_abort; 1373 1342 1343 + unsupported_service: 1344 + rcu_read_unlock(); 1345 + trace_rxrpc_abort(0, "INV", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq, 1346 + RX_INVALID_OPERATION, EOPNOTSUPP); 1347 + skb->priority = RX_INVALID_OPERATION; 1348 + goto post_abort; 1349 + 1374 1350 reupgrade: 1375 1351 rcu_read_unlock(); 1376 1352 trace_rxrpc_abort(0, "UPG", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq, ··· 1392 1354 protocol_error: 1393 1355 skb->priority = RX_PROTOCOL_ERROR; 1394 1356 post_abort: 1395 - skb->mark = RXRPC_SKB_MARK_LOCAL_ABORT; 1357 + skb->mark = RXRPC_SKB_MARK_REJECT_ABORT; 1396 1358 reject_packet: 1397 1359 trace_rxrpc_rx_done(skb->mark, skb->priority); 1398 1360 rxrpc_reject_packet(local, skb);
+26 -14
net/rxrpc/local_object.c
··· 135 135 } 136 136 137 137 switch (local->srx.transport.family) { 138 + case AF_INET6: 139 + /* we want to receive ICMPv6 errors */ 140 + opt = 1; 141 + ret = kernel_setsockopt(local->socket, SOL_IPV6, IPV6_RECVERR, 142 + (char *) &opt, sizeof(opt)); 143 + if (ret < 0) { 144 + _debug("setsockopt failed"); 145 + goto error; 146 + } 147 + 148 + /* we want to set the don't fragment bit */ 149 + opt = IPV6_PMTUDISC_DO; 150 + ret = kernel_setsockopt(local->socket, SOL_IPV6, IPV6_MTU_DISCOVER, 151 + (char *) &opt, sizeof(opt)); 152 + if (ret < 0) { 153 + _debug("setsockopt failed"); 154 + goto error; 155 + } 156 + 157 + /* Fall through and set IPv4 options too otherwise we don't get 158 + * errors from IPv4 packets sent through the IPv6 socket. 159 + */ 160 + 138 161 case AF_INET: 139 162 /* we want to receive ICMP errors */ 140 163 opt = 1; ··· 176 153 _debug("setsockopt failed"); 177 154 goto error; 178 155 } 179 - break; 180 156 181 - case AF_INET6: 182 - /* we want to receive ICMP errors */ 157 + /* We want receive timestamps. */ 183 158 opt = 1; 184 - ret = kernel_setsockopt(local->socket, SOL_IPV6, IPV6_RECVERR, 185 - (char *) &opt, sizeof(opt)); 186 - if (ret < 0) { 187 - _debug("setsockopt failed"); 188 - goto error; 189 - } 190 - 191 - /* we want to set the don't fragment bit */ 192 - opt = IPV6_PMTUDISC_DO; 193 - ret = kernel_setsockopt(local->socket, SOL_IPV6, IPV6_MTU_DISCOVER, 194 - (char *) &opt, sizeof(opt)); 159 + ret = kernel_setsockopt(local->socket, SOL_SOCKET, SO_TIMESTAMPNS, 160 + (char *)&opt, sizeof(opt)); 195 161 if (ret < 0) { 196 162 _debug("setsockopt failed"); 197 163 goto error;
+36 -18
net/rxrpc/output.c
··· 124 124 struct kvec iov[2]; 125 125 rxrpc_serial_t serial; 126 126 rxrpc_seq_t hard_ack, top; 127 - ktime_t now; 128 127 size_t len, n; 129 128 int ret; 130 129 u8 reason; ··· 195 196 /* We need to stick a time in before we send the packet in case 196 197 * the reply gets back before kernel_sendmsg() completes - but 197 198 * asking UDP to send the packet can take a relatively long 198 - * time, so we update the time after, on the assumption that 199 - * the packet transmission is more likely to happen towards the 200 - * end of the kernel_sendmsg() call. 199 + * time. 201 200 */ 202 201 call->ping_time = ktime_get_real(); 203 202 set_bit(RXRPC_CALL_PINGING, &call->flags); ··· 203 206 } 204 207 205 208 ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 2, len); 206 - now = ktime_get_real(); 207 - if (ping) 208 - call->ping_time = now; 209 209 conn->params.peer->last_tx_at = ktime_get_seconds(); 210 210 if (ret < 0) 211 211 trace_rxrpc_tx_fail(call->debug_id, serial, ret, ··· 357 363 358 364 /* If our RTT cache needs working on, request an ACK. Also request 359 365 * ACKs if a DATA packet appears to have been lost. 366 + * 367 + * However, we mustn't request an ACK on the last reply packet of a 368 + * service call, lest OpenAFS incorrectly send us an ACK with some 369 + * soft-ACKs in it and then never follow up with a proper hard ACK. 360 370 */ 361 - if (!(sp->hdr.flags & RXRPC_LAST_PACKET) && 371 + if ((!(sp->hdr.flags & RXRPC_LAST_PACKET) || 372 + rxrpc_to_server(sp) 373 + ) && 362 374 (test_and_clear_bit(RXRPC_CALL_EV_ACK_LOST, &call->events) || 363 375 retrans || 364 376 call->cong_mode == RXRPC_CALL_SLOW_START || ··· 390 390 goto send_fragmentable; 391 391 392 392 down_read(&conn->params.local->defrag_sem); 393 + 394 + sp->hdr.serial = serial; 395 + smp_wmb(); /* Set serial before timestamp */ 396 + skb->tstamp = ktime_get_real(); 397 + 393 398 /* send the packet by UDP 394 399 * - returns -EMSGSIZE if UDP would have to fragment the packet 395 400 * to go out of the interface ··· 418 413 trace_rxrpc_tx_data(call, sp->hdr.seq, serial, whdr.flags, 419 414 retrans, lost); 420 415 if (ret >= 0) { 421 - ktime_t now = ktime_get_real(); 422 - skb->tstamp = now; 423 - smp_wmb(); 424 - sp->hdr.serial = serial; 425 416 if (whdr.flags & RXRPC_REQUEST_ACK) { 426 - call->peer->rtt_last_req = now; 417 + call->peer->rtt_last_req = skb->tstamp; 427 418 trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_data, serial); 428 419 if (call->peer->rtt_usage > 1) { 429 420 unsigned long nowj = jiffies, ack_lost_at; ··· 457 456 _debug("send fragment"); 458 457 459 458 down_write(&conn->params.local->defrag_sem); 459 + 460 + sp->hdr.serial = serial; 461 + smp_wmb(); /* Set serial before timestamp */ 462 + skb->tstamp = ktime_get_real(); 460 463 461 464 switch (conn->params.local->srx.transport.family) { 462 465 case AF_INET: ··· 524 519 struct kvec iov[2]; 525 520 size_t size; 526 521 __be32 code; 527 - int ret; 522 + int ret, ioc; 528 523 529 524 _enter("%d", local->debug_id); 530 525 ··· 532 527 iov[0].iov_len = sizeof(whdr); 533 528 iov[1].iov_base = &code; 534 529 iov[1].iov_len = sizeof(code); 535 - size = sizeof(whdr) + sizeof(code); 536 530 537 531 msg.msg_name = &srx.transport; 538 532 msg.msg_control = NULL; ··· 539 535 msg.msg_flags = 0; 540 536 541 537 memset(&whdr, 0, sizeof(whdr)); 542 - whdr.type = RXRPC_PACKET_TYPE_ABORT; 543 538 544 539 while ((skb = skb_dequeue(&local->reject_queue))) { 545 540 rxrpc_see_skb(skb, rxrpc_skb_rx_seen); 546 541 sp = rxrpc_skb(skb); 547 542 543 + switch (skb->mark) { 544 + case RXRPC_SKB_MARK_REJECT_BUSY: 545 + whdr.type = RXRPC_PACKET_TYPE_BUSY; 546 + size = sizeof(whdr); 547 + ioc = 1; 548 + break; 549 + case RXRPC_SKB_MARK_REJECT_ABORT: 550 + whdr.type = RXRPC_PACKET_TYPE_ABORT; 551 + code = htonl(skb->priority); 552 + size = sizeof(whdr) + sizeof(code); 553 + ioc = 2; 554 + break; 555 + default: 556 + rxrpc_free_skb(skb, rxrpc_skb_rx_freed); 557 + continue; 558 + } 559 + 548 560 if (rxrpc_extract_addr_from_skb(local, &srx, skb) == 0) { 549 561 msg.msg_namelen = srx.transport_len; 550 - 551 - code = htonl(skb->priority); 552 562 553 563 whdr.epoch = htonl(sp->hdr.epoch); 554 564 whdr.cid = htonl(sp->hdr.cid);
+11 -35
net/rxrpc/peer_event.c
··· 23 23 #include "ar-internal.h" 24 24 25 25 static void rxrpc_store_error(struct rxrpc_peer *, struct sock_exterr_skb *); 26 + static void rxrpc_distribute_error(struct rxrpc_peer *, int, 27 + enum rxrpc_call_completion); 26 28 27 29 /* 28 30 * Find the peer associated with an ICMP packet. ··· 196 194 rcu_read_unlock(); 197 195 rxrpc_free_skb(skb, rxrpc_skb_rx_freed); 198 196 199 - /* The ref we obtained is passed off to the work item */ 200 - __rxrpc_queue_peer_error(peer); 201 197 _leave(""); 202 198 } 203 199 ··· 205 205 static void rxrpc_store_error(struct rxrpc_peer *peer, 206 206 struct sock_exterr_skb *serr) 207 207 { 208 + enum rxrpc_call_completion compl = RXRPC_CALL_NETWORK_ERROR; 208 209 struct sock_extended_err *ee; 209 210 int err; 210 211 ··· 256 255 case SO_EE_ORIGIN_NONE: 257 256 case SO_EE_ORIGIN_LOCAL: 258 257 _proto("Rx Received local error { error=%d }", err); 259 - err += RXRPC_LOCAL_ERROR_OFFSET; 258 + compl = RXRPC_CALL_LOCAL_ERROR; 260 259 break; 261 260 262 261 case SO_EE_ORIGIN_ICMP6: ··· 265 264 break; 266 265 } 267 266 268 - peer->error_report = err; 267 + rxrpc_distribute_error(peer, err, compl); 269 268 } 270 269 271 270 /* 272 - * Distribute an error that occurred on a peer 271 + * Distribute an error that occurred on a peer. 273 272 */ 274 - void rxrpc_peer_error_distributor(struct work_struct *work) 273 + static void rxrpc_distribute_error(struct rxrpc_peer *peer, int error, 274 + enum rxrpc_call_completion compl) 275 275 { 276 - struct rxrpc_peer *peer = 277 - container_of(work, struct rxrpc_peer, error_distributor); 278 276 struct rxrpc_call *call; 279 - enum rxrpc_call_completion compl; 280 - int error; 281 277 282 - _enter(""); 283 - 284 - error = READ_ONCE(peer->error_report); 285 - if (error < RXRPC_LOCAL_ERROR_OFFSET) { 286 - compl = RXRPC_CALL_NETWORK_ERROR; 287 - } else { 288 - compl = RXRPC_CALL_LOCAL_ERROR; 289 - error -= RXRPC_LOCAL_ERROR_OFFSET; 290 - } 291 - 292 - _debug("ISSUE ERROR %s %d", rxrpc_call_completions[compl], error); 293 - 294 - spin_lock_bh(&peer->lock); 295 - 296 - while (!hlist_empty(&peer->error_targets)) { 297 - call = hlist_entry(peer->error_targets.first, 298 - struct rxrpc_call, error_link); 299 - hlist_del_init(&call->error_link); 278 + hlist_for_each_entry_rcu(call, &peer->error_targets, error_link) { 300 279 rxrpc_see_call(call); 301 - 302 - if (rxrpc_set_call_completion(call, compl, 0, -error)) 280 + if (call->state < RXRPC_CALL_COMPLETE && 281 + rxrpc_set_call_completion(call, compl, 0, -error)) 303 282 rxrpc_notify_socket(call); 304 283 } 305 - 306 - spin_unlock_bh(&peer->lock); 307 - 308 - rxrpc_put_peer(peer); 309 - _leave(""); 310 284 } 311 285 312 286 /*
+11 -41
net/rxrpc/peer_object.c
··· 124 124 struct rxrpc_net *rxnet = local->rxnet; 125 125 126 126 hash_for_each_possible_rcu(rxnet->peer_hash, peer, hash_link, hash_key) { 127 - if (rxrpc_peer_cmp_key(peer, local, srx, hash_key) == 0) { 128 - if (atomic_read(&peer->usage) == 0) 129 - return NULL; 127 + if (rxrpc_peer_cmp_key(peer, local, srx, hash_key) == 0 && 128 + atomic_read(&peer->usage) > 0) 130 129 return peer; 131 - } 132 130 } 133 131 134 132 return NULL; ··· 220 222 atomic_set(&peer->usage, 1); 221 223 peer->local = local; 222 224 INIT_HLIST_HEAD(&peer->error_targets); 223 - INIT_WORK(&peer->error_distributor, 224 - &rxrpc_peer_error_distributor); 225 225 peer->service_conns = RB_ROOT; 226 226 seqlock_init(&peer->service_conn_lock); 227 227 spin_lock_init(&peer->lock); ··· 295 299 } 296 300 297 301 /* 298 - * Set up a new incoming peer. The address is prestored in the preallocated 299 - * peer. 302 + * Set up a new incoming peer. There shouldn't be any other matching peers 303 + * since we've already done a search in the list from the non-reentrant context 304 + * (the data_ready handler) that is the only place we can add new peers. 300 305 */ 301 - struct rxrpc_peer *rxrpc_lookup_incoming_peer(struct rxrpc_local *local, 302 - struct rxrpc_peer *prealloc) 306 + void rxrpc_new_incoming_peer(struct rxrpc_local *local, struct rxrpc_peer *peer) 303 307 { 304 - struct rxrpc_peer *peer; 305 308 struct rxrpc_net *rxnet = local->rxnet; 306 309 unsigned long hash_key; 307 310 308 - hash_key = rxrpc_peer_hash_key(local, &prealloc->srx); 309 - prealloc->local = local; 310 - rxrpc_init_peer(prealloc, hash_key); 311 + hash_key = rxrpc_peer_hash_key(local, &peer->srx); 312 + peer->local = local; 313 + rxrpc_init_peer(peer, hash_key); 311 314 312 315 spin_lock(&rxnet->peer_hash_lock); 313 - 314 - /* Need to check that we aren't racing with someone else */ 315 - peer = __rxrpc_lookup_peer_rcu(local, &prealloc->srx, hash_key); 316 - if (peer && !rxrpc_get_peer_maybe(peer)) 317 - peer = NULL; 318 - if (!peer) { 319 - peer = prealloc; 320 - hash_add_rcu(rxnet->peer_hash, &peer->hash_link, hash_key); 321 - list_add_tail(&peer->keepalive_link, &rxnet->peer_keepalive_new); 322 - } 323 - 316 + hash_add_rcu(rxnet->peer_hash, &peer->hash_link, hash_key); 317 + list_add_tail(&peer->keepalive_link, &rxnet->peer_keepalive_new); 324 318 spin_unlock(&rxnet->peer_hash_lock); 325 - return peer; 326 319 } 327 320 328 321 /* ··· 398 413 peer = NULL; 399 414 } 400 415 return peer; 401 - } 402 - 403 - /* 404 - * Queue a peer record. This passes the caller's ref to the workqueue. 405 - */ 406 - void __rxrpc_queue_peer_error(struct rxrpc_peer *peer) 407 - { 408 - const void *here = __builtin_return_address(0); 409 - int n; 410 - 411 - n = atomic_read(&peer->usage); 412 - if (rxrpc_queue_work(&peer->error_distributor)) 413 - trace_rxrpc_peer(peer, rxrpc_peer_queued_error, n, here); 414 - else 415 - rxrpc_put_peer(peer); 416 416 } 417 417 418 418 /*
-15
net/rxrpc/protocol.h
··· 50 50 #define RXRPC_PACKET_TYPE_10 10 /* Ignored */ 51 51 #define RXRPC_PACKET_TYPE_11 11 /* Ignored */ 52 52 #define RXRPC_PACKET_TYPE_VERSION 13 /* version string request */ 53 - #define RXRPC_N_PACKET_TYPES 14 /* number of packet types (incl type 0) */ 54 53 55 54 uint8_t flags; /* packet flags */ 56 55 #define RXRPC_CLIENT_INITIATED 0x01 /* signifies a packet generated by a client */ ··· 70 71 __be16 serviceId; /* service ID */ 71 72 72 73 } __packed; 73 - 74 - #define RXRPC_SUPPORTED_PACKET_TYPES ( \ 75 - (1 << RXRPC_PACKET_TYPE_DATA) | \ 76 - (1 << RXRPC_PACKET_TYPE_ACK) | \ 77 - (1 << RXRPC_PACKET_TYPE_BUSY) | \ 78 - (1 << RXRPC_PACKET_TYPE_ABORT) | \ 79 - (1 << RXRPC_PACKET_TYPE_ACKALL) | \ 80 - (1 << RXRPC_PACKET_TYPE_CHALLENGE) | \ 81 - (1 << RXRPC_PACKET_TYPE_RESPONSE) | \ 82 - /*(1 << RXRPC_PACKET_TYPE_DEBUG) | */ \ 83 - (1 << RXRPC_PACKET_TYPE_PARAMS) | \ 84 - (1 << RXRPC_PACKET_TYPE_10) | \ 85 - (1 << RXRPC_PACKET_TYPE_11) | \ 86 - (1 << RXRPC_PACKET_TYPE_VERSION)) 87 74 88 75 /*****************************************************************************/ 89 76 /*