net/ipv4/route.c
Source file repositories/reference/linux-study-clean/net/ipv4/route.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/route.c- Extension
.c- Size
- 98008 bytes
- Lines
- 3797
- 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/module.hlinux/bitops.hlinux/kernel.hlinux/mm.hlinux/memblock.hlinux/socket.hlinux/errno.hlinux/in.hlinux/inet.hlinux/netdevice.hlinux/proc_fs.hlinux/init.hlinux/skbuff.hlinux/inetdevice.hlinux/igmp.hlinux/pkt_sched.hlinux/mroute.hlinux/netfilter_ipv4.hlinux/random.hlinux/rcupdate.hlinux/slab.hlinux/jhash.hnet/dst.hnet/dst_metadata.hnet/flow.hnet/inet_dscp.hnet/net_namespace.hnet/ip.hnet/route.hnet/inetpeer.hnet/sock.hnet/ip_fib.h
Detected Declarations
struct uncached_listfunction rt_cache_seq_stopfunction rt_cpu_seq_stopfunction rt_acct_proc_showfunction for_each_possible_cpufunction ip_rt_do_proc_initfunction ip_rt_do_proc_exitfunction ip_rt_proc_initfunction ip_rt_proc_initfunction rt_is_expiredfunction rt_cache_flushfunction ipv4_confirm_neighfunction ip_idents_reservefunction __ip_select_identfunction __build_flow_keyfunction build_skb_flow_keyfunction build_sk_flow_keyfunction ip_rt_build_flow_keyfunction fnhe_flush_routesfunction fnhe_remove_oldestfunction fnhe_hashfunfunction fill_route_from_fnhefunction update_or_create_fnhefunction for_each_possible_cpufunction __ip_do_redirectfunction ip_do_redirectfunction ipv4_negative_advicefunction ip_rt_send_redirectfunction time_afterfunction ip_errorfunction __ip_rt_update_pmtufunction ip_rt_update_pmtufunction ipv4_update_pmtufunction __ipv4_sk_update_pmtufunction ipv4_sk_update_pmtufunction ipv4_redirectfunction ipv4_sk_redirectfunction ipv4_send_dest_unreachfunction ipv4_link_failurefunction ip_rt_bugfunction ip_rt_get_sourcefunction set_class_tagfunction ipv4_default_advmssfunction ipv4_mtufunction ip_del_fnhefunction ip_mtu_from_fib_resultfunction rt_bind_exceptionfunction rt_cache_route
Annotated Snippet
struct uncached_list {
spinlock_t lock;
struct list_head head;
};
static DEFINE_PER_CPU_ALIGNED(struct uncached_list, rt_uncached_list);
void rt_add_uncached_list(struct rtable *rt)
{
struct uncached_list *ul = raw_cpu_ptr(&rt_uncached_list);
rt->dst.rt_uncached_list = ul;
spin_lock_bh(&ul->lock);
list_add_tail(&rt->dst.rt_uncached, &ul->head);
spin_unlock_bh(&ul->lock);
}
void rt_del_uncached_list(struct rtable *rt)
{
struct uncached_list *ul = rt->dst.rt_uncached_list;
if (ul) {
spin_lock_bh(&ul->lock);
list_del_init(&rt->dst.rt_uncached);
spin_unlock_bh(&ul->lock);
}
}
static void ipv4_dst_destroy(struct dst_entry *dst)
{
ip_dst_metrics_put(dst);
rt_del_uncached_list(dst_rtable(dst));
}
void rt_flush_dev(struct net_device *dev)
{
struct rtable *rt, *safe;
int cpu;
for_each_possible_cpu(cpu) {
struct uncached_list *ul = &per_cpu(rt_uncached_list, cpu);
if (list_empty(&ul->head))
continue;
spin_lock_bh(&ul->lock);
list_for_each_entry_safe(rt, safe, &ul->head, dst.rt_uncached) {
if (rt->dst.dev != dev)
continue;
rt->dst.dev = blackhole_netdev;
netdev_ref_replace(dev, blackhole_netdev,
&rt->dst.dev_tracker, GFP_ATOMIC);
list_del_init(&rt->dst.rt_uncached);
}
spin_unlock_bh(&ul->lock);
}
}
static bool rt_cache_valid(const struct rtable *rt)
{
return rt &&
READ_ONCE(rt->dst.obsolete) == DST_OBSOLETE_FORCE_CHK &&
!rt_is_expired(rt);
}
static void rt_set_nexthop(struct rtable *rt, __be32 daddr,
const struct fib_result *res,
struct fib_nh_exception *fnhe,
struct fib_info *fi, u16 type, u32 itag,
const bool do_cache)
{
bool cached = false;
if (fi) {
struct fib_nh_common *nhc = FIB_RES_NHC(*res);
if (nhc->nhc_gw_family && nhc->nhc_scope == RT_SCOPE_LINK) {
rt->rt_uses_gateway = 1;
rt->rt_gw_family = nhc->nhc_gw_family;
/* only INET and INET6 are supported */
if (likely(nhc->nhc_gw_family == AF_INET))
rt->rt_gw4 = nhc->nhc_gw.ipv4;
else
rt->rt_gw6 = nhc->nhc_gw.ipv6;
}
ip_dst_init_metrics(&rt->dst, fi->fib_metrics);
#ifdef CONFIG_IP_ROUTE_CLASSID
Annotation
- Immediate include surface: `linux/module.h`, `linux/bitops.h`, `linux/kernel.h`, `linux/mm.h`, `linux/memblock.h`, `linux/socket.h`, `linux/errno.h`, `linux/in.h`.
- Detected declarations: `struct uncached_list`, `function rt_cache_seq_stop`, `function rt_cpu_seq_stop`, `function rt_acct_proc_show`, `function for_each_possible_cpu`, `function ip_rt_do_proc_init`, `function ip_rt_do_proc_exit`, `function ip_rt_proc_init`, `function ip_rt_proc_init`, `function rt_is_expired`.
- 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.