net/netfilter/nft_set_hash.c
Source file repositories/reference/linux-study-clean/net/netfilter/nft_set_hash.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nft_set_hash.c- Extension
.c- Size
- 22575 bytes
- Lines
- 904
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/init.hlinux/module.hlinux/list.hlinux/log2.hlinux/jhash.hlinux/netlink.hlinux/workqueue.hlinux/rhashtable.hlinux/netfilter.hlinux/netfilter/nf_tables.hnet/netfilter/nf_tables_core.h
Detected Declarations
struct nft_rhashstruct nft_rhash_elemstruct nft_rhash_cmp_argstruct nft_rhash_ctxstruct nft_hashstruct nft_hash_elemfunction nft_rhash_keyfunction nft_rhash_objfunction nft_rhash_cmpfunction nft_rhash_lookupfunction nft_rhash_getfunction nft_rhash_updatefunction nft_rhash_insertfunction nft_rhash_activatefunction nft_rhash_flushfunction nft_rhash_deactivatefunction nft_rhash_removefunction nft_rhash_deletefunction nft_rhash_walk_rofunction nft_rhash_walk_updatefunction nft_rhash_walkfunction nft_rhash_expr_needs_gc_runfunction nft_setelem_expr_foreachfunction nft_rhash_gcfunction nft_rhash_privsizefunction nft_rhash_gc_initfunction nft_rhash_initfunction nft_rhash_elem_destroyfunction nft_rhash_destroyfunction nft_hash_bucketsfunction nft_rhash_estimatefunction nft_hash_lookupfunction nft_hash_getfunction nft_hash_lookup_fastfunction nft_jhashfunction nft_hash_insertfunction nft_hash_activatefunction nft_hash_flushfunction nft_hash_deactivatefunction nft_hash_removefunction nft_hash_walkfunction hlist_for_each_entry_rcufunction nft_hash_privsizefunction nft_hash_initfunction nft_hash_destroyfunction hlist_for_each_entry_safefunction nft_hash_estimatefunction nft_hash_fast_estimate
Annotated Snippet
struct nft_rhash {
struct rhashtable ht;
struct delayed_work gc_work;
u32 wq_gc_seq;
};
struct nft_rhash_elem {
struct nft_elem_priv priv;
struct rhash_head node;
struct llist_node walk_node;
u32 wq_gc_seq;
struct nft_set_ext ext;
};
struct nft_rhash_cmp_arg {
const struct nft_set *set;
const u32 *key;
u8 genmask;
u64 tstamp;
};
static inline u32 nft_rhash_key(const void *data, u32 len, u32 seed)
{
const struct nft_rhash_cmp_arg *arg = data;
return jhash(arg->key, len, seed);
}
static inline u32 nft_rhash_obj(const void *data, u32 len, u32 seed)
{
const struct nft_rhash_elem *he = data;
return jhash(nft_set_ext_key(&he->ext), len, seed);
}
static inline int nft_rhash_cmp(struct rhashtable_compare_arg *arg,
const void *ptr)
{
const struct nft_rhash_cmp_arg *x = arg->key;
const struct nft_rhash_elem *he = ptr;
if (memcmp(nft_set_ext_key(&he->ext), x->key, x->set->klen))
return 1;
if (nft_set_elem_is_dead(&he->ext))
return 1;
if (__nft_set_elem_expired(&he->ext, x->tstamp))
return 1;
if (!nft_set_elem_active(&he->ext, x->genmask))
return 1;
return 0;
}
static const struct rhashtable_params nft_rhash_params = {
.head_offset = offsetof(struct nft_rhash_elem, node),
.hashfn = nft_rhash_key,
.obj_hashfn = nft_rhash_obj,
.obj_cmpfn = nft_rhash_cmp,
.automatic_shrinking = true,
};
INDIRECT_CALLABLE_SCOPE
const struct nft_set_ext *
nft_rhash_lookup(const struct net *net, const struct nft_set *set,
const u32 *key)
{
struct nft_rhash *priv = nft_set_priv(set);
const struct nft_rhash_elem *he;
struct nft_rhash_cmp_arg arg = {
.genmask = nft_genmask_cur(net),
.set = set,
.key = key,
.tstamp = get_jiffies_64(),
};
he = rhashtable_lookup(&priv->ht, &arg, nft_rhash_params);
if (he != NULL)
return &he->ext;
return NULL;
}
static struct nft_elem_priv *
nft_rhash_get(const struct net *net, const struct nft_set *set,
const struct nft_set_elem *elem, unsigned int flags)
{
struct nft_rhash *priv = nft_set_priv(set);
struct nft_rhash_elem *he;
struct nft_rhash_cmp_arg arg = {
.genmask = nft_genmask_cur(net),
.set = set,
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/init.h`, `linux/module.h`, `linux/list.h`, `linux/log2.h`, `linux/jhash.h`, `linux/netlink.h`, `linux/workqueue.h`.
- Detected declarations: `struct nft_rhash`, `struct nft_rhash_elem`, `struct nft_rhash_cmp_arg`, `struct nft_rhash_ctx`, `struct nft_hash`, `struct nft_hash_elem`, `function nft_rhash_key`, `function nft_rhash_obj`, `function nft_rhash_cmp`, `function nft_rhash_lookup`.
- 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.
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.