提交 28036f44 编写于 作者: D David Howells

rxrpc: Permit multiple service binding

Permit bind() to be called on an AF_RXRPC socket more than once (currently
maximum twice) to bind multiple listening services to it.  There are some
restrictions:

 (1) All bind() calls involved must have a non-zero service ID.

 (2) The service IDs must all be different.

 (3) The rest of the address (notably the transport part) must be the same
     in all (a single UDP socket is shared).

 (4) This must be done before listen() or sendmsg() is called.

This allows someone to connect to the service socket with different service
IDs and lays the foundation for service upgrading.

The service ID used by an incoming call can be extracted from the msg_name
returned by recvmsg().
Signed-off-by: NDavid Howells <dhowells@redhat.com>
上级 68d6d1ae
...@@ -600,6 +600,10 @@ A server would be set up to accept operations in the following manner: ...@@ -600,6 +600,10 @@ A server would be set up to accept operations in the following manner:
}; };
bind(server, &srx, sizeof(srx)); bind(server, &srx, sizeof(srx));
More than one service ID may be bound to a socket, provided the transport
parameters are the same. The limit is currently two. To do this, bind()
should be called twice.
(3) The server is then set to listen out for incoming calls: (3) The server is then set to listen out for incoming calls:
listen(server, 100); listen(server, 100);
......
...@@ -144,31 +144,48 @@ static int rxrpc_bind(struct socket *sock, struct sockaddr *saddr, int len) ...@@ -144,31 +144,48 @@ static int rxrpc_bind(struct socket *sock, struct sockaddr *saddr, int len)
lock_sock(&rx->sk); lock_sock(&rx->sk);
if (rx->sk.sk_state != RXRPC_UNBOUND) { switch (rx->sk.sk_state) {
ret = -EINVAL; case RXRPC_UNBOUND:
goto error_unlock; rx->srx = *srx;
} local = rxrpc_lookup_local(sock_net(&rx->sk), &rx->srx);
if (IS_ERR(local)) {
memcpy(&rx->srx, srx, sizeof(rx->srx)); ret = PTR_ERR(local);
goto error_unlock;
}
local = rxrpc_lookup_local(sock_net(&rx->sk), &rx->srx); if (service_id) {
if (IS_ERR(local)) { write_lock(&local->services_lock);
ret = PTR_ERR(local); if (rcu_access_pointer(local->service))
goto error_unlock; goto service_in_use;
} rx->local = local;
rcu_assign_pointer(local->service, rx);
write_unlock(&local->services_lock);
rx->sk.sk_state = RXRPC_SERVER_BOUND;
} else {
rx->local = local;
rx->sk.sk_state = RXRPC_CLIENT_BOUND;
}
break;
if (service_id) { case RXRPC_SERVER_BOUND:
write_lock(&local->services_lock); ret = -EINVAL;
if (rcu_access_pointer(local->service)) if (service_id == 0)
goto service_in_use; goto error_unlock;
rx->local = local; ret = -EADDRINUSE;
rcu_assign_pointer(local->service, rx); if (service_id == rx->srx.srx_service)
write_unlock(&local->services_lock); goto error_unlock;
ret = -EINVAL;
srx->srx_service = rx->srx.srx_service;
if (memcmp(srx, &rx->srx, sizeof(*srx)) != 0)
goto error_unlock;
rx->second_service = service_id;
rx->sk.sk_state = RXRPC_SERVER_BOUND2;
break;
rx->sk.sk_state = RXRPC_SERVER_BOUND; default:
} else { ret = -EINVAL;
rx->local = local; goto error_unlock;
rx->sk.sk_state = RXRPC_CLIENT_BOUND;
} }
release_sock(&rx->sk); release_sock(&rx->sk);
...@@ -205,6 +222,7 @@ static int rxrpc_listen(struct socket *sock, int backlog) ...@@ -205,6 +222,7 @@ static int rxrpc_listen(struct socket *sock, int backlog)
ret = -EADDRNOTAVAIL; ret = -EADDRNOTAVAIL;
break; break;
case RXRPC_SERVER_BOUND: case RXRPC_SERVER_BOUND:
case RXRPC_SERVER_BOUND2:
ASSERT(rx->local != NULL); ASSERT(rx->local != NULL);
max = READ_ONCE(rxrpc_max_backlog); max = READ_ONCE(rxrpc_max_backlog);
ret = -EINVAL; ret = -EINVAL;
......
...@@ -61,6 +61,7 @@ enum { ...@@ -61,6 +61,7 @@ enum {
RXRPC_CLIENT_UNBOUND, /* Unbound socket used as client */ RXRPC_CLIENT_UNBOUND, /* Unbound socket used as client */
RXRPC_CLIENT_BOUND, /* client local address bound */ RXRPC_CLIENT_BOUND, /* client local address bound */
RXRPC_SERVER_BOUND, /* server local address bound */ RXRPC_SERVER_BOUND, /* server local address bound */
RXRPC_SERVER_BOUND2, /* second server local address bound */
RXRPC_SERVER_LISTENING, /* server listening for connections */ RXRPC_SERVER_LISTENING, /* server listening for connections */
RXRPC_SERVER_LISTEN_DISABLED, /* server listening disabled */ RXRPC_SERVER_LISTEN_DISABLED, /* server listening disabled */
RXRPC_CLOSE, /* socket is being closed */ RXRPC_CLOSE, /* socket is being closed */
...@@ -142,6 +143,7 @@ struct rxrpc_sock { ...@@ -142,6 +143,7 @@ struct rxrpc_sock {
u32 min_sec_level; /* minimum security level */ u32 min_sec_level; /* minimum security level */
#define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT #define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT
bool exclusive; /* Exclusive connection for a client socket */ bool exclusive; /* Exclusive connection for a client socket */
u16 second_service; /* Additional service bound to the endpoint */
sa_family_t family; /* Protocol family created with */ sa_family_t family; /* Protocol family created with */
struct sockaddr_rxrpc srx; /* local address */ struct sockaddr_rxrpc srx; /* local address */
struct sockaddr_rxrpc connect_srx; /* Default client address from connect() */ struct sockaddr_rxrpc connect_srx; /* Default client address from connect() */
......
...@@ -341,7 +341,8 @@ struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *local, ...@@ -341,7 +341,8 @@ struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *local,
/* Get the socket providing the service */ /* Get the socket providing the service */
rx = rcu_dereference(local->service); rx = rcu_dereference(local->service);
if (rx && service_id == rx->srx.srx_service) if (rx && (service_id == rx->srx.srx_service ||
service_id == rx->second_service))
goto found_service; goto found_service;
trace_rxrpc_abort("INV", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq, trace_rxrpc_abort("INV", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq,
......
...@@ -94,6 +94,7 @@ static struct rxrpc_local *rxrpc_alloc_local(struct rxrpc_net *rxnet, ...@@ -94,6 +94,7 @@ static struct rxrpc_local *rxrpc_alloc_local(struct rxrpc_net *rxnet,
rwlock_init(&local->services_lock); rwlock_init(&local->services_lock);
local->debug_id = atomic_inc_return(&rxrpc_debug_id); local->debug_id = atomic_inc_return(&rxrpc_debug_id);
memcpy(&local->srx, srx, sizeof(*srx)); memcpy(&local->srx, srx, sizeof(*srx));
local->srx.srx_service = 0;
} }
_leave(" = %p", local); _leave(" = %p", local);
......
...@@ -133,7 +133,8 @@ int rxrpc_init_server_conn_security(struct rxrpc_connection *conn) ...@@ -133,7 +133,8 @@ int rxrpc_init_server_conn_security(struct rxrpc_connection *conn)
read_lock(&local->services_lock); read_lock(&local->services_lock);
rx = rcu_dereference_protected(local->service, rx = rcu_dereference_protected(local->service,
lockdep_is_held(&local->services_lock)); lockdep_is_held(&local->services_lock));
if (rx && rx->srx.srx_service == conn->service_id) if (rx && (rx->srx.srx_service == conn->service_id ||
rx->second_service == conn->service_id))
goto found_service; goto found_service;
/* the service appears to have died */ /* the service appears to have died */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册