net/netfilter/ipset/ip_set_hash_gen.h
Source file repositories/reference/linux-study-clean/net/netfilter/ipset/ip_set_hash_gen.h
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/ipset/ip_set_hash_gen.h- Extension
.h- Size
- 45124 bytes
- Lines
- 1662
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/rcupdate.hlinux/rcupdate_wait.hlinux/jhash.hlinux/types.hlinux/netfilter/nfnetlink.hlinux/netfilter/ipset/ip_set.h
Detected Declarations
struct hbucketstruct htable_gcstruct htablestruct net_prefixesstruct htypestruct mtype_resize_adfunction htable_sizefunction mtype_add_cidrfunction mtype_del_cidrfunction mtype_ahash_memsizefunction mtype_ext_cleanupfunction mtype_flushfunction mtype_ahash_destroyfunction mtype_destroyfunction mtype_same_setfunction mtype_gc_dofunction mtype_gcfunction mtype_gc_initfunction mtype_cancel_gcfunction mtype_resizefunction mtype_ext_sizefunction mtype_addfunction mtype_delfunction mtype_data_matchfunction mtype_test_cidrsfunction mtype_testfunction mtype_headfunction mtype_ureffunction mtype_listfunction IPSET_TOKEN
Annotated Snippet
struct hbucket {
struct rcu_head rcu; /* for call_rcu */
/* Which positions are used in the array */
DECLARE_BITMAP(used, AHASH_MAX_TUNED);
u8 size; /* size of the array */
u8 pos; /* position of the first free entry */
unsigned char value[] /* the array of the values */
__aligned(__alignof__(u64));
};
/* Region size for locking == 2^HTABLE_REGION_BITS */
#define HTABLE_REGION_BITS 10
#define ahash_numof_locks(htable_bits) \
((htable_bits) < HTABLE_REGION_BITS ? 1 \
: jhash_size((htable_bits) - HTABLE_REGION_BITS))
#define ahash_sizeof_regions(htable_bits) \
(ahash_numof_locks(htable_bits) * sizeof(struct ip_set_region))
#define ahash_region(n) \
((n) / jhash_size(HTABLE_REGION_BITS))
#define ahash_bucket_start(h, htable_bits) \
((htable_bits) < HTABLE_REGION_BITS ? 0 \
: (h) * jhash_size(HTABLE_REGION_BITS))
#define ahash_bucket_end(h, htable_bits) \
((htable_bits) < HTABLE_REGION_BITS ? jhash_size(htable_bits) \
: ((h) + 1) * jhash_size(HTABLE_REGION_BITS))
struct htable_gc {
struct delayed_work dwork;
struct ip_set *set; /* Set the gc belongs to */
u32 region; /* Last gc run position */
};
/* The hash table: the table size stored here in order to make resizing easy */
struct htable {
atomic_t ref; /* References for resizing */
atomic_t uref; /* References for dumping and gc */
u8 htable_bits; /* size of hash table == 2^htable_bits */
u32 maxelem; /* Maxelem per region */
struct ip_set_region *hregion; /* Region locks and ext sizes */
struct hbucket __rcu *bucket[]; /* hashtable buckets */
};
#define hbucket(h, i) ((h)->bucket[i])
#define ext_size(n, dsize) \
(sizeof(struct hbucket) + (n) * (dsize))
#ifndef IPSET_NET_COUNT
#define IPSET_NET_COUNT 1
#endif
/* Book-keeping of the prefixes added to the set */
struct net_prefixes {
u32 nets[IPSET_NET_COUNT]; /* number of elements for this cidr */
u8 cidr[IPSET_NET_COUNT]; /* the cidr value */
};
/* Compute the hash table size */
static size_t
htable_size(u8 hbits)
{
size_t hsize;
/* We must fit both into u32 in jhash and INT_MAX in kvmalloc_node() */
if (hbits > 31)
return 0;
hsize = jhash_size(hbits);
if ((INT_MAX - sizeof(struct htable)) / sizeof(struct hbucket *)
< hsize)
return 0;
return hsize * sizeof(struct hbucket *) + sizeof(struct htable);
}
#ifdef IP_SET_HASH_WITH_NETS
#if IPSET_NET_COUNT > 1
#define __CIDR(cidr, i) (cidr[i])
#else
#define __CIDR(cidr, i) (cidr)
#endif
/* cidr + 1 is stored in net_prefixes to support /0 */
#define NCIDR_PUT(cidr) ((cidr) + 1)
#define NCIDR_GET(cidr) ((cidr) - 1)
#ifdef IP_SET_HASH_WITH_NETS_PACKED
/* When cidr is packed with nomatch, cidr - 1 is stored in the data entry */
#define DCIDR_PUT(cidr) ((cidr) - 1)
#define DCIDR_GET(cidr, i) (__CIDR(cidr, i) + 1)
#else
#define DCIDR_PUT(cidr) (cidr)
Annotation
- Immediate include surface: `linux/rcupdate.h`, `linux/rcupdate_wait.h`, `linux/jhash.h`, `linux/types.h`, `linux/netfilter/nfnetlink.h`, `linux/netfilter/ipset/ip_set.h`.
- Detected declarations: `struct hbucket`, `struct htable_gc`, `struct htable`, `struct net_prefixes`, `struct htype`, `struct mtype_resize_ad`, `function htable_size`, `function mtype_add_cidr`, `function mtype_del_cidr`, `function mtype_ahash_memsize`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.