rxrpc: Split service connection code out into its own file
authorDavid Howells <dhowells@redhat.com>
Mon, 4 Apr 2016 13:00:40 +0000 (14:00 +0100)
committerDavid Howells <dhowells@redhat.com>
Wed, 6 Jul 2016 09:49:35 +0000 (10:49 +0100)
Split the service-specific connection code out into into its own file.  The
client-specific code has already been split out.  This will leave just the
common code in the original file.

Signed-off-by: David Howells <dhowells@redhat.com>
net/rxrpc/Makefile
net/rxrpc/ar-internal.h
net/rxrpc/conn_object.c
net/rxrpc/conn_service.c [new file with mode: 0644]

index 6522e50fb750038c3b1c22f57715665bdb47d8cd..10f3f48a16a8c0796b010f6a34d9458654876072 100644 (file)
@@ -10,6 +10,7 @@ af-rxrpc-y := \
        conn_client.o \
        conn_event.o \
        conn_object.o \
+       conn_service.o \
        input.o \
        insecure.o \
        key.o \
index 021d28b54282c8954e963cbcee7052bf5d70ed23..e1af258a7ac97c70d3a4010490bb7e12bd6c9d3f 100644 (file)
@@ -563,6 +563,9 @@ extern unsigned int rxrpc_connection_expiry;
 extern struct list_head rxrpc_connections;
 extern rwlock_t rxrpc_connection_lock;
 
+void rxrpc_conn_hash_proto_key(struct rxrpc_conn_proto *);
+void rxrpc_extract_conn_params(struct rxrpc_conn_proto *,
+                              struct rxrpc_local *, struct sk_buff *);
 struct rxrpc_connection *rxrpc_alloc_connection(gfp_t);
 struct rxrpc_connection *rxrpc_find_connection(struct rxrpc_local *,
                                               struct rxrpc_peer *,
@@ -571,9 +574,6 @@ void __rxrpc_disconnect_call(struct rxrpc_call *);
 void rxrpc_disconnect_call(struct rxrpc_call *);
 void rxrpc_put_connection(struct rxrpc_connection *);
 void __exit rxrpc_destroy_all_connections(void);
-struct rxrpc_connection *rxrpc_incoming_connection(struct rxrpc_local *,
-                                                  struct rxrpc_peer *,
-                                                  struct sk_buff *);
 
 static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn)
 {
@@ -603,6 +603,13 @@ static inline void rxrpc_queue_conn(struct rxrpc_connection *conn)
                rxrpc_put_connection(conn);
 }
 
+/*
+ * conn_service.c
+ */
+struct rxrpc_connection *rxrpc_incoming_connection(struct rxrpc_local *,
+                                                  struct rxrpc_peer *,
+                                                  struct sk_buff *);
+
 /*
  * input.c
  */
index ab5c8c2960e4601eaa28a2af0dbd3712e523aab4..8379e3748d131cb8bfe1fd71d5790aae804aa5ca 100644 (file)
@@ -60,138 +60,6 @@ struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
        return conn;
 }
 
-/*
- * get a record of an incoming connection
- */
-struct rxrpc_connection *rxrpc_incoming_connection(struct rxrpc_local *local,
-                                                  struct rxrpc_peer *peer,
-                                                  struct sk_buff *skb)
-{
-       struct rxrpc_connection *conn, *candidate = NULL;
-       struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
-       struct rb_node *p, **pp;
-       const char *new = "old";
-       u32 epoch, cid;
-
-       _enter("");
-
-       ASSERT(sp->hdr.flags & RXRPC_CLIENT_INITIATED);
-
-       epoch = sp->hdr.epoch;
-       cid = sp->hdr.cid & RXRPC_CIDMASK;
-
-       /* search the connection list first */
-       read_lock_bh(&peer->conn_lock);
-
-       p = peer->service_conns.rb_node;
-       while (p) {
-               conn = rb_entry(p, struct rxrpc_connection, service_node);
-
-               _debug("maybe %x", conn->proto.cid);
-
-               if (epoch < conn->proto.epoch)
-                       p = p->rb_left;
-               else if (epoch > conn->proto.epoch)
-                       p = p->rb_right;
-               else if (cid < conn->proto.cid)
-                       p = p->rb_left;
-               else if (cid > conn->proto.cid)
-                       p = p->rb_right;
-               else
-                       goto found_extant_connection;
-       }
-       read_unlock_bh(&peer->conn_lock);
-
-       /* not yet present - create a candidate for a new record and then
-        * redo the search */
-       candidate = rxrpc_alloc_connection(GFP_NOIO);
-       if (!candidate) {
-               _leave(" = -ENOMEM");
-               return ERR_PTR(-ENOMEM);
-       }
-
-       candidate->proto.local          = local;
-       candidate->proto.epoch          = sp->hdr.epoch;
-       candidate->proto.cid            = sp->hdr.cid & RXRPC_CIDMASK;
-       candidate->proto.in_clientflag  = RXRPC_CLIENT_INITIATED;
-       candidate->params.local         = local;
-       candidate->params.peer          = peer;
-       candidate->params.service_id    = sp->hdr.serviceId;
-       candidate->security_ix          = sp->hdr.securityIndex;
-       candidate->out_clientflag       = 0;
-       candidate->state                = RXRPC_CONN_SERVICE;
-       if (candidate->params.service_id)
-               candidate->state        = RXRPC_CONN_SERVICE_UNSECURED;
-
-       write_lock_bh(&peer->conn_lock);
-
-       pp = &peer->service_conns.rb_node;
-       p = NULL;
-       while (*pp) {
-               p = *pp;
-               conn = rb_entry(p, struct rxrpc_connection, service_node);
-
-               if (epoch < conn->proto.epoch)
-                       pp = &(*pp)->rb_left;
-               else if (epoch > conn->proto.epoch)
-                       pp = &(*pp)->rb_right;
-               else if (cid < conn->proto.cid)
-                       pp = &(*pp)->rb_left;
-               else if (cid > conn->proto.cid)
-                       pp = &(*pp)->rb_right;
-               else
-                       goto found_extant_second;
-       }
-
-       /* we can now add the new candidate to the list */
-       conn = candidate;
-       candidate = NULL;
-       rb_link_node(&conn->service_node, p, pp);
-       rb_insert_color(&conn->service_node, &peer->service_conns);
-       rxrpc_get_peer(peer);
-       rxrpc_get_local(local);
-
-       write_unlock_bh(&peer->conn_lock);
-
-       write_lock(&rxrpc_connection_lock);
-       list_add_tail(&conn->link, &rxrpc_connections);
-       write_unlock(&rxrpc_connection_lock);
-
-       new = "new";
-
-success:
-       _net("CONNECTION %s %d {%x}", new, conn->debug_id, conn->proto.cid);
-
-       _leave(" = %p {u=%d}", conn, atomic_read(&conn->usage));
-       return conn;
-
-       /* we found the connection in the list immediately */
-found_extant_connection:
-       if (sp->hdr.securityIndex != conn->security_ix) {
-               read_unlock_bh(&peer->conn_lock);
-               goto security_mismatch;
-       }
-       rxrpc_get_connection(conn);
-       read_unlock_bh(&peer->conn_lock);
-       goto success;
-
-       /* we found the connection on the second time through the list */
-found_extant_second:
-       if (sp->hdr.securityIndex != conn->security_ix) {
-               write_unlock_bh(&peer->conn_lock);
-               goto security_mismatch;
-       }
-       rxrpc_get_connection(conn);
-       write_unlock_bh(&peer->conn_lock);
-       kfree(candidate);
-       goto success;
-
-security_mismatch:
-       kfree(candidate);
-       _leave(" = -EKEYREJECTED");
-       return ERR_PTR(-EKEYREJECTED);
-}
-
 /*
  * find a connection based on transport and RxRPC connection ID for an incoming
  * packet
diff --git a/net/rxrpc/conn_service.c b/net/rxrpc/conn_service.c
new file mode 100644 (file)
index 0000000..cdcac50
--- /dev/null
@@ -0,0 +1,145 @@
+/* Service connection management
+ *
+ * Copyright (C) 2016 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#include <linux/slab.h>
+#include "ar-internal.h"
+
+/*
+ * get a record of an incoming connection
+ */
+struct rxrpc_connection *rxrpc_incoming_connection(struct rxrpc_local *local,
+                                                  struct rxrpc_peer *peer,
+                                                  struct sk_buff *skb)
+{
+       struct rxrpc_connection *conn, *candidate = NULL;
+       struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
+       struct rb_node *p, **pp;
+       const char *new = "old";
+       u32 epoch, cid;
+
+       _enter("");
+
+       ASSERT(sp->hdr.flags & RXRPC_CLIENT_INITIATED);
+
+       epoch = sp->hdr.epoch;
+       cid = sp->hdr.cid & RXRPC_CIDMASK;
+
+       /* search the connection list first */
+       read_lock_bh(&peer->conn_lock);
+
+       p = peer->service_conns.rb_node;
+       while (p) {
+               conn = rb_entry(p, struct rxrpc_connection, service_node);
+
+               _debug("maybe %x", conn->proto.cid);
+
+               if (epoch < conn->proto.epoch)
+                       p = p->rb_left;
+               else if (epoch > conn->proto.epoch)
+                       p = p->rb_right;
+               else if (cid < conn->proto.cid)
+                       p = p->rb_left;
+               else if (cid > conn->proto.cid)
+                       p = p->rb_right;
+               else
+                       goto found_extant_connection;
+       }
+       read_unlock_bh(&peer->conn_lock);
+
+       /* not yet present - create a candidate for a new record and then
+        * redo the search */
+       candidate = rxrpc_alloc_connection(GFP_NOIO);
+       if (!candidate) {
+               _leave(" = -ENOMEM");
+               return ERR_PTR(-ENOMEM);
+       }
+
+       candidate->proto.local          = local;
+       candidate->proto.epoch          = sp->hdr.epoch;
+       candidate->proto.cid            = sp->hdr.cid & RXRPC_CIDMASK;
+       candidate->proto.in_clientflag  = RXRPC_CLIENT_INITIATED;
+       candidate->params.local         = local;
+       candidate->params.peer          = peer;
+       candidate->params.service_id    = sp->hdr.serviceId;
+       candidate->security_ix          = sp->hdr.securityIndex;
+       candidate->out_clientflag       = 0;
+       candidate->state                = RXRPC_CONN_SERVICE;
+       if (candidate->params.service_id)
+               candidate->state        = RXRPC_CONN_SERVICE_UNSECURED;
+
+       write_lock_bh(&peer->conn_lock);
+
+       pp = &peer->service_conns.rb_node;
+       p = NULL;
+       while (*pp) {
+               p = *pp;
+               conn = rb_entry(p, struct rxrpc_connection, service_node);
+
+               if (epoch < conn->proto.epoch)
+                       pp = &(*pp)->rb_left;
+               else if (epoch > conn->proto.epoch)
+                       pp = &(*pp)->rb_right;
+               else if (cid < conn->proto.cid)
+                       pp = &(*pp)->rb_left;
+               else if (cid > conn->proto.cid)
+                       pp = &(*pp)->rb_right;
+               else
+                       goto found_extant_second;
+       }
+
+       /* we can now add the new candidate to the list */
+       conn = candidate;
+       candidate = NULL;
+       rb_link_node(&conn->service_node, p, pp);
+       rb_insert_color(&conn->service_node, &peer->service_conns);
+       rxrpc_get_peer(peer);
+       rxrpc_get_local(local);
+
+       write_unlock_bh(&peer->conn_lock);
+
+       write_lock(&rxrpc_connection_lock);
+       list_add_tail(&conn->link, &rxrpc_connections);
+       write_unlock(&rxrpc_connection_lock);
+
+       new = "new";
+
+success:
+       _net("CONNECTION %s %d {%x}", new, conn->debug_id, conn->proto.cid);
+
+       _leave(" = %p {u=%d}", conn, atomic_read(&conn->usage));
+       return conn;
+
+       /* we found the connection in the list immediately */
+found_extant_connection:
+       if (sp->hdr.securityIndex != conn->security_ix) {
+               read_unlock_bh(&peer->conn_lock);
+               goto security_mismatch;
+       }
+       rxrpc_get_connection(conn);
+       read_unlock_bh(&peer->conn_lock);
+       goto success;
+
+       /* we found the connection on the second time through the list */
+found_extant_second:
+       if (sp->hdr.securityIndex != conn->security_ix) {
+               write_unlock_bh(&peer->conn_lock);
+               goto security_mismatch;
+       }
+       rxrpc_get_connection(conn);
+       write_unlock_bh(&peer->conn_lock);
+       kfree(candidate);
+       goto success;
+
+security_mismatch:
+       kfree(candidate);
+       _leave(" = -EKEYREJECTED");
+       return ERR_PTR(-EKEYREJECTED);
+}