net/netfilter/nft_set_rbtree.c
Source file repositories/reference/linux-study-clean/net/netfilter/nft_set_rbtree.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nft_set_rbtree.c- Extension
.c- Size
- 30781 bytes
- Lines
- 1200
- 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.
- 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/kernel.hlinux/init.hlinux/module.hlinux/list.hlinux/rbtree.hlinux/bsearch.hlinux/netlink.hlinux/netfilter.hlinux/netfilter/nf_tables.hnet/netfilter/nf_tables_core.h
Detected Declarations
struct nft_array_intervalstruct nft_arraystruct nft_rbtreestruct nft_rbtree_elemstruct nft_array_lookup_ctxstruct nft_array_get_ctxfunction nft_rbtree_interval_endfunction nft_rbtree_interval_startfunction nft_rbtree_interval_nullfunction nft_rbtree_cmpfunction nft_array_lookup_cmpfunction nft_rbtree_lookupfunction nft_array_get_cmpfunction nft_rbtree_getfunction nft_rbtree_gc_elem_movefunction nft_rbtree_gc_elemfunction nft_rbtree_update_firstfunction __nft_rbtree_next_activefunction nft_rbtree_next_activefunction nft_rbtree_maybe_reset_start_cookiefunction nft_rbtree_set_start_cookiefunction nft_rbtree_cmp_start_cookiefunction nft_rbtree_insert_same_intervalfunction __nft_rbtree_insertfunction nft_rbtree_interval_startfunction nft_rbtree_interval_endfunction nft_rbtree_interval_startfunction nft_array_intervals_allocfunction nft_array_elemsfunction nft_array_may_resizefunction nft_rbtree_insertfunction nft_rbtree_removefunction nft_rbtree_activatefunction nft_rbtree_next_inactivefunction nft_rbtree_deactivate_same_intervalfunction nft_rbtree_flushfunction nft_rbtree_deactivatefunction nft_rbtree_interval_endfunction nft_rbtree_do_walkfunction nft_rbtree_walkfunction nft_rbtree_gc_scanfunction nft_rbtree_gc_queuefunction list_for_each_entry_safefunction nft_rbtree_privsizefunction nft_rbtree_initfunction __nft_array_freefunction nft_rbtree_destroyfunction list_for_each_entry_safe
Annotated Snippet
struct nft_array_interval {
struct nft_set_ext *from;
struct nft_set_ext *to;
};
struct nft_array {
u32 max_intervals;
u32 num_intervals;
struct nft_array_interval *intervals;
struct rcu_head rcu_head;
};
struct nft_rbtree {
struct rb_root root;
rwlock_t lock;
struct nft_array __rcu *array;
struct nft_array *array_next;
unsigned long start_rbe_cookie;
unsigned long last_gc;
struct list_head expired;
u64 last_tstamp;
};
struct nft_rbtree_elem {
struct nft_elem_priv priv;
union {
struct rb_node node;
struct list_head list;
};
struct nft_set_ext ext;
};
static bool nft_rbtree_interval_end(const struct nft_rbtree_elem *rbe)
{
return nft_set_ext_exists(&rbe->ext, NFT_SET_EXT_FLAGS) &&
(*nft_set_ext_flags(&rbe->ext) & NFT_SET_ELEM_INTERVAL_END);
}
static bool nft_rbtree_interval_start(const struct nft_rbtree_elem *rbe)
{
return !nft_rbtree_interval_end(rbe);
}
static bool nft_rbtree_interval_null(const struct nft_set *set,
const struct nft_rbtree_elem *rbe)
{
return (!memchr_inv(nft_set_ext_key(&rbe->ext), 0, set->klen) &&
nft_rbtree_interval_end(rbe));
}
static int nft_rbtree_cmp(const struct nft_set *set,
const struct nft_rbtree_elem *e1,
const struct nft_rbtree_elem *e2)
{
return memcmp(nft_set_ext_key(&e1->ext), nft_set_ext_key(&e2->ext),
set->klen);
}
struct nft_array_lookup_ctx {
const u32 *key;
u32 klen;
};
static int nft_array_lookup_cmp(const void *pkey, const void *entry)
{
const struct nft_array_interval *interval = entry;
const struct nft_array_lookup_ctx *ctx = pkey;
int a, b;
if (!interval->from)
return 1;
a = memcmp(ctx->key, nft_set_ext_key(interval->from), ctx->klen);
if (!interval->to)
b = -1;
else
b = memcmp(ctx->key, nft_set_ext_key(interval->to), ctx->klen);
if (a >= 0 && b < 0)
return 0;
if (a < 0)
return -1;
return 1;
}
INDIRECT_CALLABLE_SCOPE
const struct nft_set_ext *
nft_rbtree_lookup(const struct net *net, const struct nft_set *set,
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/init.h`, `linux/module.h`, `linux/list.h`, `linux/rbtree.h`, `linux/bsearch.h`, `linux/netlink.h`, `linux/netfilter.h`.
- Detected declarations: `struct nft_array_interval`, `struct nft_array`, `struct nft_rbtree`, `struct nft_rbtree_elem`, `struct nft_array_lookup_ctx`, `struct nft_array_get_ctx`, `function nft_rbtree_interval_end`, `function nft_rbtree_interval_start`, `function nft_rbtree_interval_null`, `function nft_rbtree_cmp`.
- 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.