Skip to content

Commit 606f72c

Browse files
Neal Cardwellkernel-patches-bot
authored andcommitted
From: Neal Cardwell <ncardwell@google.com>
Simplify tcp_set_congestion_control() by removing the initialization code path for the !load case. There are only two call sites for tcp_set_congestion_control(). The EBPF call site is the only one that passes load=false; it also passes cap_net_admin=true. Because of that, the exact same behavior can be achieved by removing the special if (!load) branch of the logic. Both before and after this commit, the EBPF case will call bpf_try_module_get(), and if that succeeds then call tcp_reinit_congestion_control() or if that fails then return EBUSY. Note that this returns the logic to a structure very similar to the structure before: commit 91b5b21 ("bpf: Add support for changing congestion control") except that the CAP_NET_ADMIN status is passed in as a function argument. This clean-up was suggested by Martin KaFai Lau. Signed-off-by: Neal Cardwell <ncardwell@google.com> Suggested-by: Martin KaFai Lau <kafai@fb.com> Cc: Lawrence Brakmo <brakmo@fb.com> Cc: Eric Dumazet <edumazet@google.com> Cc: Yuchung Cheng <ycheng@google.com> Cc: Kevin Yang <yyd@google.com> --- net/ipv4/tcp_cong.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
1 parent 558a156 commit 606f72c

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

net/ipv4/tcp_cong.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -362,21 +362,14 @@ int tcp_set_congestion_control(struct sock *sk, const char *name, bool load,
362362
goto out;
363363
}
364364

365-
if (!ca) {
365+
if (!ca)
366366
err = -ENOENT;
367-
} else if (!load) {
368-
if (bpf_try_module_get(ca, ca->owner)) {
369-
tcp_reinit_congestion_control(sk, ca);
370-
} else {
371-
err = -EBUSY;
372-
}
373-
} else if (!((ca->flags & TCP_CONG_NON_RESTRICTED) || cap_net_admin)) {
367+
else if (!((ca->flags & TCP_CONG_NON_RESTRICTED) || cap_net_admin))
374368
err = -EPERM;
375-
} else if (!bpf_try_module_get(ca, ca->owner)) {
369+
else if (!bpf_try_module_get(ca, ca->owner))
376370
err = -EBUSY;
377-
} else {
371+
else
378372
tcp_reinit_congestion_control(sk, ca);
379-
}
380373
out:
381374
rcu_read_unlock();
382375
return err;

0 commit comments

Comments
 (0)