net/ipv4/tcp_ipv4.c
Source file repositories/reference/linux-study-clean/net/ipv4/tcp_ipv4.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/tcp_ipv4.c- Extension
.c- Size
- 99544 bytes
- Lines
- 3666
- 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/bottom_half.hlinux/types.hlinux/fcntl.hlinux/module.hlinux/random.hlinux/cache.hlinux/fips.hlinux/jhash.hlinux/init.hlinux/times.hlinux/slab.hlinux/sched.hlinux/sock_diag.hnet/aligned_data.hnet/net_namespace.hnet/icmp.hnet/inet_hashtables.hnet/tcp.hnet/tcp_ecn.hnet/transp_v6.hnet/ipv6.hnet/inet_common.hnet/inet_ecn.hnet/timewait_sock.hnet/xfrm.hnet/secure_seq.hnet/busy_poll.hnet/rstreason.hnet/psp.hlinux/inet.hlinux/ipv6.hlinux/stddef.h
Detected Declarations
struct bpf_tcp_iter_statestruct bpf_iter__tcpfunction tcp_v4_init_seq_and_ts_offfunction tcp_twsk_uniquefunction tcp_v4_pre_connectfunction tcp_v4_connectfunction tcp_release_cbfunction do_redirectfunction tcp_req_errfunction tcp_ld_RTO_revertfunction tcp_v4_errfunction discoveryfunction PORT_UNREACHfunction tcp_v4_ao_sign_resetfunction tcp_v4_send_resetfunction tcp_v4_send_ackfunction tcp_v4_timewait_ackfunction tcp_v4_reqsk_send_ackfunction tcp_rsk_used_aofunction tcp_v4_send_synackfunction tcp_v4_reqsk_destructorfunction better_md5_matchfunction hlist_for_each_entry_rcufunction lockdep_sock_is_heldfunction tcp_md5sig_info_addfunction __tcp_md5_do_addfunction tcp_md5_do_addfunction tcp_md5_key_copyfunction tcp_md5_do_delfunction tcp_clear_md5_listfunction hlist_for_each_entry_safefunction tcp_v4_parse_md5_keysfunction tcp_v4_md5_hash_headersfunction tcp_v4_md5_hash_hdrfunction tcp_v4_md5_hash_skbfunction tcp_v4_init_reqfunction tcp_v4_conn_requestfunction voidfunction tcp_v4_get_syncookiefunction tcp_v4_do_rcvfunction tcp_add_backlogfunction tcp_v4_restore_cbfunction tcp_v4_fill_cbfunction tcp_v4_rcvfunction inet_sk_rx_dst_setfunction tcp4_destruct_sockfunction sk_allocfunction tcp_release_user_frags
Annotated Snippet
struct bpf_tcp_iter_state {
struct tcp_iter_state state;
unsigned int cur_sk;
unsigned int end_sk;
unsigned int max_sk;
union bpf_tcp_iter_batch_item *batch;
};
struct bpf_iter__tcp {
__bpf_md_ptr(struct bpf_iter_meta *, meta);
__bpf_md_ptr(struct sock_common *, sk_common);
uid_t uid __aligned(8);
};
static int tcp_prog_seq_show(struct bpf_prog *prog, struct bpf_iter_meta *meta,
struct sock_common *sk_common, uid_t uid)
{
struct bpf_iter__tcp ctx;
meta->seq_num--; /* skip SEQ_START_TOKEN */
ctx.meta = meta;
ctx.sk_common = sk_common;
ctx.uid = uid;
return bpf_iter_run_prog(prog, &ctx);
}
static void bpf_iter_tcp_put_batch(struct bpf_tcp_iter_state *iter)
{
union bpf_tcp_iter_batch_item *item;
unsigned int cur_sk = iter->cur_sk;
__u64 cookie;
/* Remember the cookies of the sockets we haven't seen yet, so we can
* pick up where we left off next time around.
*/
while (cur_sk < iter->end_sk) {
item = &iter->batch[cur_sk++];
cookie = sock_gen_cookie(item->sk);
sock_gen_put(item->sk);
item->cookie = cookie;
}
}
static int bpf_iter_tcp_realloc_batch(struct bpf_tcp_iter_state *iter,
unsigned int new_batch_sz, gfp_t flags)
{
union bpf_tcp_iter_batch_item *new_batch;
new_batch = kvmalloc(sizeof(*new_batch) * new_batch_sz,
flags | __GFP_NOWARN);
if (!new_batch)
return -ENOMEM;
memcpy(new_batch, iter->batch, sizeof(*iter->batch) * iter->end_sk);
kvfree(iter->batch);
iter->batch = new_batch;
iter->max_sk = new_batch_sz;
return 0;
}
static struct sock *bpf_iter_tcp_resume_bucket(struct sock *first_sk,
union bpf_tcp_iter_batch_item *cookies,
int n_cookies)
{
struct hlist_nulls_node *node;
struct sock *sk;
int i;
for (i = 0; i < n_cookies; i++) {
sk = first_sk;
sk_nulls_for_each_from(sk, node)
if (cookies[i].cookie == atomic64_read(&sk->sk_cookie))
return sk;
}
return NULL;
}
static struct sock *bpf_iter_tcp_resume_listening(struct seq_file *seq)
{
struct inet_hashinfo *hinfo = seq_file_net(seq)->ipv4.tcp_death_row.hashinfo;
struct bpf_tcp_iter_state *iter = seq->private;
struct tcp_iter_state *st = &iter->state;
unsigned int find_cookie = iter->cur_sk;
unsigned int end_cookie = iter->end_sk;
int resume_bucket = st->bucket;
struct sock *sk;
if (end_cookie && find_cookie == end_cookie)
Annotation
- Immediate include surface: `linux/bottom_half.h`, `linux/types.h`, `linux/fcntl.h`, `linux/module.h`, `linux/random.h`, `linux/cache.h`, `linux/fips.h`, `linux/jhash.h`.
- Detected declarations: `struct bpf_tcp_iter_state`, `struct bpf_iter__tcp`, `function tcp_v4_init_seq_and_ts_off`, `function tcp_twsk_unique`, `function tcp_v4_pre_connect`, `function tcp_v4_connect`, `function tcp_release_cb`, `function do_redirect`, `function tcp_req_err`, `function tcp_ld_RTO_revert`.
- 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.