在函数ip_rt_init( )中进行了rt_hash_bucket的初始化,代码如下:
rt_hash_table = (struct rt_hash_bucket *)
alloc_large_system_hash("IP route cache",
sizeof(struct rt_hash_bucket),
rhash_entries,
(num_physpages >= 128 * 1024) ?
15 : 17,
0,
&rt_hash_log,
&rt_hash_mask,
0);
memset(rt_hash_table, 0, (rt_hash_mask + 1) * sizeof(struct rt_hash_bucket));
使用alloc_large_system_hash函数初始化了一个哈希表
在该函数中还创建了slab句柄,用于存储具体的r_table项
ipv4_dst_ops.kmem_cachep =
kmem_cache_create("ip_dst_cache", sizeof(struct rtable), 0,
SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
路由缓存查找过程
数据包进入网络层之后,第一个调用的函数是ip_ rcv函数,通过pskb_may_pull完成碎片重组之后还要进行一些有效性检查,最后调用
return NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, dev, NULL,
ip_rcv_finish);
进入ip_rcv_finish函数,ip_rcv_finish函数开始就调用了ip_route_input以生成路由信息。