Skip to content

Commit fa46349

Browse files
kraigatgoogdavem330
authored andcommitted
soreuseport: Prep for fast reuseport TCP socket selection
Both of the lines in this patch probably should have been included in the initial implementation of this code for generic socket support, but weren't technically necessary since only UDP sockets were supported. First, the sk_reuseport_cb points to a structure which assumes each socket in the group has this pointer assigned at the same time it's added to the array in the structure. The sk_clone_lock function breaks this assumption. Since a child socket shouldn't implicitly be in a reuseport group, the simple fix is to clear the field in the clone. Second, the SO_ATTACH_REUSEPORT_xBPF socket options require that SO_REUSEPORT also be set first. For UDP sockets, this is easily enforced at bind-time since that process both puts the socket in the appropriate receive hlist and updates the reuseport structures. Since these operations can happen at two different times for TCP sockets (bind and listen) it must be explicitly checked to enforce the use of SO_REUSEPORT with SO_ATTACH_REUSEPORT_xBPF in the setsockopt call. Signed-off-by: Craig Gallek <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a583636 commit fa46349

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

net/core/filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,7 @@ static int __reuseport_attach_prog(struct bpf_prog *prog, struct sock *sk)
11811181
if (bpf_prog_size(prog->len) > sysctl_optmem_max)
11821182
return -ENOMEM;
11831183

1184-
if (sk_unhashed(sk)) {
1184+
if (sk_unhashed(sk) && sk->sk_reuseport) {
11851185
err = reuseport_alloc(sk);
11861186
if (err)
11871187
return err;

net/core/sock.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,7 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
15311531
newsk = NULL;
15321532
goto out;
15331533
}
1534+
RCU_INIT_POINTER(newsk->sk_reuseport_cb, NULL);
15341535

15351536
newsk->sk_err = 0;
15361537
newsk->sk_priority = 0;

0 commit comments

Comments
 (0)