net/ipv4/fib_trie.c
Source file repositories/reference/linux-study-clean/net/ipv4/fib_trie.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/fib_trie.c- Extension
.c- Size
- 74452 bytes
- Lines
- 3040
- 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/cache.hlinux/uaccess.hlinux/bitops.hlinux/types.hlinux/kernel.hlinux/mm.hlinux/string.hlinux/socket.hlinux/sockios.hlinux/errno.hlinux/in.hlinux/inet.hlinux/inetdevice.hlinux/netdevice.hlinux/if_arp.hlinux/proc_fs.hlinux/rcupdate.hlinux/rcupdate_wait.hlinux/skbuff.hlinux/netlink.hlinux/init.hlinux/list.hlinux/slab.hlinux/export.hlinux/vmalloc.hlinux/notifier.hnet/net_namespace.hnet/inet_dscp.hnet/ip.hnet/protocol.hnet/route.hnet/tcp.h
Detected Declarations
struct key_vectorstruct tnodestruct trie_use_statsstruct trie_statstruct triestruct fib_trie_iterstruct fib_route_iterfunction call_fib_entry_notifierfunction call_fib_entry_notifiersfunction node_set_parentfunction child_lengthfunction get_indexfunction alias_free_mem_rcufunction __node_free_rcufunction empty_child_incfunction empty_child_decfunction tnode_fullfunction put_childfunction update_childrenfunction put_child_rootfunction tnode_free_initfunction tnode_free_appendfunction tnode_freefunction update_suffixfunction should_halvefunction should_collapsefunction node_pull_suffixfunction node_push_suffixfunction hlist_for_each_entryfunction fib_find_matching_aliasfunction hlist_for_each_entry_rcufunction fib_alias_hw_flags_setfunction trie_rebalancefunction fib_insert_nodefunction fib_insert_aliasfunction hlist_for_each_entryfunction fib_table_insertfunction hlist_for_each_entry_fromfunction prefix_mismatchfunction fib_lookup_good_nhcfunction fib_table_lookupfunction fib_remove_aliasfunction fib_notify_alias_deletefunction fib_table_deletefunction fib_trie_freefunction hlist_for_each_entry_safefunction hlist_for_each_entryfunction fib_table_flush_external
Annotated Snippet
struct key_vector {
t_key key;
unsigned char pos; /* 2log(KEYLENGTH) bits needed */
unsigned char bits; /* 2log(KEYLENGTH) bits needed */
unsigned char slen;
union {
/* This list pointer if valid if (pos | bits) == 0 (LEAF) */
struct hlist_head leaf;
/* This array is valid if (pos | bits) > 0 (TNODE) */
DECLARE_FLEX_ARRAY(struct key_vector __rcu *, tnode);
};
};
struct tnode {
struct rcu_head rcu;
t_key empty_children; /* KEYLENGTH bits needed */
t_key full_children; /* KEYLENGTH bits needed */
struct key_vector __rcu *parent;
struct key_vector kv[1];
#define tn_bits kv[0].bits
};
#define TNODE_SIZE(n) offsetof(struct tnode, kv[0].tnode[n])
#define LEAF_SIZE TNODE_SIZE(1)
#ifdef CONFIG_IP_FIB_TRIE_STATS
struct trie_use_stats {
unsigned int gets;
unsigned int backtrack;
unsigned int semantic_match_passed;
unsigned int semantic_match_miss;
unsigned int null_node_hit;
unsigned int resize_node_skipped;
};
#endif
struct trie_stat {
unsigned int totdepth;
unsigned int maxdepth;
unsigned int tnodes;
unsigned int leaves;
unsigned int nullpointers;
unsigned int prefixes;
unsigned int nodesizes[MAX_STAT_DEPTH];
};
struct trie {
struct key_vector kv[1];
#ifdef CONFIG_IP_FIB_TRIE_STATS
struct trie_use_stats __percpu *stats;
#endif
};
static struct key_vector *resize(struct trie *t, struct key_vector *tn);
static unsigned int tnode_free_size;
/*
* synchronize_rcu after call_rcu for outstanding dirty memory; it should be
* especially useful before resizing the root node with PREEMPT_NONE configs;
* the value was obtained experimentally, aiming to avoid visible slowdown.
*/
unsigned int sysctl_fib_sync_mem = 512 * 1024;
unsigned int sysctl_fib_sync_mem_min = 64 * 1024;
unsigned int sysctl_fib_sync_mem_max = 64 * 1024 * 1024;
static struct kmem_cache *fn_alias_kmem __ro_after_init;
static struct kmem_cache *trie_leaf_kmem __ro_after_init;
static inline struct tnode *tn_info(struct key_vector *kv)
{
return container_of(kv, struct tnode, kv[0]);
}
/* caller must hold RTNL */
#define node_parent(tn) rtnl_dereference(tn_info(tn)->parent)
#define get_child(tn, i) rtnl_dereference((tn)->tnode[i])
/* caller must hold RCU read lock or RTNL */
#define node_parent_rcu(tn) rcu_dereference_rtnl(tn_info(tn)->parent)
#define get_child_rcu(tn, i) rcu_dereference_rtnl((tn)->tnode[i])
/* wrapper for rcu_assign_pointer */
static inline void node_set_parent(struct key_vector *n, struct key_vector *tp)
{
if (n)
rcu_assign_pointer(tn_info(n)->parent, tp);
}
#define NODE_INIT_PARENT(n, p) RCU_INIT_POINTER(tn_info(n)->parent, p)
Annotation
- Immediate include surface: `linux/cache.h`, `linux/uaccess.h`, `linux/bitops.h`, `linux/types.h`, `linux/kernel.h`, `linux/mm.h`, `linux/string.h`, `linux/socket.h`.
- Detected declarations: `struct key_vector`, `struct tnode`, `struct trie_use_stats`, `struct trie_stat`, `struct trie`, `struct fib_trie_iter`, `struct fib_route_iter`, `function call_fib_entry_notifier`, `function call_fib_entry_notifiers`, `function node_set_parent`.
- 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.