Skip to content

Commit 19ffa01

Browse files
committed
rxrpc: Use structs to hold connection params and protocol info
Define and use a structure to hold connection parameters. This makes it easier to pass multiple connection parameters around. Define and use a structure to hold protocol information used to hash a connection for lookup on incoming packet. Most of these fields will be disposed of eventually, including the duplicate local pointer. Whilst we're at it rename "proto" to "family" when referring to a protocol family. Signed-off-by: David Howells <[email protected]>
1 parent 2f9f9f5 commit 19ffa01

File tree

13 files changed

+226
-163
lines changed

13 files changed

+226
-163
lines changed

net/rxrpc/af_rxrpc.c

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static int rxrpc_validate_address(struct rxrpc_sock *rx,
9797
srx->transport_len > len)
9898
return -EINVAL;
9999

100-
if (srx->transport.family != rx->proto)
100+
if (srx->transport.family != rx->family)
101101
return -EAFNOSUPPORT;
102102

103103
switch (srx->transport.family) {
@@ -227,32 +227,30 @@ static int rxrpc_listen(struct socket *sock, int backlog)
227227
/*
228228
* find a transport by address
229229
*/
230-
struct rxrpc_transport *rxrpc_name_to_transport(struct rxrpc_sock *rx,
231-
struct sockaddr *addr,
232-
int addr_len, int flags,
233-
gfp_t gfp)
230+
struct rxrpc_transport *
231+
rxrpc_name_to_transport(struct rxrpc_conn_parameters *cp,
232+
struct sockaddr *addr,
233+
int addr_len,
234+
gfp_t gfp)
234235
{
235236
struct sockaddr_rxrpc *srx = (struct sockaddr_rxrpc *) addr;
236237
struct rxrpc_transport *trans;
237-
struct rxrpc_peer *peer;
238238

239-
_enter("%p,%p,%d,%d", rx, addr, addr_len, flags);
240-
241-
ASSERT(rx->local != NULL);
239+
_enter("%p,%d", addr, addr_len);
242240

243-
if (rx->srx.transport_type != srx->transport_type)
241+
if (cp->local->srx.transport_type != srx->transport_type)
244242
return ERR_PTR(-ESOCKTNOSUPPORT);
245-
if (rx->srx.transport.family != srx->transport.family)
243+
if (cp->local->srx.transport.family != srx->transport.family)
246244
return ERR_PTR(-EAFNOSUPPORT);
247245

248246
/* find a remote transport endpoint from the local one */
249-
peer = rxrpc_lookup_peer(rx->local, srx, gfp);
250-
if (!peer)
247+
cp->peer = rxrpc_lookup_peer(cp->local, srx, gfp);
248+
if (!cp->peer)
251249
return ERR_PTR(-ENOMEM);
252250

253251
/* find a transport */
254-
trans = rxrpc_get_transport(rx->local, peer, gfp);
255-
rxrpc_put_peer(peer);
252+
trans = rxrpc_get_transport(cp->local, cp->peer, gfp);
253+
rxrpc_put_peer(cp->peer);
256254
_leave(" = %p", trans);
257255
return trans;
258256
}
@@ -277,6 +275,7 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
277275
unsigned long user_call_ID,
278276
gfp_t gfp)
279277
{
278+
struct rxrpc_conn_parameters cp;
280279
struct rxrpc_conn_bundle *bundle;
281280
struct rxrpc_transport *trans;
282281
struct rxrpc_call *call;
@@ -286,26 +285,34 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
286285

287286
lock_sock(&rx->sk);
288287

289-
trans = rxrpc_name_to_transport(rx, (struct sockaddr *)srx,
290-
sizeof(*srx), 0, gfp);
288+
if (!key)
289+
key = rx->key;
290+
if (key && !key->payload.data[0])
291+
key = NULL; /* a no-security key */
292+
293+
memset(&cp, 0, sizeof(cp));
294+
cp.local = rx->local;
295+
cp.key = key;
296+
cp.security_level = 0;
297+
cp.exclusive = false;
298+
cp.service_id = srx->srx_service;
299+
300+
trans = rxrpc_name_to_transport(&cp, (struct sockaddr *)srx,
301+
sizeof(*srx), gfp);
291302
if (IS_ERR(trans)) {
292303
call = ERR_CAST(trans);
293304
trans = NULL;
294305
goto out_notrans;
295306
}
296-
297-
if (!key)
298-
key = rx->key;
299-
if (key && !key->payload.data[0])
300-
key = NULL; /* a no-security key */
307+
cp.peer = trans->peer;
301308

302309
bundle = rxrpc_get_bundle(rx, trans, key, srx->srx_service, gfp);
303310
if (IS_ERR(bundle)) {
304311
call = ERR_CAST(bundle);
305312
goto out;
306313
}
307314

308-
call = rxrpc_new_client_call(rx, trans, bundle, user_call_ID, gfp);
315+
call = rxrpc_new_client_call(rx, &cp, trans, bundle, user_call_ID, gfp);
309316
rxrpc_put_bundle(trans, bundle);
310317
out:
311318
rxrpc_put_transport(trans);
@@ -600,7 +607,7 @@ static int rxrpc_create(struct net *net, struct socket *sock, int protocol,
600607
sk->sk_destruct = rxrpc_sock_destructor;
601608

602609
rx = rxrpc_sk(sk);
603-
rx->proto = protocol;
610+
rx->family = protocol;
604611
rx->calls = RB_ROOT;
605612

606613
INIT_LIST_HEAD(&rx->listen_link);

net/rxrpc/ar-internal.h

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct rxrpc_sock {
7272
#define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT
7373
struct sockaddr_rxrpc srx; /* local address */
7474
struct sockaddr_rxrpc connect_srx; /* Default client address from connect() */
75-
sa_family_t proto; /* protocol created with */
75+
sa_family_t family; /* protocol family created with */
7676
};
7777

7878
#define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
@@ -261,6 +261,34 @@ struct rxrpc_conn_bundle {
261261
u8 security_ix; /* security type */
262262
};
263263

264+
/*
265+
* Keys for matching a connection.
266+
*/
267+
struct rxrpc_conn_proto {
268+
unsigned long hash_key;
269+
struct rxrpc_local *local; /* Representation of local endpoint */
270+
u32 epoch; /* epoch of this connection */
271+
u32 cid; /* connection ID */
272+
u8 in_clientflag; /* RXRPC_CLIENT_INITIATED if we are server */
273+
u8 addr_size; /* Size of the address */
274+
sa_family_t family; /* Transport protocol */
275+
__be16 port; /* Peer UDP/UDP6 port */
276+
union { /* Peer address */
277+
struct in_addr ipv4_addr;
278+
struct in6_addr ipv6_addr;
279+
u32 raw_addr[0];
280+
};
281+
};
282+
283+
struct rxrpc_conn_parameters {
284+
struct rxrpc_local *local; /* Representation of local endpoint */
285+
struct rxrpc_peer *peer; /* Remote endpoint */
286+
struct key *key; /* Security details */
287+
bool exclusive; /* T if conn is exclusive */
288+
u16 service_id; /* Service ID for this connection */
289+
u32 security_level; /* Security level selected */
290+
};
291+
264292
/*
265293
* RxRPC connection definition
266294
* - matched by { transport, service_id, conn_id, direction, key }
@@ -269,6 +297,9 @@ struct rxrpc_conn_bundle {
269297
struct rxrpc_connection {
270298
struct rxrpc_transport *trans; /* transport session */
271299
struct rxrpc_conn_bundle *bundle; /* connection bundle (client) */
300+
struct rxrpc_conn_proto proto;
301+
struct rxrpc_conn_parameters params;
302+
272303
struct work_struct processor; /* connection event processor */
273304
struct rb_node node; /* node in transport's lookup tree */
274305
struct list_head link; /* link in master connection list */
@@ -277,7 +308,6 @@ struct rxrpc_connection {
277308
struct sk_buff_head rx_queue; /* received conn-level packets */
278309
struct rxrpc_call *channels[RXRPC_MAXCALLS]; /* channels (active calls) */
279310
const struct rxrpc_security *security; /* applied security module */
280-
struct key *key; /* security for this connection (client) */
281311
struct key *server_key; /* security for this service */
282312
struct crypto_skcipher *cipher; /* encryption handle */
283313
struct rxrpc_crypt csum_iv; /* packet checksum base */
@@ -308,13 +338,8 @@ struct rxrpc_connection {
308338
u8 size_align; /* data size alignment (for security) */
309339
u8 header_size; /* rxrpc + security header size */
310340
u8 security_size; /* security header size */
311-
u32 security_level; /* security level negotiated */
312341
u32 security_nonce; /* response re-use preventer */
313-
u32 epoch; /* epoch of this connection */
314-
u32 cid; /* connection ID */
315-
u16 service_id; /* service ID for this connection */
316342
u8 security_ix; /* security type */
317-
u8 in_clientflag; /* RXRPC_CLIENT_INITIATED if we are server */
318343
u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */
319344
};
320345

@@ -448,7 +473,7 @@ struct rxrpc_call {
448473
unsigned long hash_key; /* Full hash key */
449474
u8 in_clientflag; /* Copy of conn->in_clientflag for hashing */
450475
struct rxrpc_local *local; /* Local endpoint. Used for hashing. */
451-
sa_family_t proto; /* Frame protocol */
476+
sa_family_t family; /* Frame protocol */
452477
u32 call_id; /* call ID on connection */
453478
u32 cid; /* connection ID plus channel index */
454479
u32 epoch; /* epoch of this connection */
@@ -481,9 +506,9 @@ extern u32 rxrpc_epoch;
481506
extern atomic_t rxrpc_debug_id;
482507
extern struct workqueue_struct *rxrpc_workqueue;
483508

484-
extern struct rxrpc_transport *rxrpc_name_to_transport(struct rxrpc_sock *,
509+
extern struct rxrpc_transport *rxrpc_name_to_transport(struct rxrpc_conn_parameters *,
485510
struct sockaddr *,
486-
int, int, gfp_t);
511+
int, gfp_t);
487512

488513
/*
489514
* call_accept.c
@@ -512,6 +537,7 @@ struct rxrpc_call *rxrpc_find_call_hash(struct rxrpc_host_header *,
512537
void *, sa_family_t, const void *);
513538
struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long);
514539
struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *,
540+
struct rxrpc_conn_parameters *,
515541
struct rxrpc_transport *,
516542
struct rxrpc_conn_bundle *,
517543
unsigned long, gfp_t);
@@ -541,15 +567,26 @@ struct rxrpc_conn_bundle *rxrpc_get_bundle(struct rxrpc_sock *,
541567
struct rxrpc_transport *,
542568
struct key *, u16, gfp_t);
543569
void rxrpc_put_bundle(struct rxrpc_transport *, struct rxrpc_conn_bundle *);
544-
int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_transport *,
545-
struct rxrpc_conn_bundle *, struct rxrpc_call *, gfp_t);
570+
int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_conn_parameters *,
571+
struct rxrpc_transport *, struct rxrpc_conn_bundle *,
572+
struct rxrpc_call *, gfp_t);
546573
void rxrpc_put_connection(struct rxrpc_connection *);
547574
void __exit rxrpc_destroy_all_connections(void);
548575
struct rxrpc_connection *rxrpc_find_connection(struct rxrpc_transport *,
549576
struct rxrpc_host_header *);
550577
extern struct rxrpc_connection *
551578
rxrpc_incoming_connection(struct rxrpc_transport *, struct rxrpc_host_header *);
552579

580+
static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn)
581+
{
582+
return conn->out_clientflag;
583+
}
584+
585+
static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn)
586+
{
587+
return conn->proto.in_clientflag;
588+
}
589+
553590
/*
554591
* input.c
555592
*/

net/rxrpc/call_event.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ void rxrpc_process_call(struct work_struct *work)
842842
msg.msg_controllen = 0;
843843
msg.msg_flags = 0;
844844

845-
whdr.epoch = htonl(call->conn->epoch);
845+
whdr.epoch = htonl(call->conn->proto.epoch);
846846
whdr.cid = htonl(call->cid);
847847
whdr.callNumber = htonl(call->call_id);
848848
whdr.seq = 0;
@@ -1264,7 +1264,7 @@ void rxrpc_process_call(struct work_struct *work)
12641264
if (call->state >= RXRPC_CALL_COMPLETE &&
12651265
!list_empty(&call->accept_link)) {
12661266
_debug("X unlinking once-pending call %p { e=%lx f=%lx c=%x }",
1267-
call, call->events, call->flags, call->conn->cid);
1267+
call, call->events, call->flags, call->conn->proto.cid);
12681268

12691269
read_lock_bh(&call->state_lock);
12701270
if (!test_bit(RXRPC_CALL_RELEASED, &call->flags) &&
@@ -1282,7 +1282,7 @@ void rxrpc_process_call(struct work_struct *work)
12821282
* this means there's a race between clearing the flag and setting the
12831283
* work pending bit and the work item being processed again */
12841284
if (call->events && !work_pending(&call->processor)) {
1285-
_debug("jumpstart %x", call->conn->cid);
1285+
_debug("jumpstart %x", call->conn->proto.cid);
12861286
rxrpc_queue_call(call);
12871287
}
12881288

0 commit comments

Comments
 (0)