Commit fe31a326 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David S. Miller
Browse files

net: add sock_set_reuseport



Add a helper to directly set the SO_REUSEPORT sockopt from kernel space
without going through a fake uaccess.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 26cfabf9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2695,6 +2695,7 @@ void sock_set_keepalive(struct sock *sk);
void sock_set_priority(struct sock *sk, u32 priority);
void sock_set_rcvbuf(struct sock *sk, int val);
void sock_set_reuseaddr(struct sock *sk);
void sock_set_reuseport(struct sock *sk);
void sock_set_sndtimeo(struct sock *sk, s64 secs);

#endif	/* _SOCK_H */
+8 −0
Original line number Diff line number Diff line
@@ -729,6 +729,14 @@ void sock_set_reuseaddr(struct sock *sk)
}
EXPORT_SYMBOL(sock_set_reuseaddr);

void sock_set_reuseport(struct sock *sk)
{
	lock_sock(sk);
	sk->sk_reuseport = true;
	release_sock(sk);
}
EXPORT_SYMBOL(sock_set_reuseport);

void sock_no_linger(struct sock *sk)
{
	lock_sock(sk);
+1 −16
Original line number Diff line number Diff line
@@ -1594,21 +1594,6 @@ static int xs_get_random_port(void)
	return rand + min;
}

/**
 * xs_set_reuseaddr_port - set the socket's port and address reuse options
 * @sock: socket
 *
 * Note that this function has to be called on all sockets that share the
 * same port, and it must be called before binding.
 */
static void xs_sock_set_reuseport(struct socket *sock)
{
	int opt = 1;

	kernel_setsockopt(sock, SOL_SOCKET, SO_REUSEPORT,
			(char *)&opt, sizeof(opt));
}

static unsigned short xs_sock_getport(struct socket *sock)
{
	struct sockaddr_storage buf;
@@ -1801,7 +1786,7 @@ static struct socket *xs_create_sock(struct rpc_xprt *xprt,
	xs_reclassify_socket(family, sock);

	if (reuseport)
		xs_sock_set_reuseport(sock);
		sock_set_reuseport(sock->sk);

	err = xs_bind(transport, sock);
	if (err) {