Skip to content

Commit 210f035

Browse files
committed
rxrpc: Allow listen(sock, 0) to be used to disable listening
Allow listen() with a backlog of 0 to be used to disable listening on an AF_RXRPC socket. This also releases any preallocation, thereby making it easier for a kernel service to account for all allocated call structures when shutting down the service. The socket cannot thereafter have listening reenabled, but must rather be closed and reopened. Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 56ff9c8 commit 210f035

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

net/rxrpc/af_rxrpc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,14 @@ static int rxrpc_listen(struct socket *sock, int backlog)
224224
else
225225
sk->sk_max_ack_backlog = old;
226226
break;
227+
case RXRPC_SERVER_LISTENING:
228+
if (backlog == 0) {
229+
rx->sk.sk_state = RXRPC_SERVER_LISTEN_DISABLED;
230+
sk->sk_max_ack_backlog = 0;
231+
rxrpc_discard_prealloc(rx);
232+
ret = 0;
233+
break;
234+
}
227235
default:
228236
ret = -EBUSY;
229237
break;

net/rxrpc/ar-internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ enum {
6060
RXRPC_CLIENT_BOUND, /* client local address bound */
6161
RXRPC_SERVER_BOUND, /* server local address bound */
6262
RXRPC_SERVER_LISTENING, /* server listening for connections */
63+
RXRPC_SERVER_LISTEN_DISABLED, /* server listening disabled */
6364
RXRPC_CLOSE, /* socket is being closed */
6465
};
6566

net/rxrpc/call_accept.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *local,
349349

350350
found_service:
351351
spin_lock(&rx->incoming_lock);
352-
if (rx->sk.sk_state == RXRPC_CLOSE) {
352+
if (rx->sk.sk_state == RXRPC_SERVER_LISTEN_DISABLED ||
353+
rx->sk.sk_state == RXRPC_CLOSE) {
353354
trace_rxrpc_abort("CLS", sp->hdr.cid, sp->hdr.callNumber,
354355
sp->hdr.seq, RX_INVALID_OPERATION, ESHUTDOWN);
355356
skb->mark = RXRPC_SKB_MARK_LOCAL_ABORT;

0 commit comments

Comments
 (0)