Skip to content

Commit 5050bef

Browse files
nealcardwellAlexei Starovoitov
authored andcommitted
tcp: Simplify tcp_set_congestion_control() load=false case
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. Suggested-by: Martin KaFai Lau <[email protected]> Signed-off-by: Neal Cardwell <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Cc: Lawrence Brakmo <[email protected]> Cc: Eric Dumazet <[email protected]> Cc: Yuchung Cheng <[email protected]> Cc: Kevin Yang <[email protected]>
1 parent 5cdc744 commit 5050bef

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)