net/ipv4/tcp.c
Source file repositories/reference/linux-study-clean/net/ipv4/tcp.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/tcp.c- Extension
.c- Size
- 149832 bytes
- Lines
- 5383
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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
crypto/md5.hcrypto/utils.hlinux/kernel.hlinux/module.hlinux/types.hlinux/fcntl.hlinux/poll.hlinux/inet_diag.hlinux/init.hlinux/fs.hlinux/skbuff.hlinux/splice.hlinux/net.hlinux/socket.hlinux/random.hlinux/memblock.hlinux/highmem.hlinux/cache.hlinux/err.hlinux/time.hlinux/slab.hlinux/errqueue.hlinux/static_key.hlinux/btf.hnet/icmp.hnet/inet_common.hnet/inet_ecn.hnet/tcp.hnet/tcp_ecn.hnet/mptcp.hnet/proto_memory.hnet/xfrm.h
Detected Declarations
struct tcp_xa_poolfunction tcp_enter_memory_pressurefunction tcp_leave_memory_pressurefunction secs_to_retransfunction retrans_to_secsfunction tcp_compute_delivery_ratefunction tcp_md5_destruct_sockfunction sk_allocfunction tcp_tx_timestampfunction sock_def_write_spacefunction tcp_stream_is_readablefunction racesfunction inet_test_bitfunction tcp_ioctlfunction tcp_mark_pushfunction forced_pushfunction tcp_skb_entailfunction tcp_mark_urgfunction sendmsgfunction tcp_pushfunction tcp_splice_data_recvfunction __tcp_splice_readfunction tcp_splice_readfunction andfunction tcp_xmit_size_goalfunction tcp_send_mssfunction epollfunction tcp_downgrade_zcopy_purefunction tcp_wmem_schedulefunction tcp_free_fastopen_reqfunction tcp_sendmsg_fastopenfunction tcp_rate_check_app_limitedfunction tcp_sendmsg_lockedfunction tcp_sendmsgfunction tcp_splice_eoffunction tcp_recv_urgfunction tcp_peek_sndqfunction skb_rbtree_walkfunction skb_queue_walkfunction __tcp_cleanup_rbuffunction tcp_cleanup_rbuffunction tcp_eat_recv_skbfunction tcp_recvmsgfunction tcp_read_sockfunction tcp_read_sock_noackfunction tcp_read_skbfunction tcp_read_donefunction tcp_peek_len
Annotated Snippet
struct tcp_xa_pool {
u8 max; /* max <= MAX_SKB_FRAGS */
u8 idx; /* idx <= max */
__u32 tokens[MAX_SKB_FRAGS];
netmem_ref netmems[MAX_SKB_FRAGS];
};
static void tcp_xa_pool_commit_locked(struct sock *sk, struct tcp_xa_pool *p)
{
int i;
/* Commit part that has been copied to user space. */
for (i = 0; i < p->idx; i++)
__xa_cmpxchg(&sk->sk_user_frags, p->tokens[i], XA_ZERO_ENTRY,
(__force void *)p->netmems[i], GFP_KERNEL);
/* Rollback what has been pre-allocated and is no longer needed. */
for (; i < p->max; i++)
__xa_erase(&sk->sk_user_frags, p->tokens[i]);
p->max = 0;
p->idx = 0;
}
static void tcp_xa_pool_commit(struct sock *sk, struct tcp_xa_pool *p)
{
if (!p->max)
return;
xa_lock_bh(&sk->sk_user_frags);
tcp_xa_pool_commit_locked(sk, p);
xa_unlock_bh(&sk->sk_user_frags);
}
static int tcp_xa_pool_refill(struct sock *sk, struct tcp_xa_pool *p,
unsigned int max_frags)
{
int err, k;
if (p->idx < p->max)
return 0;
xa_lock_bh(&sk->sk_user_frags);
tcp_xa_pool_commit_locked(sk, p);
for (k = 0; k < max_frags; k++) {
err = __xa_alloc(&sk->sk_user_frags, &p->tokens[k],
XA_ZERO_ENTRY, xa_limit_31b, GFP_KERNEL);
if (err)
break;
}
xa_unlock_bh(&sk->sk_user_frags);
p->max = k;
p->idx = 0;
return k ? 0 : err;
}
/* On error, returns the -errno. On success, returns number of bytes sent to the
* user. May not consume all of @remaining_len.
*/
static int tcp_recvmsg_dmabuf(struct sock *sk, const struct sk_buff *skb,
unsigned int offset, struct msghdr *msg,
int remaining_len)
{
struct dmabuf_cmsg dmabuf_cmsg = { 0 };
struct tcp_xa_pool tcp_xa_pool;
unsigned int start;
int i, copy, n;
int sent = 0;
int err = 0;
tcp_xa_pool.max = 0;
tcp_xa_pool.idx = 0;
do {
start = skb_headlen(skb);
if (skb_frags_readable(skb)) {
err = -ENODEV;
goto out;
}
/* Copy header. */
copy = start - offset;
if (copy > 0) {
copy = min(copy, remaining_len);
Annotation
- Immediate include surface: `crypto/md5.h`, `crypto/utils.h`, `linux/kernel.h`, `linux/module.h`, `linux/types.h`, `linux/fcntl.h`, `linux/poll.h`, `linux/inet_diag.h`.
- Detected declarations: `struct tcp_xa_pool`, `function tcp_enter_memory_pressure`, `function tcp_leave_memory_pressure`, `function secs_to_retrans`, `function retrans_to_secs`, `function tcp_compute_delivery_rate`, `function tcp_md5_destruct_sock`, `function sk_alloc`, `function tcp_tx_timestamp`, `function sock_def_write_space`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.