All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: davem@davemloft.net
Cc: dhowells@redhat.com, netdev@vger.kernel.org,
	linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next 17/24] rxrpc: Move peer lookup from call-accept to new-incoming-conn
Date: Tue, 05 Jul 2016 14:14:13 +0100	[thread overview]
Message-ID: <146772445297.21657.7652746484727390386.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <146772433082.21657.14046392058484946464.stgit@warthog.procyon.org.uk>

Move the lookup of a peer from a call that's being accepted into the
function that creates a new incoming connection.  This will allow us to
avoid incrementing the peer's usage count in some cases in future.

Note that I haven't bother to integrate rxrpc_get_addr_from_skb() with
rxrpc_extract_addr_from_skb() as I'm going to delete the former in the very
near future.

Signed-off-by: David Howells <dhowells@redhat.com>
---

 net/rxrpc/ar-internal.h  |    3 ++-
 net/rxrpc/call_accept.c  |   31 +++++++------------------------
 net/rxrpc/conn_service.c |   11 ++++++++++-
 net/rxrpc/utils.c        |   32 ++++++++++++++++++++++++++++++++
 4 files changed, 51 insertions(+), 26 deletions(-)

diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
index 2495c4facf51..7d87cace0177 100644
--- a/net/rxrpc/ar-internal.h
+++ b/net/rxrpc/ar-internal.h
@@ -609,7 +609,7 @@ static inline void rxrpc_queue_conn(struct rxrpc_connection *conn)
  * conn_service.c
  */
 struct rxrpc_connection *rxrpc_incoming_connection(struct rxrpc_local *,
-						   struct rxrpc_peer *,
+						   struct sockaddr_rxrpc *,
 						   struct sk_buff *);
 
 /*
@@ -775,6 +775,7 @@ static inline void rxrpc_sysctl_exit(void) {}
  */
 void rxrpc_get_addr_from_skb(struct rxrpc_local *, const struct sk_buff *,
 			     struct sockaddr_rxrpc *);
+int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
 
 /*
  * debug tracing
diff --git a/net/rxrpc/call_accept.c b/net/rxrpc/call_accept.c
index 5367dbe9b96f..0b2832141bd0 100644
--- a/net/rxrpc/call_accept.c
+++ b/net/rxrpc/call_accept.c
@@ -75,7 +75,6 @@ static int rxrpc_accept_incoming_call(struct rxrpc_local *local,
 {
 	struct rxrpc_connection *conn;
 	struct rxrpc_skb_priv *sp, *nsp;
-	struct rxrpc_peer *peer;
 	struct rxrpc_call *call;
 	struct sk_buff *notification;
 	int ret;
@@ -94,15 +93,7 @@ static int rxrpc_accept_incoming_call(struct rxrpc_local *local,
 	rxrpc_new_skb(notification);
 	notification->mark = RXRPC_SKB_MARK_NEW_CALL;
 
-	peer = rxrpc_lookup_peer(local, srx, GFP_NOIO);
-	if (!peer) {
-		_debug("no peer");
-		ret = -EBUSY;
-		goto error;
-	}
-
-	conn = rxrpc_incoming_connection(local, peer, skb);
-	rxrpc_put_peer(peer);
+	conn = rxrpc_incoming_connection(local, srx, skb);
 	if (IS_ERR(conn)) {
 		_debug("no conn");
 		ret = PTR_ERR(conn);
@@ -226,20 +217,8 @@ void rxrpc_accept_incoming_calls(struct rxrpc_local *local)
 	whdr._rsvd	= 0;
 	whdr.serviceId	= htons(sp->hdr.serviceId);
 
-	/* determine the remote address */
-	memset(&srx, 0, sizeof(srx));
-	srx.srx_family = AF_RXRPC;
-	srx.transport.family = local->srx.transport.family;
-	srx.transport_type = local->srx.transport_type;
-	switch (srx.transport.family) {
-	case AF_INET:
-		srx.transport_len = sizeof(struct sockaddr_in);
-		srx.transport.sin.sin_port = udp_hdr(skb)->source;
-		srx.transport.sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
-		break;
-	default:
-		goto busy;
-	}
+	if (rxrpc_extract_addr_from_skb(&srx, skb) < 0)
+		goto drop;
 
 	/* get the socket providing the service */
 	read_lock_bh(&local->services_lock);
@@ -285,6 +264,10 @@ busy:
 	rxrpc_free_skb(skb);
 	return;
 
+drop:
+	rxrpc_free_skb(skb);
+	return;
+
 invalid_service:
 	skb->priority = RX_INVALID_OPERATION;
 	rxrpc_reject_packet(local, skb);
diff --git a/net/rxrpc/conn_service.c b/net/rxrpc/conn_service.c
index cdcac50cd1a8..a42b210c40a5 100644
--- a/net/rxrpc/conn_service.c
+++ b/net/rxrpc/conn_service.c
@@ -16,17 +16,24 @@
  * get a record of an incoming connection
  */
 struct rxrpc_connection *rxrpc_incoming_connection(struct rxrpc_local *local,
-						   struct rxrpc_peer *peer,
+						   struct sockaddr_rxrpc *srx,
 						   struct sk_buff *skb)
 {
 	struct rxrpc_connection *conn, *candidate = NULL;
 	struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
+	struct rxrpc_peer *peer;
 	struct rb_node *p, **pp;
 	const char *new = "old";
 	u32 epoch, cid;
 
 	_enter("");
 
+	peer = rxrpc_lookup_peer(local, srx, GFP_NOIO);
+	if (!peer) {
+		_debug("no peer");
+		return ERR_PTR(-EBUSY);
+	}
+
 	ASSERT(sp->hdr.flags & RXRPC_CLIENT_INITIATED);
 
 	epoch = sp->hdr.epoch;
@@ -58,6 +65,7 @@ struct rxrpc_connection *rxrpc_incoming_connection(struct rxrpc_local *local,
 	 * redo the search */
 	candidate = rxrpc_alloc_connection(GFP_NOIO);
 	if (!candidate) {
+		rxrpc_put_peer(peer);
 		_leave(" = -ENOMEM");
 		return ERR_PTR(-ENOMEM);
 	}
@@ -114,6 +122,7 @@ struct rxrpc_connection *rxrpc_incoming_connection(struct rxrpc_local *local,
 success:
 	_net("CONNECTION %s %d {%x}", new, conn->debug_id, conn->proto.cid);
 
+	rxrpc_put_peer(peer);
 	_leave(" = %p {u=%d}", conn, atomic_read(&conn->usage));
 	return conn;
 
diff --git a/net/rxrpc/utils.c b/net/rxrpc/utils.c
index f28122a15a24..d3db02ecc37f 100644
--- a/net/rxrpc/utils.c
+++ b/net/rxrpc/utils.c
@@ -10,6 +10,7 @@
  */
 
 #include <linux/ip.h>
+#include <linux/ipv6.h>
 #include <linux/udp.h>
 #include "ar-internal.h"
 
@@ -39,3 +40,34 @@ void rxrpc_get_addr_from_skb(struct rxrpc_local *local,
 		BUG();
 	}
 }
+
+/*
+ * Fill out a peer address from a socket buffer containing a packet.
+ */
+int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *srx, struct sk_buff *skb)
+{
+	memset(srx, 0, sizeof(*srx));
+
+	switch (ntohs(skb->protocol)) {
+	case ETH_P_IP:
+		srx->transport_type = SOCK_DGRAM;
+		srx->transport_len = sizeof(srx->transport.sin);
+		srx->transport.sin.sin_family = AF_INET;
+		srx->transport.sin.sin_port = udp_hdr(skb)->source;
+		srx->transport.sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
+		return 0;
+
+	case ETH_P_IPV6:
+		srx->transport_type = SOCK_DGRAM;
+		srx->transport_len = sizeof(srx->transport.sin6);
+		srx->transport.sin6.sin6_family = AF_INET6;
+		srx->transport.sin6.sin6_port = udp_hdr(skb)->source;
+		srx->transport.sin6.sin6_addr = ipv6_hdr(skb)->saddr;
+		return 0;
+
+	default:
+		pr_warn_ratelimited("AF_RXRPC: Unknown eth protocol %u\n",
+				    ntohs(skb->protocol));
+		return -EAFNOSUPPORT;
+	}
+}

  parent reply	other threads:[~2016-07-05 13:17 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-05 13:12 [PATCH net-next 00/24] rxrpc: Improve conn/call lookup and fix call number generation [ver #2] David Howells
2016-07-05 13:12 ` [PATCH net-next 01/24] rxrpc: Fix processing of authenticated/encrypted jumbo packets David Howells
2016-07-05 17:55   ` Sergei Shtylyov
2016-07-05 19:26   ` David Howells
2016-07-05 13:12 ` [PATCH net-next 02/24] rxrpc: Fix some sparse errors David Howells
2016-07-05 13:12 ` [PATCH net-next 03/24] rxrpc: Check the source of a packet to a client conn David Howells
2016-07-05 13:12 ` [PATCH net-next 04/24] rxrpc: Avoid using stack memory in SG lists in rxkad David Howells
2016-07-06 13:19   ` Andy Lutomirski
2016-07-06 15:03   ` David Howells
2016-07-05 13:12 ` [PATCH net-next 05/24] rxrpc: Provide more refcount helper functions David Howells
2016-07-05 17:16   ` David Miller
2016-07-05 19:15   ` David Howells
2016-07-05 19:50   ` David Howells
2016-07-05 13:12 ` [PATCH net-next 06/24] rxrpc: Dup the main conn list for the proc interface David Howells
2016-07-05 17:17   ` David Miller
2016-07-05 19:21   ` David Howells
2016-07-05 19:53   ` David Howells
2016-07-05 13:13 ` [PATCH net-next 07/24] rxrpc: Turn connection #defines into enums and put outside struct def David Howells
2016-07-05 13:13 ` [PATCH net-next 08/24] rxrpc: Check that the client conns cache is empty before module removal David Howells
2016-07-05 13:13 ` [PATCH net-next 09/24] rxrpc: Move usage count getting into rxrpc_queue_conn() David Howells
2016-07-05 13:13 ` [PATCH net-next 10/24] rxrpc: Fix handling of connection failure in client call creation David Howells
2016-07-05 13:13 ` [PATCH net-next 11/24] rxrpc: Release a call's connection ref on call disconnection David Howells
2016-07-05 13:13 ` [PATCH net-next 12/24] rxrpc: Add RCU destruction for connections and calls David Howells
2016-07-05 13:13 ` [PATCH net-next 13/24] rxrpc: Access socket accept queue under right lock David Howells
2016-07-05 13:13 ` [PATCH net-next 14/24] rxrpc: Call channels should have separate call number spaces David Howells
2016-07-05 13:13 ` [PATCH net-next 15/24] rxrpc: Split client connection code out into its own file David Howells
2016-07-05 13:14 ` [PATCH net-next 16/24] rxrpc: Split service " David Howells
2016-07-05 13:14 ` David Howells [this message]
2016-07-05 13:14 ` [PATCH net-next 18/24] rxrpc: Maintain an extra ref on a conn for the cache list David Howells
2016-07-05 13:14 ` [PATCH net-next 19/24] rxrpc: Prune the contents of the rxrpc_conn_proto struct David Howells
2016-07-05 13:14 ` [PATCH net-next 20/24] rxrpc: Move data_ready peer lookup into rxrpc_find_connection() David Howells
2016-07-05 13:14 ` [PATCH net-next 21/24] Introduce rb_replace_node_rcu() David Howells
2016-07-05 13:14 ` [PATCH net-next 22/24] rcu: Suppress sparse warnings for rcu_dereference_raw() David Howells
2016-07-05 21:32   ` Paul E. McKenney
2016-07-05 13:14 ` [PATCH net-next 23/24] rxrpc: Use RCU to access a peer's service connection tree David Howells
2016-07-05 13:15 ` [PATCH net-next 24/24] rxrpc: Kill off the call hash table 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=146772445297.21657.7652746484727390386.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=davem@davemloft.net \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.