net/ipv4/fib_semantics.c
Source file repositories/reference/linux-study-clean/net/ipv4/fib_semantics.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/fib_semantics.c- Extension
.c- Size
- 53946 bytes
- Lines
- 2255
- 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/uaccess.hlinux/bitops.hlinux/types.hlinux/kernel.hlinux/jiffies.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/skbuff.hlinux/init.hlinux/slab.hlinux/netlink.hlinux/hash.hlinux/nospec.hnet/arp.hnet/inet_dscp.hnet/ip.hnet/protocol.hnet/route.hnet/tcp.hnet/sock.hnet/ip_fib.hnet/ip6_fib.hnet/nexthop.h
Detected Declarations
function rt_fibinfo_freefunction free_nh_exceptionsfunction rt_fibinfo_free_cpusfunction for_each_possible_cpufunction fib_nh_common_releasefunction fib_nh_releasefunction free_fib_info_rcufunction change_nexthopsfunction free_fib_infofunction fib_release_infofunction change_nexthopsfunction nh_compfunction for_nexthopsfunction fib_info_hashfn_1function fib_info_hashfn_resultfunction for_nexthopsfunction fib_info_hash_freefunction fib_info_hash_growfunction hlist_for_each_entryfunction hlist_for_each_entryfunction ip_fib_check_defaultfunction hlist_for_each_entry_rcufunction fib_nlmsg_sizefunction rtmsg_fibfunction fib_detect_deathfunction fib_nh_common_initfunction fib_nh_initfunction fib_count_nexthopsfunction fib_gw_from_attrfunction fib_get_nhsfunction change_nexthopsfunction fib_rebalancefunction fib_get_nhsfunction fib_encap_matchfunction fib_nh_matchfunction for_nexthopsfunction fib_metrics_matchfunction nla_for_each_attrfunction fib_check_nh_v6_gwfunction thesefunction fib_check_nh_nongwfunction fib_check_nhfunction fib_info_update_nhc_saddrfunction fib_result_prefsrcfunction fib_valid_prefsrcfunction change_nexthopsfunction change_nexthopsfunction change_nexthops
Annotated Snippet
while (fnhe) {
struct fib_nh_exception *next;
next = rcu_dereference_protected(fnhe->fnhe_next, 1);
rt_fibinfo_free(&fnhe->fnhe_rth_input);
rt_fibinfo_free(&fnhe->fnhe_rth_output);
kfree(fnhe);
fnhe = next;
}
}
kfree(hash);
}
static void rt_fibinfo_free_cpus(struct rtable __rcu * __percpu *rtp)
{
int cpu;
if (!rtp)
return;
for_each_possible_cpu(cpu) {
struct rtable *rt;
rt = rcu_dereference_protected(*per_cpu_ptr(rtp, cpu), 1);
if (rt) {
dst_dev_put(&rt->dst);
dst_release_immediate(&rt->dst);
}
}
free_percpu(rtp);
}
void fib_nh_common_release(struct fib_nh_common *nhc)
{
netdev_put(nhc->nhc_dev, &nhc->nhc_dev_tracker);
lwtstate_put(nhc->nhc_lwtstate);
rt_fibinfo_free_cpus(nhc->nhc_pcpu_rth_output);
rt_fibinfo_free(&nhc->nhc_rth_input);
free_nh_exceptions(nhc);
}
void fib_nh_release(struct net *net, struct fib_nh *fib_nh)
{
#ifdef CONFIG_IP_ROUTE_CLASSID
if (fib_nh->nh_tclassid)
atomic_dec(&net->ipv4.fib_num_tclassid_users);
#endif
fib_nh_common_release(&fib_nh->nh_common);
}
/* Release a nexthop info record */
static void free_fib_info_rcu(struct rcu_head *head)
{
struct fib_info *fi = container_of(head, struct fib_info, rcu);
if (fi->nh) {
nexthop_put(fi->nh);
} else {
change_nexthops(fi) {
fib_nh_release(fi->fib_net, nexthop_nh);
} endfor_nexthops(fi);
}
ip_fib_metrics_put(fi->fib_metrics);
kfree(fi);
}
void free_fib_info(struct fib_info *fi)
{
if (fi->fib_dead == 0) {
pr_warn("Freeing alive fib_info %p\n", fi);
return;
}
call_rcu_hurry(&fi->rcu, free_fib_info_rcu);
}
EXPORT_SYMBOL_GPL(free_fib_info);
void fib_release_info(struct fib_info *fi)
{
ASSERT_RTNL();
if (fi && refcount_dec_and_test(&fi->fib_treeref)) {
hlist_del(&fi->fib_hash);
fi->fib_net->ipv4.fib_info_cnt--;
if (fi->fib_prefsrc)
Annotation
- Immediate include surface: `linux/uaccess.h`, `linux/bitops.h`, `linux/types.h`, `linux/kernel.h`, `linux/jiffies.h`, `linux/mm.h`, `linux/string.h`, `linux/socket.h`.
- Detected declarations: `function rt_fibinfo_free`, `function free_nh_exceptions`, `function rt_fibinfo_free_cpus`, `function for_each_possible_cpu`, `function fib_nh_common_release`, `function fib_nh_release`, `function free_fib_info_rcu`, `function change_nexthops`, `function free_fib_info`, `function fib_release_info`.
- 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.