net/ipv4/fib_frontend.c
Source file repositories/reference/linux-study-clean/net/ipv4/fib_frontend.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/fib_frontend.c- Extension
.c- Size
- 41484 bytes
- Lines
- 1708
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/module.hlinux/uaccess.hlinux/bitops.hlinux/capability.hlinux/types.hlinux/kernel.hlinux/mm.hlinux/string.hlinux/socket.hlinux/sockios.hlinux/errno.hlinux/in.hlinux/inet.hlinux/inetdevice.hlinux/netdevice.hlinux/if_addr.hlinux/if_arp.hlinux/skbuff.hlinux/cache.hlinux/init.hlinux/list.hlinux/slab.hnet/flow.hnet/inet_dscp.hnet/ip.hnet/protocol.hnet/route.hnet/tcp.hnet/sock.hnet/arp.hnet/ip_fib.hnet/nexthop.h
Detected Declarations
function fib4_rules_initfunction lockdep_rtnl_is_heldfunction fib_replace_tablefunction fib_unmergefunction fib_flushfunction __inet_dev_addr_typefunction inet_addr_type_tablefunction inet_addr_typefunction inet_dev_addr_typefunction inet_addr_type_dev_tablefunction fib_compute_spec_dstfunction fib_info_nh_uses_devfunction rcu_read_lockfunction fib_validate_sourcefunction sk_extract_addrfunction put_rtaxfunction rtentry_to_fib_configfunction in_dev_for_each_ifa_rtnl_netfunction ip_rt_ioctlfunction fib_gw_from_viafunction rtm_to_fib_configfunction nlmsg_for_each_attrfunction inet_rtm_delroutefunction inet_rtm_newroutefunction ip_valid_fib_dump_reqfunction inet_dump_fibfunction hlist_for_each_entry_rcufunction fib_magicfunction fib_add_ifaddrfunction fib_modify_prefix_metricfunction fib_del_ifaddrfunction nl_fib_lookupfunction nl_fib_inputfunction nl_fib_lookup_initfunction nl_fib_lookup_exitfunction fib_disable_ipfunction fib_inetaddr_eventfunction fib_netdev_eventfunction ip_fib_net_initfunction ip_fib_net_exitfunction hlist_for_each_entry_safefunction fib_net_initfunction fib_net_pre_exitfunction fib_net_exit_rtnlfunction fib_net_exitfunction ip_fib_initexport fib_new_tableexport inet_addr_type_table
Annotated Snippet
lockdep_rtnl_is_held()) {
if (tb->tb_id == id)
return tb;
}
return NULL;
}
#endif /* CONFIG_IP_MULTIPLE_TABLES */
static void fib_replace_table(struct net *net, struct fib_table *old,
struct fib_table *new)
{
#ifdef CONFIG_IP_MULTIPLE_TABLES
switch (new->tb_id) {
case RT_TABLE_MAIN:
rcu_assign_pointer(net->ipv4.fib_main, new);
break;
case RT_TABLE_DEFAULT:
rcu_assign_pointer(net->ipv4.fib_default, new);
break;
default:
break;
}
#endif
/* replace the old table in the hlist */
hlist_replace_rcu(&old->tb_hlist, &new->tb_hlist);
}
int fib_unmerge(struct net *net)
{
struct fib_table *old, *new, *main_table;
/* attempt to fetch local table if it has been allocated */
old = fib_get_table(net, RT_TABLE_LOCAL);
if (!old)
return 0;
new = fib_trie_unmerge(old);
if (!new)
return -ENOMEM;
/* table is already unmerged */
if (new == old)
return 0;
/* replace merged table with clean table */
fib_replace_table(net, old, new);
fib_free_table(old);
/* attempt to fetch main table if it has been allocated */
main_table = fib_get_table(net, RT_TABLE_MAIN);
if (!main_table)
return 0;
/* flush local entries from main table */
fib_table_flush_external(main_table);
return 0;
}
void fib_flush(struct net *net)
{
int flushed = 0;
unsigned int h;
for (h = 0; h < FIB_TABLE_HASHSZ; h++) {
struct hlist_head *head = &net->ipv4.fib_table_hash[h];
struct hlist_node *tmp;
struct fib_table *tb;
hlist_for_each_entry_safe(tb, tmp, head, tb_hlist)
flushed += fib_table_flush(net, tb, false);
}
if (flushed)
rt_cache_flush(net);
}
/*
* Find address type as if only "dev" was present in the system. If
* on_dev is NULL then all interfaces are taken into consideration.
*/
static inline unsigned int __inet_dev_addr_type(struct net *net,
const struct net_device *dev,
__be32 addr, u32 tb_id)
{
struct flowi4 fl4 = { .daddr = addr };
struct fib_result res;
unsigned int ret = RTN_BROADCAST;
struct fib_table *table;
Annotation
- Immediate include surface: `linux/module.h`, `linux/uaccess.h`, `linux/bitops.h`, `linux/capability.h`, `linux/types.h`, `linux/kernel.h`, `linux/mm.h`, `linux/string.h`.
- Detected declarations: `function fib4_rules_init`, `function lockdep_rtnl_is_held`, `function fib_replace_table`, `function fib_unmerge`, `function fib_flush`, `function __inet_dev_addr_type`, `function inet_addr_type_table`, `function inet_addr_type`, `function inet_dev_addr_type`, `function inet_addr_type_dev_table`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.