include/net/inet_hashtables.h
Source file repositories/reference/linux-study-clean/include/net/inet_hashtables.h
File Facts
- System
- Linux kernel
- Corpus path
include/net/inet_hashtables.h- Extension
.h- Size
- 16767 bytes
- Lines
- 536
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/interrupt.hlinux/ip.hlinux/ipv6.hlinux/list.hlinux/slab.hlinux/socket.hlinux/spinlock.hlinux/types.hlinux/wait.hnet/inet_connection_sock.hnet/inet_sock.hnet/ip.hnet/sock.hnet/route.hnet/tcp_states.hnet/netns/hash.hlinux/refcount.hasm/byteorder.h
Detected Declarations
struct inet_ehash_bucketstruct inet_bind_bucketstruct inet_bind2_bucketstruct inet_bind_hashbucketstruct inet_listen_hashbucketstruct inet_hashinfostruct inet_sockfunction inet_lhash2_bucketfunction inet_ehash_locks_freefunction inet_bhashfnfunction inet_bhashfn_portaddrfunction inet_use_hash2_on_bindfunction inet_matchfunction sk_daddr_setfunction sk_rcv_saddr_set
Annotated Snippet
struct inet_ehash_bucket {
struct hlist_nulls_head chain;
};
/* There are a few simple rules, which allow for local port reuse by
* an application. In essence:
*
* 1) Sockets bound to different interfaces may share a local port.
* Failing that, goto test 2.
* 2) If all sockets have sk->sk_reuse set, and none of them are in
* TCP_LISTEN state, the port may be shared.
* Failing that, goto test 3.
* 3) If all sockets are bound to a specific inet_sk(sk)->rcv_saddr local
* address, and none of them are the same, the port may be
* shared.
* Failing this, the port cannot be shared.
*
* The interesting point, is test #2. This is what an FTP server does
* all day. To optimize this case we use a specific flag bit defined
* below. As we add sockets to a bind bucket list, we perform a
* check of: (newsk->sk_reuse && (newsk->sk_state != TCP_LISTEN))
* As long as all sockets added to a bind bucket pass this test,
* the flag bit will be set.
* The resulting situation is that tcp_v[46]_verify_bind() can just check
* for this flag bit, if it is set and the socket trying to bind has
* sk->sk_reuse set, we don't even have to walk the owners list at all,
* we return that it is ok to bind this socket to the requested local port.
*
* Sounds like a lot of work, but it is worth it. In a more naive
* implementation (ie. current FreeBSD etc.) the entire list of ports
* must be walked for each data port opened by an ftp server. Needless
* to say, this does not scale at all. With a couple thousand FTP
* users logged onto your box, isn't it nice to know that new data
* ports are created in O(1) time? I thought so. ;-) -DaveM
*/
#define FASTREUSEPORT_ANY 1
#define FASTREUSEPORT_STRICT 2
struct inet_bind_bucket {
possible_net_t ib_net;
int l3mdev;
unsigned short port;
signed char fastreuse;
signed char fastreuseport;
kuid_t fastuid;
#if IS_ENABLED(CONFIG_IPV6)
struct in6_addr fast_v6_rcv_saddr;
#endif
__be32 fast_rcv_saddr;
unsigned short fast_sk_family;
bool fast_ipv6_only;
struct hlist_node node;
struct hlist_head bhash2;
struct rcu_head rcu;
};
struct inet_bind2_bucket {
possible_net_t ib_net;
int l3mdev;
unsigned short port;
#if IS_ENABLED(CONFIG_IPV6)
unsigned short addr_type;
struct in6_addr v6_rcv_saddr;
#define rcv_saddr v6_rcv_saddr.s6_addr32[3]
#else
__be32 rcv_saddr;
#endif
/* Node in the bhash2 inet_bind_hashbucket chain */
struct hlist_node node;
struct hlist_node bhash_node;
/* List of sockets hashed to this bucket */
struct hlist_head owners;
signed char fastreuse;
signed char fastreuseport;
};
static inline struct net *ib_net(const struct inet_bind_bucket *ib)
{
return read_pnet(&ib->ib_net);
}
static inline struct net *ib2_net(const struct inet_bind2_bucket *ib)
{
return read_pnet(&ib->ib_net);
}
#define inet_bind_bucket_for_each(tb, head) \
hlist_for_each_entry(tb, head, node)
struct inet_bind_hashbucket {
Annotation
- Immediate include surface: `linux/interrupt.h`, `linux/ip.h`, `linux/ipv6.h`, `linux/list.h`, `linux/slab.h`, `linux/socket.h`, `linux/spinlock.h`, `linux/types.h`.
- Detected declarations: `struct inet_ehash_bucket`, `struct inet_bind_bucket`, `struct inet_bind2_bucket`, `struct inet_bind_hashbucket`, `struct inet_listen_hashbucket`, `struct inet_hashinfo`, `struct inet_sock`, `function inet_lhash2_bucket`, `function inet_ehash_locks_free`, `function inet_bhashfn`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
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.