文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>再议路由初始化

再议路由初始化

时间:2010-10-12  来源:shelcod

看源代码,发现路由最初初始化的函数在net/ipv4/route.c
int __init ip_rt_init(void)
{
    int rc = 0;

#ifdef CONFIG_NET_CLS_ROUTE
    ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct));
    if (!ip_rt_acct)
        panic("IP: failed to allocate ip_rt_acct\n");
#endif
   
    /*既然是全局变量,肯定很重要*/
    ipv4_dst_ops.kmem_cachep =
        kmem_cache_create("ip_dst_cache", sizeof(struct rtable), 0,
                  SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);

    ipv4_dst_blackhole_ops.kmem_cachep = ipv4_dst_ops.kmem_cachep;

    /*创建struct 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));
    rt_hash_lock_init();

    /*垃圾回收阀值*/
    ipv4_dst_ops.gc_thresh = (rt_hash_mask + 1);
    ip_rt_max_size = (rt_hash_mask + 1) * 16;

    /*主要的初始化函数*/
    devinet_init();
    ip_fib_init();

    /* All the timers, started at system startup tend
       to synchronize. Perturb it a bit.
     */
    schedule_delayed_work(&expires_work,
        net_random() % ip_rt_gc_interval + ip_rt_gc_interval);

    if (register_pernet_subsys(&rt_secret_timer_ops))
        printk(KERN_ERR "Unable to setup rt_secret_timer\n");

    if (ip_rt_proc_init())
        printk(KERN_ERR "Unable to create route proc files\n");
#ifdef CONFIG_XFRM
    xfrm_init();
    xfrm4_init();
#endif
    /*注册rtnetlink 消息, 这里是获取路由, 在devinet_init()中还有其他三种消息*/
    rtnl_register(PF_INET, RTM_GETROUTE, inet_rtm_getroute, NULL);

#ifdef CONFIG_SYSCTL
    register_pernet_subsys(&sysctl_route_ops);
#endif
    return rc;
}

void __init devinet_init(void)
{
    /*还是初始struct net结构中的部分变量*/
    register_pernet_subsys(&devinet_ops);

    register_gifconf(PF_INET, inet_gifconf);
    /*注册一个通知链,主要处理设备的状态改变*/
    register_netdevice_notifier(&ip_netdev_notifier);

    /*另外的两个消息*/
    rtnl_register(PF_INET, RTM_NEWADDR, inet_rtm_newaddr, NULL);
    rtnl_register(PF_INET, RTM_DELADDR, inet_rtm_deladdr, NULL);
    rtnl_register(PF_INET, RTM_GETADDR, NULL, inet_dump_ifaddr);
}

这是ip_netdev_notifier的初始化值:
static struct notifier_block ip_netdev_notifier = {
    .notifier_call = inetdev_event,
};

ip_fib_init()在上一篇中已经介绍过!

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载