net/ipv4/tcp_cong.c
Source file repositories/reference/linux-study-clean/net/ipv4/tcp_cong.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/tcp_cong.c- Extension
.c- Size
- 13677 bytes
- Lines
- 539
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/mm.hlinux/types.hlinux/list.hlinux/gfp.hlinux/jhash.hnet/tcp.hnet/tcp_ecn.htrace/events/tcp.h
Detected Declarations
function list_for_each_entry_rcufunction tcp_set_ca_statefunction list_for_each_entry_rcufunction tcp_validate_congestion_controlfunction tcp_register_congestion_controlfunction tcp_unregister_congestion_controlfunction tcp_update_congestion_controlfunction tcp_ca_get_key_by_namefunction tcp_assign_congestion_controlfunction tcp_init_congestion_controlfunction tcp_reinit_congestion_controlfunction tcp_cleanup_congestion_controlfunction tcp_set_default_congestion_controlfunction tcp_congestion_defaultfunction tcp_get_available_congestion_controlfunction tcp_get_default_congestion_controlfunction tcp_get_allowed_congestion_controlfunction tcp_set_allowed_congestion_controlfunction tcp_reinit_congestion_controlfunction tcp_slow_startfunction tcp_cong_avoid_aifunction tcp_reno_cong_avoidfunction tcp_reno_ssthreshfunction tcp_reno_undo_cwndexport tcp_register_congestion_controlexport tcp_unregister_congestion_controlexport tcp_slow_startexport tcp_cong_avoid_aiexport tcp_reno_cong_avoidexport tcp_reno_ssthreshexport tcp_reno_undo_cwnd
Annotated Snippet
if (!ca) {
ret = -ENOENT;
goto out;
}
}
/* pass 2 clear old values */
list_for_each_entry_rcu(ca, &tcp_cong_list, list)
ca->flags &= ~TCP_CONG_NON_RESTRICTED;
/* pass 3 mark as allowed */
while ((name = strsep(&val, " ")) && *name) {
ca = tcp_ca_find(name);
WARN_ON(!ca);
if (ca)
ca->flags |= TCP_CONG_NON_RESTRICTED;
}
out:
spin_unlock(&tcp_cong_list_lock);
kfree(saved_clone);
return ret;
}
/* Change congestion control for socket. If load is false, then it is the
* responsibility of the caller to call tcp_init_congestion_control or
* tcp_reinit_congestion_control (if the current congestion control was
* already initialized.
*/
int tcp_set_congestion_control(struct sock *sk, const char *name, bool load,
bool cap_net_admin)
{
struct inet_connection_sock *icsk = inet_csk(sk);
const struct tcp_congestion_ops *ca;
int err = 0;
if (icsk->icsk_ca_dst_locked)
return -EPERM;
rcu_read_lock();
if (!load)
ca = tcp_ca_find(name);
else
ca = tcp_ca_find_autoload(name);
/* No change asking for existing value */
if (ca == icsk->icsk_ca_ops) {
icsk->icsk_ca_setsockopt = 1;
goto out;
}
if (!ca)
err = -ENOENT;
else if (!((ca->flags & TCP_CONG_NON_RESTRICTED) || cap_net_admin))
err = -EPERM;
else if (!bpf_try_module_get(ca, ca->owner))
err = -EBUSY;
else
tcp_reinit_congestion_control(sk, ca);
out:
rcu_read_unlock();
return err;
}
/* Slow start is used when congestion window is no greater than the slow start
* threshold. We base on RFC2581 and also handle stretch ACKs properly.
* We do not implement RFC3465 Appropriate Byte Counting (ABC) per se but
* something better;) a packet is only considered (s)acked in its entirety to
* defend the ACK attacks described in the RFC. Slow start processes a stretch
* ACK of degree N as if N acks of degree 1 are received back to back except
* ABC caps N to 2. Slow start exits when cwnd grows over ssthresh and
* returns the leftover acks to adjust cwnd in congestion avoidance mode.
*/
__bpf_kfunc u32 tcp_slow_start(struct tcp_sock *tp, u32 acked)
{
u32 cwnd = min(tcp_snd_cwnd(tp) + acked, tp->snd_ssthresh);
acked -= cwnd - tcp_snd_cwnd(tp);
tcp_snd_cwnd_set(tp, min(cwnd, tp->snd_cwnd_clamp));
return acked;
}
EXPORT_SYMBOL_GPL(tcp_slow_start);
/* In theory this is tp->snd_cwnd += 1 / tp->snd_cwnd (or alternative w),
* for every packet that was ACKed.
*/
__bpf_kfunc void tcp_cong_avoid_ai(struct tcp_sock *tp, u32 w, u32 acked)
{
/* If credits accumulated at a higher w, apply them gently now. */
Annotation
- Immediate include surface: `linux/module.h`, `linux/mm.h`, `linux/types.h`, `linux/list.h`, `linux/gfp.h`, `linux/jhash.h`, `net/tcp.h`, `net/tcp_ecn.h`.
- Detected declarations: `function list_for_each_entry_rcu`, `function tcp_set_ca_state`, `function list_for_each_entry_rcu`, `function tcp_validate_congestion_control`, `function tcp_register_congestion_control`, `function tcp_unregister_congestion_control`, `function tcp_update_congestion_control`, `function tcp_ca_get_key_by_name`, `function tcp_assign_congestion_control`, `function tcp_init_congestion_control`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.