net/ipv4/inet_hashtables.c
Source file repositories/reference/linux-study-clean/net/ipv4/inet_hashtables.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/inet_hashtables.c- Extension
.c- Size
- 36884 bytes
- Lines
- 1392
- 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/module.hlinux/random.hlinux/sched.hlinux/slab.hlinux/wait.hlinux/vmalloc.hlinux/memblock.hlinux/gcd.hnet/addrconf.hnet/inet_connection_sock.hnet/inet_hashtables.hnet/inet6_hashtables.hnet/hotdata.hnet/ip.hnet/rps.hnet/secure_seq.hnet/sock_reuseport.hnet/tcp.h
Detected Declarations
function inet_init_ehash_secretfunction inet_ehashfnfunction sk_ehashfnfunction sk_is_connect_bindfunction inet_bind_bucket_destroyfunction inet_bind_bucket_matchfunction inet_bind2_bucket_initfunction inet_bind2_bucket_destroyfunction inet_bind2_bucket_addr_matchfunction inet_bind_hashfunction __inet_put_portfunction inet_put_portfunction __inet_inherit_portfunction inet_bind_bucket_for_eachfunction inet_lhash2_bucket_skfunction compute_scorefunction inet_lookup_reuseportfunction sk_nulls_for_each_rcufunction sock_gen_putfunction sock_edemuxfunction __inet_check_establishedfunction sk_nulls_for_eachfunction inet_sk_port_offsetfunction inet_ehash_lookup_by_skfunction sk_nulls_for_each_rcufunction inet_ehash_insertfunction inet_ehash_nolistenfunction inet_reuseport_add_sockfunction sk_nulls_for_each_rcufunction inet_hashfunction inet_unhashfunction inet_bind2_bucket_matchfunction inet_bind2_bucket_match_addr_anyfunction inet_bind2_bucket_findfunction inet_bhash2_addr_any_hashbucketfunction inet_update_saddrfunction __inet_bhash2_update_saddrfunction inet_bhash2_update_saddrfunction inet_bhash2_reset_saddrfunction __inet_hash_connectfunction hlist_for_each_entry_rcufunction inet_bind_bucket_for_eachfunction inet_hash_connectfunction inet_hashinfo2_initfunction inet_ehash_locks_allocfunction inet_pernet_hashinfo_freeexport inet_ehashfnexport inet_lookup_reuseport
Annotated Snippet
inet_bind_bucket_for_each(tb, &head->chain) {
if (inet_bind_bucket_match(tb, net, port, l3mdev))
break;
}
if (!tb) {
tb = inet_bind_bucket_create(table->bind_bucket_cachep,
net, head, port, l3mdev);
if (!tb) {
spin_unlock(&head2->lock);
spin_unlock(&head->lock);
return -ENOMEM;
}
created_inet_bind_bucket = true;
}
update_fastreuse = true;
goto bhash2_find;
} else if (!inet_bind2_bucket_addr_match(tb2, child)) {
l3mdev = inet_sk_bound_l3mdev(sk);
bhash2_find:
tb2 = inet_bind2_bucket_find(head2, net, port, l3mdev, child);
if (!tb2) {
tb2 = inet_bind2_bucket_create(table->bind2_bucket_cachep,
net, head2, tb, child);
if (!tb2)
goto error;
}
}
if (update_fastreuse)
inet_csk_update_fastreuse(child, tb, tb2);
inet_bind_hash(child, tb, tb2, port);
spin_unlock(&head2->lock);
spin_unlock(&head->lock);
return 0;
error:
if (created_inet_bind_bucket)
inet_bind_bucket_destroy(tb);
spin_unlock(&head2->lock);
spin_unlock(&head->lock);
return -ENOMEM;
}
static struct inet_listen_hashbucket *
inet_lhash2_bucket_sk(struct inet_hashinfo *h, struct sock *sk)
{
u32 hash;
#if IS_ENABLED(CONFIG_IPV6)
if (sk->sk_family == AF_INET6)
hash = ipv6_portaddr_hash(sock_net(sk),
&sk->sk_v6_rcv_saddr,
inet_sk(sk)->inet_num);
else
#endif
hash = ipv4_portaddr_hash(sock_net(sk),
inet_sk(sk)->inet_rcv_saddr,
inet_sk(sk)->inet_num);
return inet_lhash2_bucket(h, hash);
}
static inline int compute_score(struct sock *sk, const struct net *net,
const unsigned short hnum, const __be32 daddr,
const int dif, const int sdif)
{
int score = -1;
if (net_eq(sock_net(sk), net) && READ_ONCE(sk->sk_num) == hnum &&
!ipv6_only_sock(sk)) {
if (sk->sk_rcv_saddr != daddr)
return -1;
if (!inet_sk_bound_dev_eq(net, sk->sk_bound_dev_if, dif, sdif))
return -1;
score = sk->sk_bound_dev_if ? 2 : 1;
if (sk->sk_family == PF_INET)
score++;
if (READ_ONCE(sk->sk_incoming_cpu) == raw_smp_processor_id())
score++;
}
return score;
}
/**
* inet_lookup_reuseport() - execute reuseport logic on AF_INET socket if necessary.
* @net: network namespace.
* @sk: AF_INET socket, must be in TCP_LISTEN state for TCP or TCP_CLOSE for UDP.
Annotation
- Immediate include surface: `linux/module.h`, `linux/random.h`, `linux/sched.h`, `linux/slab.h`, `linux/wait.h`, `linux/vmalloc.h`, `linux/memblock.h`, `linux/gcd.h`.
- Detected declarations: `function inet_init_ehash_secret`, `function inet_ehashfn`, `function sk_ehashfn`, `function sk_is_connect_bind`, `function inet_bind_bucket_destroy`, `function inet_bind_bucket_match`, `function inet_bind2_bucket_init`, `function inet_bind2_bucket_destroy`, `function inet_bind2_bucket_addr_match`, `function inet_bind_hash`.
- 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.