net/ipv4/tcp_input.c
Source file repositories/reference/linux-study-clean/net/ipv4/tcp_input.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/tcp_input.c- Extension
.c- Size
- 231676 bytes
- Lines
- 7776
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/mm.hlinux/slab.hlinux/module.hlinux/sysctl.hlinux/kernel.hlinux/prefetch.hlinux/bitops.hnet/dst.hnet/tcp.hnet/tcp_ecn.hnet/proto_memory.hnet/inet_common.hlinux/ipsec.hlinux/unaligned.hlinux/errqueue.htrace/events/tcp.hlinux/jump_label_ratelimit.hnet/busy_poll.hnet/mptcp.h
Detected Declarations
struct tcp_sacktag_statefunction clean_acked_data_enablefunction clean_acked_data_disablefunction clean_acked_data_flushfunction bpf_skops_parse_hdrfunction bpf_skops_establishedfunction bpf_skops_establishedfunction bpf_skops_parse_hdrfunction tcp_measure_rcv_mssfunction tcp_incr_quickackfunction tcp_enter_quickack_modefunction tcp_in_quickack_modefunction tcp_data_ecn_checkfunction tcp_accecn_process_optionfunction tcp_count_delivered_cefunction tcp_count_deliveredfunction __tcp_accecn_processfunction tcp_accecn_processfunction tcp_sndbuf_expandfunction tcp_full_spacefunction fragfunction tcp_grow_windowfunction tcp_init_buffer_spacefunction tcp_clamp_windowfunction tcp_measure_rcv_mssfunction tcp_rcv_rtt_updatefunction tcp_rcv_rtt_measurefunction tcp_rtt_tsopt_usfunction tcp_rcv_rtt_measure_tsfunction tcp_rcvbuf_growfunction tcp_rcv_space_adjustfunction tcp_save_lrcv_flowlabelfunction tcp_event_data_recvfunction tcp_rtt_estimatorfunction tcp_update_pacing_ratefunction tcp_set_rtofunction tcp_init_cwndfunction tcp_dsack_seenfunction tcp_check_sack_reorderingfunction tcp_verify_retransmit_hintfunction tcp_notify_skb_loss_eventfunction tcp_mark_skb_lostfunction triggerfunction tcp_check_dsackfunction hasslefunction tcp_rack_advancefunction tcp_sacktag_onefunction tcp_rate_gen
Annotated Snippet
struct tcp_sacktag_state {
/* Timestamps for earliest and latest never-retransmitted segment
* that was SACKed. RTO needs the earliest RTT to stay conservative,
* but congestion control should still get an accurate delay signal.
*/
u64 first_sackt;
u64 last_sackt;
u32 reord;
u32 sack_delivered;
u32 delivered_bytes;
int flag;
unsigned int mss_now;
struct rate_sample *rate;
};
/* Take a notice that peer is sending D-SACKs. Skip update of data delivery
* and spurious retransmission information if this DSACK is unlikely caused by
* sender's action:
* - DSACKed sequence range is larger than maximum receiver's window.
* - Total no. of DSACKed segments exceed the total no. of retransmitted segs.
*/
static u32 tcp_dsack_seen(struct tcp_sock *tp, u32 start_seq,
u32 end_seq, struct tcp_sacktag_state *state)
{
u32 seq_len, dup_segs = 1;
if (!before(start_seq, end_seq))
return 0;
seq_len = end_seq - start_seq;
/* Dubious DSACK: DSACKed range greater than maximum advertised rwnd */
if (seq_len > tp->max_window)
return 0;
if (seq_len > tp->mss_cache)
dup_segs = DIV_ROUND_UP(seq_len, tp->mss_cache);
else if (tp->tlp_high_seq && tp->tlp_high_seq == end_seq)
state->flag |= FLAG_DSACK_TLP;
WRITE_ONCE(tp->dsack_dups, tp->dsack_dups + dup_segs);
/* Skip the DSACK if dup segs weren't retransmitted by sender */
if (tp->dsack_dups > tp->total_retrans)
return 0;
tp->rx_opt.sack_ok |= TCP_DSACK_SEEN;
/* We increase the RACK ordering window in rounds where we receive
* DSACKs that may have been due to reordering causing RACK to trigger
* a spurious fast recovery. Thus RACK ignores DSACKs that happen
* without having seen reordering, or that match TLP probes (TLP
* is timer-driven, not triggered by RACK).
*/
if (tp->reord_seen && !(state->flag & FLAG_DSACK_TLP))
tp->rack.dsack_seen = 1;
state->flag |= FLAG_DSACKING_ACK;
/* A spurious retransmission is delivered */
state->sack_delivered += dup_segs;
return dup_segs;
}
/* It's reordering when higher sequence was delivered (i.e. sacked) before
* some lower never-retransmitted sequence ("low_seq"). The maximum reordering
* distance is approximated in full-mss packet distance ("reordering").
*/
static void tcp_check_sack_reordering(struct sock *sk, const u32 low_seq,
const int ts)
{
struct tcp_sock *tp = tcp_sk(sk);
const u32 mss = tp->mss_cache;
u32 fack, metric;
fack = tcp_highest_sack_seq(tp);
if (!before(low_seq, fack))
return;
metric = fack - low_seq;
if ((metric > tp->reordering * mss) && mss) {
#if FASTRETRANS_DEBUG > 1
pr_debug("Disorder%d %d %u f%u s%u rr%d\n",
tp->rx_opt.sack_ok, inet_csk(sk)->icsk_ca_state,
tp->reordering,
0,
tp->sacked_out,
tp->undo_marker ? tp->undo_retrans : 0);
#endif
WRITE_ONCE(tp->reordering,
min_t(u32, (metric + mss - 1) / mss,
READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_max_reordering)));
}
Annotation
- Immediate include surface: `linux/mm.h`, `linux/slab.h`, `linux/module.h`, `linux/sysctl.h`, `linux/kernel.h`, `linux/prefetch.h`, `linux/bitops.h`, `net/dst.h`.
- Detected declarations: `struct tcp_sacktag_state`, `function clean_acked_data_enable`, `function clean_acked_data_disable`, `function clean_acked_data_flush`, `function bpf_skops_parse_hdr`, `function bpf_skops_established`, `function bpf_skops_established`, `function bpf_skops_parse_hdr`, `function tcp_measure_rcv_mss`, `function tcp_incr_quickack`.
- 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.