linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: netdev@vger.kernel.org
Cc: Marc Dionne <marc.dionne@auristor.com>,
	linux-afs@lists.infradead.org, dhowells@redhat.com,
	linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next 29/35] rxrpc: Extract the peer address from an incoming packet earlier
Date: Wed, 30 Nov 2022 16:58:28 +0000	[thread overview]
Message-ID: <166982750897.621383.7304976593934044192.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <166982725699.621383.2358362793992993374.stgit@warthog.procyon.org.uk>

Extract the peer address from an incoming packet earlier, at the beginning
of rxrpc_input_packet() and thence pass a pointer to it to various
functions that use it as part of the lookup rather than doing it on several
separate paths.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
---

 net/rxrpc/ar-internal.h |    2 ++
 net/rxrpc/call_accept.c |   10 ++++++----
 net/rxrpc/conn_object.c |   29 ++++++++---------------------
 net/rxrpc/io_thread.c   |   17 +++++++++++++++--
 4 files changed, 31 insertions(+), 27 deletions(-)

diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
index cfd16f1e5c83..c3c915a05627 100644
--- a/net/rxrpc/ar-internal.h
+++ b/net/rxrpc/ar-internal.h
@@ -824,6 +824,7 @@ int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t);
 void rxrpc_discard_prealloc(struct rxrpc_sock *);
 struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *,
 					   struct rxrpc_sock *,
+					   struct sockaddr_rxrpc *,
 					   struct sk_buff *);
 void rxrpc_accept_incoming_calls(struct rxrpc_local *);
 int rxrpc_user_charge_accept(struct rxrpc_sock *, unsigned long);
@@ -916,6 +917,7 @@ extern unsigned int rxrpc_closed_conn_expiry;
 
 struct rxrpc_connection *rxrpc_alloc_connection(struct rxrpc_net *, gfp_t);
 struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *,
+						   struct sockaddr_rxrpc *,
 						   struct sk_buff *,
 						   struct rxrpc_peer **);
 void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *);
diff --git a/net/rxrpc/call_accept.c b/net/rxrpc/call_accept.c
index beb8efa2e7a9..11134b7cec17 100644
--- a/net/rxrpc/call_accept.c
+++ b/net/rxrpc/call_accept.c
@@ -258,6 +258,7 @@ static struct rxrpc_call *rxrpc_alloc_incoming_call(struct rxrpc_sock *rx,
 						    struct rxrpc_peer *peer,
 						    struct rxrpc_connection *conn,
 						    const struct rxrpc_security *sec,
+						    struct sockaddr_rxrpc *peer_srx,
 						    struct sk_buff *skb)
 {
 	struct rxrpc_backlog *b = rx->backlog;
@@ -287,8 +288,7 @@ static struct rxrpc_call *rxrpc_alloc_incoming_call(struct rxrpc_sock *rx,
 			peer = NULL;
 		if (!peer) {
 			peer = b->peer_backlog[peer_tail];
-			if (rxrpc_extract_addr_from_skb(&peer->srx, skb) < 0)
-				return NULL;
+			peer->srx = *peer_srx;
 			b->peer_backlog[peer_tail] = NULL;
 			smp_store_release(&b->peer_backlog_tail,
 					  (peer_tail + 1) &
@@ -346,6 +346,7 @@ static struct rxrpc_call *rxrpc_alloc_incoming_call(struct rxrpc_sock *rx,
  */
 struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *local,
 					   struct rxrpc_sock *rx,
+					   struct sockaddr_rxrpc *peer_srx,
 					   struct sk_buff *skb)
 {
 	struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
@@ -371,7 +372,7 @@ struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *local,
 	 * we have to recheck the routing.  However, we're now holding
 	 * rx->incoming_lock, so the values should remain stable.
 	 */
-	conn = rxrpc_find_connection_rcu(local, skb, &peer);
+	conn = rxrpc_find_connection_rcu(local, peer_srx, skb, &peer);
 
 	if (!conn) {
 		sec = rxrpc_get_incoming_security(rx, skb);
@@ -379,7 +380,8 @@ struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *local,
 			goto no_call;
 	}
 
-	call = rxrpc_alloc_incoming_call(rx, local, peer, conn, sec, skb);
+	call = rxrpc_alloc_incoming_call(rx, local, peer, conn, sec, peer_srx,
+					 skb);
 	if (!call) {
 		skb->mark = RXRPC_SKB_MARK_REJECT_BUSY;
 		goto no_call;
diff --git a/net/rxrpc/conn_object.c b/net/rxrpc/conn_object.c
index 5a39255ea014..98e49646ca1d 100644
--- a/net/rxrpc/conn_object.c
+++ b/net/rxrpc/conn_object.c
@@ -73,29 +73,17 @@ struct rxrpc_connection *rxrpc_alloc_connection(struct rxrpc_net *rxnet,
  * The caller must be holding the RCU read lock.
  */
 struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *local,
+						   struct sockaddr_rxrpc *srx,
 						   struct sk_buff *skb,
 						   struct rxrpc_peer **_peer)
 {
 	struct rxrpc_connection *conn;
 	struct rxrpc_conn_proto k;
 	struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
-	struct sockaddr_rxrpc srx;
 	struct rxrpc_peer *peer;
 
 	_enter(",%x", sp->hdr.cid & RXRPC_CIDMASK);
 
-	if (rxrpc_extract_addr_from_skb(&srx, skb) < 0)
-		goto not_found;
-
-	if (srx.transport.family != local->srx.transport.family &&
-	    (srx.transport.family == AF_INET &&
-	     local->srx.transport.family != AF_INET6)) {
-		pr_warn_ratelimited("AF_RXRPC: Protocol mismatch %u not %u\n",
-				    srx.transport.family,
-				    local->srx.transport.family);
-		goto not_found;
-	}
-
 	k.epoch	= sp->hdr.epoch;
 	k.cid	= sp->hdr.cid & RXRPC_CIDMASK;
 
@@ -104,7 +92,7 @@ struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *local,
 		 * parameter set.  We look up the peer first as an intermediate
 		 * step and then the connection from the peer's tree.
 		 */
-		peer = rxrpc_lookup_peer_rcu(local, &srx);
+		peer = rxrpc_lookup_peer_rcu(local, srx);
 		if (!peer)
 			goto not_found;
 		*_peer = peer;
@@ -117,8 +105,7 @@ struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *local,
 		/* Look up client connections by connection ID alone as their
 		 * IDs are unique for this machine.
 		 */
-		conn = idr_find(&rxrpc_client_conn_ids,
-				sp->hdr.cid >> RXRPC_CIDSHIFT);
+		conn = idr_find(&rxrpc_client_conn_ids, sp->hdr.cid >> RXRPC_CIDSHIFT);
 		if (!conn || refcount_read(&conn->ref) == 0) {
 			_debug("no conn");
 			goto not_found;
@@ -129,20 +116,20 @@ struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *local,
 			goto not_found;
 
 		peer = conn->peer;
-		switch (srx.transport.family) {
+		switch (srx->transport.family) {
 		case AF_INET:
 			if (peer->srx.transport.sin.sin_port !=
-			    srx.transport.sin.sin_port ||
+			    srx->transport.sin.sin_port ||
 			    peer->srx.transport.sin.sin_addr.s_addr !=
-			    srx.transport.sin.sin_addr.s_addr)
+			    srx->transport.sin.sin_addr.s_addr)
 				goto not_found;
 			break;
 #ifdef CONFIG_AF_RXRPC_IPV6
 		case AF_INET6:
 			if (peer->srx.transport.sin6.sin6_port !=
-			    srx.transport.sin6.sin6_port ||
+			    srx->transport.sin6.sin6_port ||
 			    memcmp(&peer->srx.transport.sin6.sin6_addr,
-				   &srx.transport.sin6.sin6_addr,
+				   &srx->transport.sin6.sin6_addr,
 				   sizeof(struct in6_addr)) != 0)
 				goto not_found;
 			break;
diff --git a/net/rxrpc/io_thread.c b/net/rxrpc/io_thread.c
index 3b6927610677..bc65d83fab88 100644
--- a/net/rxrpc/io_thread.c
+++ b/net/rxrpc/io_thread.c
@@ -155,6 +155,7 @@ static bool rxrpc_extract_abort(struct sk_buff *skb)
 static int rxrpc_input_packet(struct rxrpc_local *local, struct sk_buff **_skb)
 {
 	struct rxrpc_connection *conn;
+	struct sockaddr_rxrpc peer_srx;
 	struct rxrpc_channel *chan;
 	struct rxrpc_call *call = NULL;
 	struct rxrpc_skb_priv *sp;
@@ -257,6 +258,18 @@ static int rxrpc_input_packet(struct rxrpc_local *local, struct sk_buff **_skb)
 	if (sp->hdr.serviceId == 0)
 		goto bad_message;
 
+	if (WARN_ON_ONCE(rxrpc_extract_addr_from_skb(&peer_srx, skb) < 0))
+		return 0; /* Unsupported address type - discard. */
+
+	if (peer_srx.transport.family != local->srx.transport.family &&
+	    (peer_srx.transport.family == AF_INET &&
+	     local->srx.transport.family != AF_INET6)) {
+		pr_warn_ratelimited("AF_RXRPC: Protocol mismatch %u not %u\n",
+				    peer_srx.transport.family,
+				    local->srx.transport.family);
+		return 0; /* Wrong address type - discard. */
+	}
+
 	rcu_read_lock();
 
 	if (rxrpc_to_server(sp)) {
@@ -276,7 +289,7 @@ static int rxrpc_input_packet(struct rxrpc_local *local, struct sk_buff **_skb)
 		}
 	}
 
-	conn = rxrpc_find_connection_rcu(local, skb, &peer);
+	conn = rxrpc_find_connection_rcu(local, &peer_srx, skb, &peer);
 	if (conn) {
 		if (sp->hdr.securityIndex != conn->security_ix)
 			goto wrong_security;
@@ -389,7 +402,7 @@ static int rxrpc_input_packet(struct rxrpc_local *local, struct sk_buff **_skb)
 			rcu_read_unlock();
 			return 0;
 		}
-		call = rxrpc_new_incoming_call(local, rx, skb);
+		call = rxrpc_new_incoming_call(local, rx, &peer_srx, skb);
 		if (!call) {
 			rcu_read_unlock();
 			goto reject_packet;



  parent reply	other threads:[~2022-11-30 17:03 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-30 16:54 [PATCH net-next 00/35] rxrpc: Increasing SACK size and moving away from softirq, parts 2 & 3 David Howells
2022-11-30 16:54 ` [PATCH net-next 01/35] rxrpc: Implement an in-kernel rxperf server for testing purposes David Howells
2022-12-01  4:04   ` Jakub Kicinski
2022-11-30 16:54 ` [PATCH net-next 02/35] rxrpc: Fix call leak David Howells
2022-11-30 16:54 ` [PATCH net-next 03/35] rxrpc: Remove decl for rxrpc_kernel_call_is_complete() David Howells
2022-11-30 16:54 ` [PATCH net-next 04/35] rxrpc: Remove handling of duplicate packets in recvmsg_queue David Howells
2022-11-30 16:55 ` [PATCH net-next 05/35] rxrpc: Remove the [k_]proto() debugging macros David Howells
2022-11-30 16:55 ` [PATCH net-next 06/35] rxrpc: Remove the [_k]net() " David Howells
2022-11-30 16:55 ` [PATCH net-next 07/35] rxrpc: Drop rxrpc_conn_parameters from rxrpc_connection and rxrpc_bundle David Howells
2022-11-30 16:55 ` [PATCH net-next 08/35] rxrpc: Extract the code from a received ABORT packet much earlier David Howells
2022-11-30 16:55 ` [PATCH net-next 09/35] rxrpc: trace: Don't use __builtin_return_address for rxrpc_local tracing David Howells
2022-11-30 16:55 ` [PATCH net-next 10/35] rxrpc: trace: Don't use __builtin_return_address for rxrpc_peer tracing David Howells
2022-11-30 16:55 ` [PATCH net-next 11/35] rxrpc: trace: Don't use __builtin_return_address for rxrpc_conn tracing David Howells
2022-11-30 16:56 ` [PATCH net-next 12/35] rxrpc: trace: Don't use __builtin_return_address for rxrpc_call tracing David Howells
2022-11-30 16:56 ` [PATCH net-next 13/35] rxrpc: Trace rxrpc_bundle refcount David Howells
2022-11-30 16:56 ` [PATCH net-next 14/35] rxrpc: trace: Don't use __builtin_return_address for sk_buff tracing David Howells
2022-11-30 16:56 ` [PATCH net-next 15/35] rxrpc: Don't hold a ref for call timer or workqueue David Howells
2022-11-30 16:56 ` [PATCH net-next 16/35] rxrpc: Don't hold a ref for connection workqueue David Howells
2022-11-30 16:56 ` [PATCH net-next 17/35] rxrpc: Split the receive code David Howells
2022-11-30 16:56 ` [PATCH net-next 18/35] rxrpc: Create a per-local endpoint receive queue and I/O thread David Howells
2022-11-30 16:57 ` [PATCH net-next 19/35] rxrpc: Move packet reception processing into " David Howells
2022-11-30 16:57 ` [PATCH net-next 20/35] rxrpc: Move error processing into the local endpoint " David Howells
2022-11-30 16:57 ` [PATCH net-next 21/35] rxrpc: Remove call->input_lock David Howells
2022-11-30 16:57 ` [PATCH net-next 22/35] rxrpc: Don't use sk->sk_receive_queue.lock to guard socket state changes David Howells
2022-11-30 16:57 ` [PATCH net-next 23/35] rxrpc: Implement a mechanism to send an event notification to a call David Howells
2022-11-30 16:57 ` [PATCH net-next 24/35] rxrpc: Copy client call parameters into rxrpc_call earlier David Howells
2022-11-30 16:57 ` [PATCH net-next 25/35] rxrpc: Move DATA transmission into call processor work item David Howells
2022-11-30 16:58 ` [PATCH net-next 26/35] rxrpc: Remove RCU from peer->error_targets list David Howells
2022-11-30 16:58 ` [PATCH net-next 27/35] rxrpc: Simplify skbuff accounting in receive path David Howells
2022-11-30 16:58 ` [PATCH net-next 28/35] rxrpc: Reduce the use of RCU in packet input David Howells
2022-11-30 16:58 ` David Howells [this message]
2022-11-30 16:58 ` [PATCH net-next 30/35] rxrpc: Make the I/O thread take over the call and local processor work David Howells
2022-11-30 16:58 ` [PATCH net-next 31/35] rxrpc: Remove the _bh annotation from all the spinlocks David Howells
2022-11-30 16:58 ` [PATCH net-next 32/35] rxrpc: Trace/count transmission underflows and cwnd resets David Howells
2022-11-30 16:59 ` [PATCH net-next 33/35] rxrpc: Move the cwnd degradation after transmitting packets David Howells
2022-11-30 16:59 ` [PATCH net-next 34/35] rxrpc: Fold __rxrpc_unuse_local() into rxrpc_unuse_local() David Howells
2022-11-30 16:59 ` [PATCH net-next 35/35] rxrpc: Transmit ACKs at the point of generation David Howells

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=166982750897.621383.7304976593934044192.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.dionne@auristor.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).