Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* Peer event handling, typically ICMP messages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Written by David Howells (dhowells@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/errqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/udp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/in6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/icmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <net/af_rxrpc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "ar-internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static void rxrpc_store_error(struct rxrpc_peer *, struct sock_exterr_skb *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static void rxrpc_distribute_error(struct rxrpc_peer *, int,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 				   enum rxrpc_call_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * Find the peer associated with an ICMP packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static struct rxrpc_peer *rxrpc_lookup_peer_icmp_rcu(struct rxrpc_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 						     const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 						     struct sockaddr_rxrpc *srx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct sock_exterr_skb *serr = SKB_EXT_ERR(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	_enter("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	memset(srx, 0, sizeof(*srx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	srx->transport_type = local->srx.transport_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	srx->transport_len = local->srx.transport_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	srx->transport.family = local->srx.transport.family;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	/* Can we see an ICMP4 packet on an ICMP6 listening socket?  and vice
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	 * versa?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	switch (srx->transport.family) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	case AF_INET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		srx->transport_len = sizeof(srx->transport.sin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		srx->transport.family = AF_INET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		srx->transport.sin.sin_port = serr->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		switch (serr->ee.ee_origin) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		case SO_EE_ORIGIN_ICMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 			_net("Rx ICMP");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			memcpy(&srx->transport.sin.sin_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			       skb_network_header(skb) + serr->addr_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			       sizeof(struct in_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		case SO_EE_ORIGIN_ICMP6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 			_net("Rx ICMP6 on v4 sock");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 			memcpy(&srx->transport.sin.sin_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			       skb_network_header(skb) + serr->addr_offset + 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 			       sizeof(struct in_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 			memcpy(&srx->transport.sin.sin_addr, &ip_hdr(skb)->saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			       sizeof(struct in_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #ifdef CONFIG_AF_RXRPC_IPV6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	case AF_INET6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		switch (serr->ee.ee_origin) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		case SO_EE_ORIGIN_ICMP6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			_net("Rx ICMP6");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			srx->transport.sin6.sin6_port = serr->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			memcpy(&srx->transport.sin6.sin6_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			       skb_network_header(skb) + serr->addr_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			       sizeof(struct in6_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		case SO_EE_ORIGIN_ICMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			_net("Rx ICMP on v6 sock");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 			srx->transport_len = sizeof(srx->transport.sin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			srx->transport.family = AF_INET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			srx->transport.sin.sin_port = serr->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			memcpy(&srx->transport.sin.sin_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			       skb_network_header(skb) + serr->addr_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			       sizeof(struct in_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			memcpy(&srx->transport.sin6.sin6_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			       &ipv6_hdr(skb)->saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			       sizeof(struct in6_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return rxrpc_lookup_peer_rcu(local, srx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  * Handle an MTU/fragmentation problem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static void rxrpc_adjust_mtu(struct rxrpc_peer *peer, struct sock_exterr_skb *serr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	u32 mtu = serr->ee.ee_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	_net("Rx ICMP Fragmentation Needed (%d)", mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	/* wind down the local interface MTU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	if (mtu > 0 && peer->if_mtu == 65535 && mtu < peer->if_mtu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		peer->if_mtu = mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		_net("I/F MTU %u", mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (mtu == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		/* they didn't give us a size, estimate one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		mtu = peer->if_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		if (mtu > 1500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			mtu >>= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			if (mtu < 1500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 				mtu = 1500;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			mtu -= 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			if (mtu < peer->hdrsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 				mtu = peer->hdrsize + 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (mtu < peer->mtu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		spin_lock_bh(&peer->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		peer->mtu = mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		peer->maxdata = peer->mtu - peer->hdrsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		spin_unlock_bh(&peer->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		_net("Net MTU %u (maxdata %u)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		     peer->mtu, peer->maxdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * Handle an error received on the local endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) void rxrpc_error_report(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct sock_exterr_skb *serr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	struct sockaddr_rxrpc srx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	struct rxrpc_local *local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	struct rxrpc_peer *peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	local = rcu_dereference_sk_user_data(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (unlikely(!local)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	_enter("%p{%d}", sk, local->debug_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	/* Clear the outstanding error value on the socket so that it doesn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	 * cause kernel_sendmsg() to return it later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	sock_error(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	skb = sock_dequeue_err_skb(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		_leave("UDP socket errqueue empty");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	rxrpc_new_skb(skb, rxrpc_skb_received);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	serr = SKB_EXT_ERR(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if (!skb->len && serr->ee.ee_origin == SO_EE_ORIGIN_TIMESTAMPING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		_leave("UDP empty message");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		rxrpc_free_skb(skb, rxrpc_skb_freed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	peer = rxrpc_lookup_peer_icmp_rcu(local, skb, &srx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	if (peer && !rxrpc_get_peer_maybe(peer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		peer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (!peer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		rxrpc_free_skb(skb, rxrpc_skb_freed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		_leave(" [no peer]");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	trace_rxrpc_rx_icmp(peer, &serr->ee, &srx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if ((serr->ee.ee_origin == SO_EE_ORIGIN_ICMP &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	     serr->ee.ee_type == ICMP_DEST_UNREACH &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	     serr->ee.ee_code == ICMP_FRAG_NEEDED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		rxrpc_adjust_mtu(peer, serr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		rxrpc_free_skb(skb, rxrpc_skb_freed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		rxrpc_put_peer(peer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		_leave(" [MTU update]");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	rxrpc_store_error(peer, serr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	rxrpc_free_skb(skb, rxrpc_skb_freed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	rxrpc_put_peer(peer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	_leave("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  * Map an error report to error codes on the peer record.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static void rxrpc_store_error(struct rxrpc_peer *peer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			      struct sock_exterr_skb *serr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	enum rxrpc_call_completion compl = RXRPC_CALL_NETWORK_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	struct sock_extended_err *ee;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	_enter("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	ee = &serr->ee;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	err = ee->ee_errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	switch (ee->ee_origin) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	case SO_EE_ORIGIN_ICMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		switch (ee->ee_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		case ICMP_DEST_UNREACH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			switch (ee->ee_code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			case ICMP_NET_UNREACH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 				_net("Rx Received ICMP Network Unreachable");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			case ICMP_HOST_UNREACH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 				_net("Rx Received ICMP Host Unreachable");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			case ICMP_PORT_UNREACH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 				_net("Rx Received ICMP Port Unreachable");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			case ICMP_NET_UNKNOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 				_net("Rx Received ICMP Unknown Network");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			case ICMP_HOST_UNKNOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 				_net("Rx Received ICMP Unknown Host");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 				_net("Rx Received ICMP DestUnreach code=%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 				     ee->ee_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		case ICMP_TIME_EXCEEDED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			_net("Rx Received ICMP TTL Exceeded");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			_proto("Rx Received ICMP error { type=%u code=%u }",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			       ee->ee_type, ee->ee_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	case SO_EE_ORIGIN_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	case SO_EE_ORIGIN_LOCAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		_proto("Rx Received local error { error=%d }", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		compl = RXRPC_CALL_LOCAL_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	case SO_EE_ORIGIN_ICMP6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		if (err == EACCES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			err = EHOSTUNREACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		_proto("Rx Received error report { orig=%u }", ee->ee_origin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	rxrpc_distribute_error(peer, err, compl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)  * Distribute an error that occurred on a peer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static void rxrpc_distribute_error(struct rxrpc_peer *peer, int error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 				   enum rxrpc_call_completion compl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	struct rxrpc_call *call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	hlist_for_each_entry_rcu(call, &peer->error_targets, error_link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		rxrpc_see_call(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		rxrpc_set_call_completion(call, compl, 0, -error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)  * Perform keep-alive pings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static void rxrpc_peer_keepalive_dispatch(struct rxrpc_net *rxnet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 					  struct list_head *collector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 					  time64_t base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 					  u8 cursor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	struct rxrpc_peer *peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	const u8 mask = ARRAY_SIZE(rxnet->peer_keepalive) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	time64_t keepalive_at;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	int slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	spin_lock_bh(&rxnet->peer_hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	while (!list_empty(collector)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		peer = list_entry(collector->next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 				  struct rxrpc_peer, keepalive_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		list_del_init(&peer->keepalive_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		if (!rxrpc_get_peer_maybe(peer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		if (__rxrpc_use_local(peer->local)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 			spin_unlock_bh(&rxnet->peer_hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 			keepalive_at = peer->last_tx_at + RXRPC_KEEPALIVE_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 			slot = keepalive_at - base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 			_debug("%02x peer %u t=%d {%pISp}",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 			       cursor, peer->debug_id, slot, &peer->srx.transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 			if (keepalive_at <= base ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 			    keepalive_at > base + RXRPC_KEEPALIVE_TIME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 				rxrpc_send_keepalive(peer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 				slot = RXRPC_KEEPALIVE_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			/* A transmission to this peer occurred since last we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			 * examined it so put it into the appropriate future
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			 * bucket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 			slot += cursor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 			slot &= mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 			spin_lock_bh(&rxnet->peer_hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			list_add_tail(&peer->keepalive_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 				      &rxnet->peer_keepalive[slot & mask]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			rxrpc_unuse_local(peer->local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		rxrpc_put_peer_locked(peer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	spin_unlock_bh(&rxnet->peer_hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)  * Perform keep-alive pings with VERSION packets to keep any NAT alive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) void rxrpc_peer_keepalive_worker(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	struct rxrpc_net *rxnet =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		container_of(work, struct rxrpc_net, peer_keepalive_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	const u8 mask = ARRAY_SIZE(rxnet->peer_keepalive) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	time64_t base, now, delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	u8 cursor, stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	LIST_HEAD(collector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	now = ktime_get_seconds();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	base = rxnet->peer_keepalive_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	cursor = rxnet->peer_keepalive_cursor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	_enter("%lld,%u", base - now, cursor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	if (!rxnet->live)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	/* Remove to a temporary list all the peers that are currently lodged
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	 * in expired buckets plus all new peers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	 * Everything in the bucket at the cursor is processed this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	 * second; the bucket at cursor + 1 goes at now + 1s and so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	 * on...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	spin_lock_bh(&rxnet->peer_hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	list_splice_init(&rxnet->peer_keepalive_new, &collector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	stop = cursor + ARRAY_SIZE(rxnet->peer_keepalive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	while (base <= now && (s8)(cursor - stop) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		list_splice_tail_init(&rxnet->peer_keepalive[cursor & mask],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 				      &collector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		base++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		cursor++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	base = now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	spin_unlock_bh(&rxnet->peer_hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	rxnet->peer_keepalive_base = base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	rxnet->peer_keepalive_cursor = cursor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	rxrpc_peer_keepalive_dispatch(rxnet, &collector, base, cursor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	ASSERT(list_empty(&collector));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	/* Schedule the timer for the next occupied timeslot. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	cursor = rxnet->peer_keepalive_cursor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	stop = cursor + RXRPC_KEEPALIVE_TIME - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	for (; (s8)(cursor - stop) < 0; cursor++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		if (!list_empty(&rxnet->peer_keepalive[cursor & mask]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		base++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	now = ktime_get_seconds();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	delay = base - now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	if (delay < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		delay = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	delay *= HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	if (rxnet->live)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		timer_reduce(&rxnet->peer_keepalive_timer, jiffies + delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	_leave("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }