Skip to content

Commit fe31a32

Browse files
Christoph Hellwigdavem330
authored andcommitted
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: Christoph Hellwig <hch@lst.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 26cfabf commit fe31a32

3 files changed

Lines changed: 10 additions & 16 deletions

File tree

‎include/net/sock.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,6 +2695,7 @@ void sock_set_keepalive(struct sock *sk);
26952695
void sock_set_priority(struct sock *sk, u32 priority);
26962696
void sock_set_rcvbuf(struct sock *sk, int val);
26972697
void sock_set_reuseaddr(struct sock *sk);
2698+
void sock_set_reuseport(struct sock *sk);
26982699
void sock_set_sndtimeo(struct sock *sk, s64 secs);
26992700

27002701
#endif /* _SOCK_H */

‎net/core/sock.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,14 @@ void sock_set_reuseaddr(struct sock *sk)
729729
}
730730
EXPORT_SYMBOL(sock_set_reuseaddr);
731731

732+
void sock_set_reuseport(struct sock *sk)
733+
{
734+
lock_sock(sk);
735+
sk->sk_reuseport = true;
736+
release_sock(sk);
737+
}
738+
EXPORT_SYMBOL(sock_set_reuseport);
739+
732740
void sock_no_linger(struct sock *sk)
733741
{
734742
lock_sock(sk);

‎net/sunrpc/xprtsock.c‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,21 +1594,6 @@ static int xs_get_random_port(void)
15941594
return rand + min;
15951595
}
15961596

1597-
/**
1598-
* xs_set_reuseaddr_port - set the socket's port and address reuse options
1599-
* @sock: socket
1600-
*
1601-
* Note that this function has to be called on all sockets that share the
1602-
* same port, and it must be called before binding.
1603-
*/
1604-
static void xs_sock_set_reuseport(struct socket *sock)
1605-
{
1606-
int opt = 1;
1607-
1608-
kernel_setsockopt(sock, SOL_SOCKET, SO_REUSEPORT,
1609-
(char *)&opt, sizeof(opt));
1610-
}
1611-
16121597
static unsigned short xs_sock_getport(struct socket *sock)
16131598
{
16141599
struct sockaddr_storage buf;
@@ -1801,7 +1786,7 @@ static struct socket *xs_create_sock(struct rpc_xprt *xprt,
18011786
xs_reclassify_socket(family, sock);
18021787

18031788
if (reuseport)
1804-
xs_sock_set_reuseport(sock);
1789+
sock_set_reuseport(sock->sk);
18051790

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

0 commit comments

Comments
 (0)